Skip to content

Commit e28fc27

Browse files
committed
[DoctrineBridge] Spread some PHP 8 love
1 parent e1bdcf0 commit e28fc27

File tree

62 files changed

+337
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+337
-513
lines changed

CacheWarmer/ProxyCacheWarmer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
class ProxyCacheWarmer implements CacheWarmerInterface
2626
{
27-
private ManagerRegistry $registry;
28-
29-
public function __construct(ManagerRegistry $registry)
30-
{
31-
$this->registry = $registry;
27+
public function __construct(
28+
private readonly ManagerRegistry $registry,
29+
) {
3230
}
3331

3432
/**

DataCollector/ObjectParameter.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313

1414
final class ObjectParameter
1515
{
16-
private object $object;
17-
private ?\Throwable $error;
1816
private bool $stringable;
1917
private string $class;
2018

21-
public function __construct(object $object, ?\Throwable $error)
22-
{
23-
$this->object = $object;
24-
$this->error = $error;
25-
$this->stringable = \is_callable([$object, '__toString']);
19+
public function __construct(
20+
private readonly object $object,
21+
private readonly ?\Throwable $error,
22+
) {
23+
$this->stringable = $this->object instanceof \Stringable;
2624
$this->class = $object::class;
2725
}
2826

DataFixtures/ContainerAwareLoader.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
*/
3030
class ContainerAwareLoader extends Loader
3131
{
32-
private ContainerInterface $container;
33-
34-
public function __construct(ContainerInterface $container)
35-
{
36-
$this->container = $container;
32+
public function __construct(
33+
private readonly ContainerInterface $container,
34+
) {
3735
}
3836

3937
/**

DependencyInjection/CompilerPass/DoctrineValidationPass.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
*/
2222
class DoctrineValidationPass implements CompilerPassInterface
2323
{
24-
private string $managerType;
25-
26-
public function __construct(string $managerType)
27-
{
28-
$this->managerType = $managerType;
24+
public function __construct(
25+
private readonly string $managerType,
26+
) {
2927
}
3028

3129
/**

DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,23 @@
3030
*/
3131
class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
3232
{
33-
private string $connectionsParameter;
3433
private array $connections;
3534

3635
/**
3736
* @var array<string, Definition>
3837
*/
3938
private array $eventManagers = [];
4039

41-
private string $managerTemplate;
42-
private string $tagPrefix;
43-
4440
/**
4541
* @param string $managerTemplate sprintf() template for generating the event
4642
* manager's service ID for a connection name
4743
* @param string $tagPrefix Tag prefix for listeners and subscribers
4844
*/
49-
public function __construct(string $connectionsParameter, string $managerTemplate, string $tagPrefix)
50-
{
51-
$this->connectionsParameter = $connectionsParameter;
52-
$this->managerTemplate = $managerTemplate;
53-
$this->tagPrefix = $tagPrefix;
45+
public function __construct(
46+
private readonly string $connectionsParameter,
47+
private readonly string $managerTemplate,
48+
private readonly string $tagPrefix,
49+
) {
5450
}
5551

5652
/**

DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,6 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
7373
*/
7474
protected $enabledParameter;
7575

76-
/**
77-
* Naming pattern for the configuration service id, for example
78-
* 'doctrine.orm.%s_configuration'.
79-
*/
80-
private string $configurationPattern;
81-
82-
/**
83-
* Method name to call on the configuration service. This depends on the
84-
* Doctrine implementation. For example addEntityNamespace.
85-
*/
86-
private string $registerAliasMethodName;
87-
88-
/**
89-
* Map of alias to namespace.
90-
*
91-
* @var string[]
92-
*/
93-
private array $aliasMap;
94-
9576
/**
9677
* The $managerParameters is an ordered list of container parameters that could provide the
9778
* name of the manager to register these namespaces and alias on. The first non-empty name
@@ -108,24 +89,32 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
10889
* @param string|false $enabledParameter Service container parameter that must be
10990
* present to enable the mapping. Set to false
11091
* to not do any check, optional.
111-
* @param string $configurationPattern Pattern for the Configuration service name
112-
* @param string $registerAliasMethodName Name of Configuration class method to
113-
* register alias
92+
* @param string $configurationPattern Pattern for the Configuration service name,
93+
* for example 'doctrine.orm.%s_configuration'.
94+
* @param string $registerAliasMethodName Method name to call on the configuration service. This
95+
* depends on the Doctrine implementation.
96+
* For example addEntityNamespace.
11497
* @param string[] $aliasMap Map of alias to namespace
11598
*/
116-
public function __construct(Definition|Reference $driver, array $namespaces, array $managerParameters, string $driverPattern, string|false $enabledParameter = false, string $configurationPattern = '', string $registerAliasMethodName = '', array $aliasMap = [])
117-
{
99+
public function __construct(
100+
Definition|Reference $driver,
101+
array $namespaces,
102+
array $managerParameters,
103+
string $driverPattern,
104+
string|false $enabledParameter = false,
105+
private readonly string $configurationPattern = '',
106+
private readonly string $registerAliasMethodName = '',
107+
private readonly array $aliasMap = [],
108+
) {
118109
$this->driver = $driver;
119110
$this->namespaces = $namespaces;
120111
$this->managerParameters = $managerParameters;
121112
$this->driverPattern = $driverPattern;
122113
$this->enabledParameter = $enabledParameter;
123-
if (\count($aliasMap) && (!$configurationPattern || !$registerAliasMethodName)) {
114+
115+
if ($aliasMap && (!$configurationPattern || !$registerAliasMethodName)) {
124116
throw new \InvalidArgumentException('configurationPattern and registerAliasMethodName are required to register namespace alias.');
125117
}
126-
$this->configurationPattern = $configurationPattern;
127-
$this->registerAliasMethodName = $registerAliasMethodName;
128-
$this->aliasMap = $aliasMap;
129118
}
130119

131120
/**

DependencyInjection/Security/UserProvider/EntityFactory.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
*/
2525
class EntityFactory implements UserProviderFactoryInterface
2626
{
27-
private string $key;
28-
private string $providerId;
29-
30-
public function __construct(string $key, string $providerId)
31-
{
32-
$this->key = $key;
33-
$this->providerId = $providerId;
27+
public function __construct(
28+
private readonly string $key,
29+
private readonly string $providerId,
30+
) {
3431
}
3532

3633
/**

Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
*/
2323
class DoctrineChoiceLoader extends AbstractChoiceLoader
2424
{
25-
private ObjectManager $manager;
26-
private string $class;
27-
private ?IdReader $idReader;
28-
private ?EntityLoaderInterface $objectLoader;
25+
/** @var class-string */
26+
private readonly string $class;
2927

3028
/**
3129
* Creates a new choice loader.
@@ -36,18 +34,17 @@ class DoctrineChoiceLoader extends AbstractChoiceLoader
3634
*
3735
* @param string $class The class name of the loaded objects
3836
*/
39-
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
40-
{
41-
$classMetadata = $manager->getClassMetadata($class);
42-
37+
public function __construct(
38+
private readonly ObjectManager $manager,
39+
string $class,
40+
private readonly ?IdReader $idReader = null,
41+
private readonly ?EntityLoaderInterface $objectLoader = null,
42+
) {
4343
if ($idReader && !$idReader->isSingleId()) {
4444
throw new \InvalidArgumentException(sprintf('The second argument "$idReader" of "%s" must be null when the query cannot be optimized because of composite id fields.', __METHOD__));
4545
}
4646

47-
$this->manager = $manager;
48-
$this->class = $classMetadata->getName();
49-
$this->idReader = $idReader;
50-
$this->objectLoader = $objectLoader;
47+
$this->class = $manager->getClassMetadata($class)->getName();
5148
}
5249

5350
protected function loadChoices(): iterable

Form/ChoiceList/IdReader.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,35 @@
2424
*/
2525
class IdReader
2626
{
27-
private ObjectManager $om;
28-
private ClassMetadata $classMetadata;
29-
private bool $singleId;
30-
private bool $intId;
31-
private string $idField;
32-
private ?self $associationIdReader = null;
33-
34-
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
35-
{
27+
private readonly bool $singleId;
28+
private readonly bool $intId;
29+
private readonly string $idField;
30+
private readonly ?self $associationIdReader;
31+
32+
public function __construct(
33+
private readonly ObjectManager $om,
34+
private readonly ClassMetadata $classMetadata,
35+
) {
3636
$ids = $classMetadata->getIdentifierFieldNames();
3737
$idType = $classMetadata->getTypeOfField(current($ids));
3838

39-
$this->om = $om;
40-
$this->classMetadata = $classMetadata;
41-
$this->singleId = 1 === \count($ids);
42-
$this->intId = $this->singleId && \in_array($idType, ['integer', 'smallint', 'bigint']);
39+
$singleId = 1 === \count($ids);
4340
$this->idField = current($ids);
4441

4542
// single field association are resolved, since the schema column could be an int
46-
if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
43+
if ($singleId && $classMetadata->hasAssociation($this->idField)) {
4744
$this->associationIdReader = new self($om, $om->getClassMetadata(
4845
$classMetadata->getAssociationTargetClass($this->idField)
4946
));
5047

51-
$this->singleId = $this->associationIdReader->isSingleId();
48+
$singleId = $this->associationIdReader->isSingleId();
5249
$this->intId = $this->associationIdReader->isIntId();
50+
} else {
51+
$this->intId = $singleId && \in_array($idType, ['integer', 'smallint', 'bigint']);
52+
$this->associationIdReader = null;
5353
}
54+
55+
$this->singleId = $singleId;
5456
}
5557

5658
/**

Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,9 @@
2626
*/
2727
class ORMQueryBuilderLoader implements EntityLoaderInterface
2828
{
29-
/**
30-
* Contains the query builder that builds the query for fetching the
31-
* entities.
32-
*
33-
* This property should only be accessed through queryBuilder.
34-
*/
35-
private QueryBuilder $queryBuilder;
36-
37-
public function __construct(QueryBuilder $queryBuilder)
38-
{
39-
$this->queryBuilder = $queryBuilder;
29+
public function __construct(
30+
private readonly QueryBuilder $queryBuilder,
31+
) {
4032
}
4133

4234
public function getEntities(): array

0 commit comments

Comments
 (0)