From 5aa9c470590d2619022df0f0a9ff25fb83545052 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 13 Oct 2023 14:09:03 +0200 Subject: [PATCH] [DoctrineBridge] Spread some PHP 8 love --- .../Doctrine/CacheWarmer/ProxyCacheWarmer.php | 8 ++-- .../DataCollector/ObjectParameter.php | 12 +++-- .../DataFixtures/ContainerAwareLoader.php | 8 ++-- .../CompilerPass/DoctrineValidationPass.php | 8 ++-- ...gisterEventListenersAndSubscribersPass.php | 14 +++--- .../CompilerPass/RegisterMappingsPass.php | 45 +++++++------------ .../Security/UserProvider/EntityFactory.php | 11 ++--- .../Form/ChoiceList/DoctrineChoiceLoader.php | 21 ++++----- .../Doctrine/Form/ChoiceList/IdReader.php | 32 ++++++------- .../Form/ChoiceList/ORMQueryBuilderLoader.php | 14 ++---- .../Doctrine/IdGenerator/UlidGenerator.php | 8 ++-- .../Doctrine/IdGenerator/UuidGenerator.php | 2 +- ...rineClearEntityManagerWorkerSubscriber.php | 8 ++-- ...octrineOpenTransactionLoggerMiddleware.php | 11 +++-- .../Doctrine/Middleware/Debug/Connection.php | 6 +-- .../Middleware/Debug/DBAL3/Connection.php | 6 +-- .../Middleware/Debug/DBAL3/Statement.php | 8 ++-- .../Doctrine/Middleware/Debug/Middleware.php | 6 +-- .../Doctrine/Middleware/Debug/Statement.php | 6 +-- .../PropertyInfo/DoctrineExtractor.php | 8 ++-- ...DoctrineDbalCacheAdapterSchemaListener.php | 5 ++- .../LockStoreSchemaListener.php | 5 ++- ...ssengerTransportDoctrineSchemaListener.php | 5 ++- ...rMeTokenProviderDoctrineSchemaListener.php | 5 ++- .../RememberMe/DoctrineTokenProvider.php | 8 ++-- .../Security/User/EntityUserProvider.php | 16 +++---- .../Tests/Fixtures/AssociationEntity.php | 21 +++------ .../Tests/Fixtures/AssociationEntity2.php | 21 +++------ .../Doctrine/Tests/Fixtures/BaseUser.php | 24 ++-------- .../AnnotationsBundle/Entity/Person.php | 17 +++---- .../Entity/Person.php | 17 +++---- .../AnnotatedEntity/Person.php | 17 +++---- .../AttributesBundle/Entity/Person.php | 17 +++---- .../src/Entity/Person.php | 17 +++---- .../NewXmlBundle/src/Entity/Person.php | 14 +++--- .../Bundles/PhpBundle/Entity/Person.php | 14 +++--- .../SrcXmlBundle/src/Entity/Person.php | 14 +++--- .../Bundles/XmlBundle/Entity/Person.php | 14 +++--- .../Bundles/YamlBundle/Entity/Person.php | 14 +++--- .../Tests/Fixtures/CompositeIntIdEntity.php | 12 ++--- .../CompositeObjectNoToStringIdEntity.php | 31 +++++-------- .../Fixtures/CompositeStringIdEntity.php | 20 ++++----- .../Tests/Fixtures/DoubleNameEntity.php | 20 ++++----- .../Fixtures/DoubleNullableNameEntity.php | 20 ++++----- .../Tests/Fixtures/Embeddable/Identifier.php | 8 ++-- .../Fixtures/EmbeddedIdentifierEntity.php | 7 +-- .../Tests/Fixtures/GroupableEntity.php | 20 ++++----- .../Doctrine/Tests/Fixtures/GuidIdEntity.php | 11 +++-- .../Bridge/Doctrine/Tests/Fixtures/Person.php | 17 +++---- .../SingleAssociationToIntIdEntity.php | 17 +++---- .../Tests/Fixtures/SingleIntIdEntity.php | 19 ++++---- .../Fixtures/SingleIntIdNoToStringEntity.php | 15 +++---- .../SingleIntIdStringWrapperNameEntity.php | 16 +++---- .../Fixtures/SingleStringCastableIdEntity.php | 20 ++++----- .../Tests/Fixtures/SingleStringIdEntity.php | 15 +++---- .../Tests/Fixtures/Type/StringWrapper.php | 8 ++-- .../Doctrine/Tests/Fixtures/UlidIdEntity.php | 11 +++-- .../Bridge/Doctrine/Tests/Fixtures/User.php | 20 ++++----- .../Doctrine/Tests/Fixtures/UuidIdEntity.php | 11 +++-- .../ChoiceList/ORMQueryBuilderLoaderTest.php | 6 +-- .../Constraints/UniqueEntityValidator.php | 8 ++-- .../Doctrine/Validator/DoctrineLoader.php | 11 ++--- 62 files changed, 337 insertions(+), 513 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php index 0c107c066bac4..9f1f97e7f93db 100644 --- a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php +++ b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php @@ -24,11 +24,9 @@ */ class ProxyCacheWarmer implements CacheWarmerInterface { - private ManagerRegistry $registry; - - public function __construct(ManagerRegistry $registry) - { - $this->registry = $registry; + public function __construct( + private readonly ManagerRegistry $registry, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/ObjectParameter.php b/src/Symfony/Bridge/Doctrine/DataCollector/ObjectParameter.php index 384ba0efeb869..ce134cae450b0 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/ObjectParameter.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/ObjectParameter.php @@ -13,16 +13,14 @@ final class ObjectParameter { - private object $object; - private ?\Throwable $error; private bool $stringable; private string $class; - public function __construct(object $object, ?\Throwable $error) - { - $this->object = $object; - $this->error = $error; - $this->stringable = \is_callable([$object, '__toString']); + public function __construct( + private readonly object $object, + private readonly ?\Throwable $error, + ) { + $this->stringable = $this->object instanceof \Stringable; $this->class = $object::class; } diff --git a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php index 448da935d9347..64b6961800c21 100644 --- a/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php +++ b/src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php @@ -29,11 +29,9 @@ */ class ContainerAwareLoader extends Loader { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; + public function __construct( + private readonly ContainerInterface $container, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php index 83bfffaf2724e..e0486af27389f 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/DoctrineValidationPass.php @@ -21,11 +21,9 @@ */ class DoctrineValidationPass implements CompilerPassInterface { - private string $managerType; - - public function __construct(string $managerType) - { - $this->managerType = $managerType; + public function __construct( + private readonly string $managerType, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php index 72b4b786766f5..d7541cbe00891 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php @@ -30,7 +30,6 @@ */ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface { - private string $connectionsParameter; private array $connections; /** @@ -38,19 +37,16 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface */ private array $eventManagers = []; - private string $managerTemplate; - private string $tagPrefix; - /** * @param string $managerTemplate sprintf() template for generating the event * manager's service ID for a connection name * @param string $tagPrefix Tag prefix for listeners and subscribers */ - public function __construct(string $connectionsParameter, string $managerTemplate, string $tagPrefix) - { - $this->connectionsParameter = $connectionsParameter; - $this->managerTemplate = $managerTemplate; - $this->tagPrefix = $tagPrefix; + public function __construct( + private readonly string $connectionsParameter, + private readonly string $managerTemplate, + private readonly string $tagPrefix, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php index 1a3f227c6d100..7da87eca25764 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php @@ -73,25 +73,6 @@ abstract class RegisterMappingsPass implements CompilerPassInterface */ protected $enabledParameter; - /** - * Naming pattern for the configuration service id, for example - * 'doctrine.orm.%s_configuration'. - */ - private string $configurationPattern; - - /** - * Method name to call on the configuration service. This depends on the - * Doctrine implementation. For example addEntityNamespace. - */ - private string $registerAliasMethodName; - - /** - * Map of alias to namespace. - * - * @var string[] - */ - private array $aliasMap; - /** * The $managerParameters is an ordered list of container parameters that could provide the * 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 * @param string|false $enabledParameter Service container parameter that must be * present to enable the mapping. Set to false * to not do any check, optional. - * @param string $configurationPattern Pattern for the Configuration service name - * @param string $registerAliasMethodName Name of Configuration class method to - * register alias + * @param string $configurationPattern Pattern for the Configuration service name, + * for example 'doctrine.orm.%s_configuration'. + * @param string $registerAliasMethodName Method name to call on the configuration service. This + * depends on the Doctrine implementation. + * For example addEntityNamespace. * @param string[] $aliasMap Map of alias to namespace */ - public function __construct(Definition|Reference $driver, array $namespaces, array $managerParameters, string $driverPattern, string|false $enabledParameter = false, string $configurationPattern = '', string $registerAliasMethodName = '', array $aliasMap = []) - { + public function __construct( + Definition|Reference $driver, + array $namespaces, + array $managerParameters, + string $driverPattern, + string|false $enabledParameter = false, + private readonly string $configurationPattern = '', + private readonly string $registerAliasMethodName = '', + private readonly array $aliasMap = [], + ) { $this->driver = $driver; $this->namespaces = $namespaces; $this->managerParameters = $managerParameters; $this->driverPattern = $driverPattern; $this->enabledParameter = $enabledParameter; - if (\count($aliasMap) && (!$configurationPattern || !$registerAliasMethodName)) { + + if ($aliasMap && (!$configurationPattern || !$registerAliasMethodName)) { throw new \InvalidArgumentException('configurationPattern and registerAliasMethodName are required to register namespace alias.'); } - $this->configurationPattern = $configurationPattern; - $this->registerAliasMethodName = $registerAliasMethodName; - $this->aliasMap = $aliasMap; } /** diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php index 80ee258438d24..fa75b3c69554d 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/Security/UserProvider/EntityFactory.php @@ -24,13 +24,10 @@ */ class EntityFactory implements UserProviderFactoryInterface { - private string $key; - private string $providerId; - - public function __construct(string $key, string $providerId) - { - $this->key = $key; - $this->providerId = $providerId; + public function __construct( + private readonly string $key, + private readonly string $providerId, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php index c2d29a1f7cc79..c69fe5ae75b12 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php @@ -22,10 +22,8 @@ */ class DoctrineChoiceLoader extends AbstractChoiceLoader { - private ObjectManager $manager; - private string $class; - private ?IdReader $idReader; - private ?EntityLoaderInterface $objectLoader; + /** @var class-string */ + private readonly string $class; /** * Creates a new choice loader. @@ -36,18 +34,17 @@ class DoctrineChoiceLoader extends AbstractChoiceLoader * * @param string $class The class name of the loaded objects */ - public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null) - { - $classMetadata = $manager->getClassMetadata($class); - + public function __construct( + private readonly ObjectManager $manager, + string $class, + private readonly ?IdReader $idReader = null, + private readonly ?EntityLoaderInterface $objectLoader = null, + ) { if ($idReader && !$idReader->isSingleId()) { 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__)); } - $this->manager = $manager; - $this->class = $classMetadata->getName(); - $this->idReader = $idReader; - $this->objectLoader = $objectLoader; + $this->class = $manager->getClassMetadata($class)->getName(); } protected function loadChoices(): iterable diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php index 15a685bbc9bef..b03c832ac13e6 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php @@ -24,33 +24,35 @@ */ class IdReader { - private ObjectManager $om; - private ClassMetadata $classMetadata; - private bool $singleId; - private bool $intId; - private string $idField; - private ?self $associationIdReader = null; - - public function __construct(ObjectManager $om, ClassMetadata $classMetadata) - { + private readonly bool $singleId; + private readonly bool $intId; + private readonly string $idField; + private readonly ?self $associationIdReader; + + public function __construct( + private readonly ObjectManager $om, + private readonly ClassMetadata $classMetadata, + ) { $ids = $classMetadata->getIdentifierFieldNames(); $idType = $classMetadata->getTypeOfField(current($ids)); - $this->om = $om; - $this->classMetadata = $classMetadata; - $this->singleId = 1 === \count($ids); - $this->intId = $this->singleId && \in_array($idType, ['integer', 'smallint', 'bigint']); + $singleId = 1 === \count($ids); $this->idField = current($ids); // single field association are resolved, since the schema column could be an int - if ($this->singleId && $classMetadata->hasAssociation($this->idField)) { + if ($singleId && $classMetadata->hasAssociation($this->idField)) { $this->associationIdReader = new self($om, $om->getClassMetadata( $classMetadata->getAssociationTargetClass($this->idField) )); - $this->singleId = $this->associationIdReader->isSingleId(); + $singleId = $this->associationIdReader->isSingleId(); $this->intId = $this->associationIdReader->isIntId(); + } else { + $this->intId = $singleId && \in_array($idType, ['integer', 'smallint', 'bigint']); + $this->associationIdReader = null; } + + $this->singleId = $singleId; } /** diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index e3a4c021f0ce2..c4663307468bc 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -26,17 +26,9 @@ */ class ORMQueryBuilderLoader implements EntityLoaderInterface { - /** - * Contains the query builder that builds the query for fetching the - * entities. - * - * This property should only be accessed through queryBuilder. - */ - private QueryBuilder $queryBuilder; - - public function __construct(QueryBuilder $queryBuilder) - { - $this->queryBuilder = $queryBuilder; + public function __construct( + private readonly QueryBuilder $queryBuilder, + ) { } public function getEntities(): array diff --git a/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php index 95573309f9e4b..ab539486b4dcf 100644 --- a/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UlidGenerator.php @@ -19,11 +19,9 @@ final class UlidGenerator extends AbstractIdGenerator { - private ?UlidFactory $factory; - - public function __construct(UlidFactory $factory = null) - { - $this->factory = $factory; + public function __construct( + private readonly ?UlidFactory $factory = null + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/IdGenerator/UuidGenerator.php b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidGenerator.php index 8c366fd80d734..408b1e19af995 100644 --- a/src/Symfony/Bridge/Doctrine/IdGenerator/UuidGenerator.php +++ b/src/Symfony/Bridge/Doctrine/IdGenerator/UuidGenerator.php @@ -22,7 +22,7 @@ final class UuidGenerator extends AbstractIdGenerator { - private UuidFactory $protoFactory; + private readonly UuidFactory $protoFactory; private UuidFactory|NameBasedUuidFactory|RandomBasedUuidFactory|TimeBasedUuidFactory $factory; private ?string $entityGetter = null; diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php index 38618fc15e5ba..9fa7ae929c90f 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php @@ -23,11 +23,9 @@ */ class DoctrineClearEntityManagerWorkerSubscriber implements EventSubscriberInterface { - private ManagerRegistry $managerRegistry; - - public function __construct(ManagerRegistry $managerRegistry) - { - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineOpenTransactionLoggerMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineOpenTransactionLoggerMiddleware.php index 31c83d8e2afc0..cd11473a823b5 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineOpenTransactionLoggerMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineOpenTransactionLoggerMiddleware.php @@ -24,13 +24,12 @@ */ class DoctrineOpenTransactionLoggerMiddleware extends AbstractDoctrineMiddleware { - private ?LoggerInterface $logger; - - public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null, LoggerInterface $logger = null) - { + public function __construct( + ManagerRegistry $managerRegistry, + string $entityManagerName = null, + private readonly ?LoggerInterface $logger = null, + ) { parent::__construct($managerRegistry, $entityManagerName); - - $this->logger = $logger; } protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php index a0d642dd7d250..e20510c3e625d 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php @@ -26,9 +26,9 @@ final class Connection extends AbstractConnectionMiddleware { public function __construct( ConnectionInterface $connection, - private DebugDataHolder $debugDataHolder, - private ?Stopwatch $stopwatch, - private string $connectionName, + private readonly DebugDataHolder $debugDataHolder, + private readonly ?Stopwatch $stopwatch, + private readonly string $connectionName, ) { parent::__construct($connection); } diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Connection.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Connection.php index e3bec4d611780..8d01c02d1292e 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Connection.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Connection.php @@ -29,9 +29,9 @@ final class Connection extends AbstractConnectionMiddleware public function __construct( ConnectionInterface $connection, - private DebugDataHolder $debugDataHolder, - private ?Stopwatch $stopwatch, - private string $connectionName, + private readonly DebugDataHolder $debugDataHolder, + private readonly ?Stopwatch $stopwatch, + private readonly string $connectionName, ) { parent::__construct($connection); } diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Statement.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Statement.php index 53b117eaba3e5..cd059f80d99e2 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Statement.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/DBAL3/Statement.php @@ -26,14 +26,14 @@ */ final class Statement extends AbstractStatementMiddleware { - private Query $query; + private readonly Query $query; public function __construct( StatementInterface $statement, - private DebugDataHolder $debugDataHolder, - private string $connectionName, + private readonly DebugDataHolder $debugDataHolder, + private readonly string $connectionName, string $sql, - private ?Stopwatch $stopwatch = null, + private readonly ?Stopwatch $stopwatch = null, ) { $this->query = new Query($sql); diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Middleware.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Middleware.php index 56b03f51335a8..5f8a2462377f5 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Middleware.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Middleware.php @@ -23,9 +23,9 @@ final class Middleware implements MiddlewareInterface { public function __construct( - private DebugDataHolder $debugDataHolder, - private ?Stopwatch $stopwatch, - private string $connectionName = 'default', + private readonly DebugDataHolder $debugDataHolder, + private readonly ?Stopwatch $stopwatch, + private readonly string $connectionName = 'default', ) { } diff --git a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php index 3f4ba10fc2138..85e6c35584604 100644 --- a/src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php +++ b/src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php @@ -29,10 +29,10 @@ final class Statement extends AbstractStatementMiddleware public function __construct( StatementInterface $statement, - private DebugDataHolder $debugDataHolder, - private string $connectionName, + private readonly DebugDataHolder $debugDataHolder, + private readonly string $connectionName, string $sql, - private ?Stopwatch $stopwatch = null, + private readonly ?Stopwatch $stopwatch = null, ) { parent::__construct($statement); diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 34b0e55c64c52..89edf1ce2d2ff 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -30,11 +30,9 @@ */ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface { - private EntityManagerInterface $entityManager; - - public function __construct(EntityManagerInterface $entityManager) - { - $this->entityManager = $entityManager; + public function __construct( + private readonly EntityManagerInterface $entityManager, + ) { } public function getProperties(string $class, array $context = []): ?array diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaListener.php b/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaListener.php index 7be883db807a8..ee2e4270a3383 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaListener.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/DoctrineDbalCacheAdapterSchemaListener.php @@ -23,8 +23,9 @@ class DoctrineDbalCacheAdapterSchemaListener extends AbstractSchemaListener /** * @param iterable $dbalAdapters */ - public function __construct(private iterable $dbalAdapters) - { + public function __construct( + private readonly iterable $dbalAdapters, + ) { } public function postGenerateSchema(GenerateSchemaEventArgs $event): void diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/LockStoreSchemaListener.php b/src/Symfony/Bridge/Doctrine/SchemaListener/LockStoreSchemaListener.php index 5ab591d318225..a85d159df837b 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/LockStoreSchemaListener.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/LockStoreSchemaListener.php @@ -21,8 +21,9 @@ final class LockStoreSchemaListener extends AbstractSchemaListener /** * @param iterable $stores */ - public function __construct(private iterable $stores) - { + public function __construct( + private readonly iterable $stores, + ) { } public function postGenerateSchema(GenerateSchemaEventArgs $event): void diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/MessengerTransportDoctrineSchemaListener.php b/src/Symfony/Bridge/Doctrine/SchemaListener/MessengerTransportDoctrineSchemaListener.php index f5416115cba8f..ce3f0173f0558 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/MessengerTransportDoctrineSchemaListener.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/MessengerTransportDoctrineSchemaListener.php @@ -26,8 +26,9 @@ class MessengerTransportDoctrineSchemaListener extends AbstractSchemaListener /** * @param iterable $transports */ - public function __construct(private iterable $transports) - { + public function __construct( + private readonly iterable $transports, + ) { } public function postGenerateSchema(GenerateSchemaEventArgs $event): void diff --git a/src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaListener.php b/src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaListener.php index a7f4c49d58784..60027e913930b 100644 --- a/src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaListener.php +++ b/src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaListener.php @@ -24,8 +24,9 @@ class RememberMeTokenProviderDoctrineSchemaListener extends AbstractSchemaListen /** * @param iterable $rememberMeHandlers */ - public function __construct(private iterable $rememberMeHandlers) - { + public function __construct( + private readonly iterable $rememberMeHandlers, + ) { } public function postGenerateSchema(GenerateSchemaEventArgs $event): void diff --git a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php index f5d6d8ae94ad8..8f5fa00e6ff2a 100644 --- a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php @@ -45,11 +45,9 @@ */ class DoctrineTokenProvider implements TokenProviderInterface, TokenVerifierInterface { - private Connection $conn; - - public function __construct(Connection $conn) - { - $this->conn = $conn; + public function __construct( + private readonly Connection $conn, + ) { } public function loadTokenBySeries(string $series): PersistentTokenInterface diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 0b82520f6cc4f..22ec621a2b705 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -37,18 +37,14 @@ */ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInterface { - private ManagerRegistry $registry; - private ?string $managerName; - private string $classOrAlias; private string $class; - private ?string $property; - public function __construct(ManagerRegistry $registry, string $classOrAlias, string $property = null, string $managerName = null) - { - $this->registry = $registry; - $this->managerName = $managerName; - $this->classOrAlias = $classOrAlias; - $this->property = $property; + public function __construct( + private readonly ManagerRegistry $registry, + private readonly string $classOrAlias, + private readonly ?string $property = null, + private readonly ?string $managerName = null, + ) { } public function loadUserByIdentifier(string $identifier): UserInterface diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php index 65ef0e882c272..13d16d81988c9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity.php @@ -16,23 +16,14 @@ #[ORM\Entity] class AssociationEntity { - /** - * @var int - */ - #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')] - private $id; + #[ORM\Id, ORM\GeneratedValue, ORM\Column] + private ?int $id = null; - /** - * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity - */ - #[ORM\ManyToOne(targetEntity: SingleIntIdEntity::class)] - public $single; + #[ORM\ManyToOne] + public ?SingleIntIdEntity $single = null; - /** - * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity - */ - #[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)] + #[ORM\ManyToOne] #[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')] #[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')] - public $composite; + public ?CompositeIntIdEntity $composite = null; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity2.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity2.php index b74ca502eef8d..ae7fea027ed6c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity2.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/AssociationEntity2.php @@ -16,23 +16,14 @@ #[ORM\Entity] class AssociationEntity2 { - /** - * @var int - */ - #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')] - private $id; + #[ORM\Id, ORM\GeneratedValue, ORM\Column] + private ?int $id = null; - /** - * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity - */ - #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class)] - public $single; + #[ORM\ManyToOne] + public ?SingleIntIdNoToStringEntity $single = null; - /** - * @var \Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity - */ - #[ORM\ManyToOne(targetEntity: CompositeIntIdEntity::class)] + #[ORM\ManyToOne] #[ORM\JoinColumn(name: 'composite_id1', referencedColumnName: 'id1')] #[ORM\JoinColumn(name: 'composite_id2', referencedColumnName: 'id2')] - public $composite; + public ?CompositeIntIdEntity $composite = null; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/BaseUser.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/BaseUser.php index c8be89cc760e0..3c0869988b629 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/BaseUser.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/BaseUser.php @@ -11,30 +11,14 @@ namespace Symfony\Bridge\Doctrine\Tests\Fixtures; -/** - * Class BaseUser. - */ class BaseUser { - /** - * @var int - */ - private $id; - - /** - * @var string - */ - private $username; - private $enabled; - /** - * BaseUser constructor. - */ - public function __construct(int $id, string $username) - { - $this->id = $id; - $this->username = $username; + public function __construct( + private readonly int $id, + private readonly string $username, + ) { } public function getId(): int diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsBundle/Entity/Person.php index 45868ec5e3665..3e2a44f15944d 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsBundle/Entity/Person.php @@ -18,20 +18,17 @@ #[Entity] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php index eb88c397c12dc..e38dd8eea3ae8 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AnnotationsOneLineBundle/Entity/Person.php @@ -18,20 +18,17 @@ #[Entity] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/AnnotatedEntity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/AnnotatedEntity/Person.php index 96296394ef739..340f39bbec5ca 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/AnnotatedEntity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/AnnotatedEntity/Person.php @@ -18,20 +18,17 @@ #[Entity] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/Entity/Person.php index 6b445b198457f..f71ea28955bf0 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/AttributesBundle/Entity/Person.php @@ -18,20 +18,17 @@ #[Entity] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewAnnotationsBundle/src/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewAnnotationsBundle/src/Entity/Person.php index a1887d9abe584..ca068d9f89db0 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewAnnotationsBundle/src/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewAnnotationsBundle/src/Entity/Person.php @@ -18,20 +18,17 @@ #[Entity] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewXmlBundle/src/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewXmlBundle/src/Entity/Person.php index 3adfa62aa90fe..a7ef8798ce68e 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewXmlBundle/src/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/NewXmlBundle/src/Entity/Person.php @@ -13,18 +13,14 @@ class Person { - protected $id; - - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + protected int $id, + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/PhpBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/PhpBundle/Entity/Person.php index 67937cd3b8bd4..445d58a82c3bc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/PhpBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/PhpBundle/Entity/Person.php @@ -13,18 +13,14 @@ class Person { - protected $id; - - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + protected int $id, + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/SrcXmlBundle/src/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/SrcXmlBundle/src/Entity/Person.php index 445d0d4bd01ab..a68564d7fcf13 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/SrcXmlBundle/src/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/SrcXmlBundle/src/Entity/Person.php @@ -13,18 +13,14 @@ class Person { - protected $id; - - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + protected int $id, + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/XmlBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/XmlBundle/Entity/Person.php index 83c89773e4911..8933e58a4e7bf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/XmlBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/XmlBundle/Entity/Person.php @@ -13,18 +13,14 @@ class Person { - protected $id; - - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + protected int $id, + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/YamlBundle/Entity/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/YamlBundle/Entity/Person.php index 861cf5b652ab2..9cfb69077fba9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/YamlBundle/Entity/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Bundles/YamlBundle/Entity/Person.php @@ -13,18 +13,14 @@ class Person { - protected $id; - - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + protected int $id, + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php index bd3d4506d3c3e..f113c080c04c6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeIntIdEntity.php @@ -18,14 +18,14 @@ #[Entity] class CompositeIntIdEntity { - #[Id, Column(type: 'integer')] - protected $id1; + #[Id, Column] + protected int $id1; - #[Id, Column(type: 'integer')] - protected $id2; + #[Id, Column] + protected int $id2; - #[Column(type: 'string')] - public $name; + #[Column] + public string $name; public function __construct($id1, $id2, $name) { diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeObjectNoToStringIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeObjectNoToStringIdEntity.php index 50556c6b1c3e2..ee584fa45bdaa 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeObjectNoToStringIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeObjectNoToStringIdEntity.php @@ -19,26 +19,17 @@ #[ORM\Entity] class CompositeObjectNoToStringIdEntity { - /** - * @var SingleIntIdNoToStringEntity - */ - #[ORM\Id] - #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])] - #[ORM\JoinColumn(name: 'object_one_id')] - protected $objectOne; - - /** - * @var SingleIntIdNoToStringEntity - */ - #[ORM\Id] - #[ORM\ManyToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['persist'])] - #[ORM\JoinColumn(name: 'object_two_id')] - protected $objectTwo; - - public function __construct(SingleIntIdNoToStringEntity $objectOne, SingleIntIdNoToStringEntity $objectTwo) - { - $this->objectOne = $objectOne; - $this->objectTwo = $objectTwo; + public function __construct( + #[ORM\Id] + #[ORM\ManyToOne(cascade: ['persist'])] + #[ORM\JoinColumn(name: 'object_one_id', nullable: false)] + protected SingleIntIdNoToStringEntity $objectOne, + + #[ORM\Id] + #[ORM\ManyToOne(cascade: ['persist'])] + #[ORM\JoinColumn(name: 'object_two_id', nullable: false)] + protected SingleIntIdNoToStringEntity $objectTwo, + ) { } public function getObjectOne(): SingleIntIdNoToStringEntity diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php index 62875248fd293..d372ee801ea02 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/CompositeStringIdEntity.php @@ -18,20 +18,16 @@ #[Entity] class CompositeStringIdEntity { - #[Id, Column(type: 'string')] - protected $id1; + public function __construct( + #[Id, Column] + protected string $id1, - #[Id, Column(type: 'string')] - protected $id2; + #[Id, Column] + protected string $id2, - #[Column(type: 'string')] - public $name; - - public function __construct($id1, $id2, $name) - { - $this->id1 = $id1; - $this->id2 = $id2; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNameEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNameEntity.php index f039b3a50c40d..d020ee3530d0d 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNameEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNameEntity.php @@ -18,19 +18,15 @@ #[Entity] class DoubleNameEntity { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; + #[Column] + public string $name, - #[Column(type: 'string', nullable: true)] - public $name2; - - public function __construct($id, $name, $name2) - { - $this->id = $id; - $this->name = $name; - $this->name2 = $name2; + #[Column(nullable: true)] + public ?string $name2, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNullableNameEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNullableNameEntity.php index 614d14e47ffbb..7047f9a1d400a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNullableNameEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/DoubleNullableNameEntity.php @@ -18,19 +18,15 @@ #[Entity] class DoubleNullableNameEntity { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string', nullable: true)] - public $name; + #[Column(nullable: true)] + public ?string $name, - #[Column(type: 'string', nullable: true)] - public $name2; - - public function __construct($id, $name, $name2) - { - $this->id = $id; - $this->name = $name; - $this->name2 = $name2; + #[Column(nullable: true)] + public ?string $name2, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Embeddable/Identifier.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Embeddable/Identifier.php index c32dd141b993a..d1f0b2eddfd07 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Embeddable/Identifier.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Embeddable/Identifier.php @@ -11,14 +11,12 @@ namespace Symfony\Bridge\Doctrine\Tests\Fixtures\Embeddable; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Embeddable] class Identifier { - /** - * @var int - */ - #[ORM\Id, ORM\Column(type: 'integer')] - protected $value; + #[ORM\Id, ORM\Column] + protected int $value; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/EmbeddedIdentifierEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/EmbeddedIdentifierEntity.php index 581d4b710a6b9..9c4583b945746 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/EmbeddedIdentifierEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/EmbeddedIdentifierEntity.php @@ -17,9 +17,6 @@ #[ORM\Entity] class EmbeddedIdentifierEntity { - /** - * @var Embeddable\Identifier - */ - #[ORM\Embedded(class: Identifier::class)] - protected $id; + #[ORM\Embedded] + protected Identifier $id; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GroupableEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GroupableEntity.php index 2a232ae0faeda..0bcacb83cf4b4 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GroupableEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GroupableEntity.php @@ -18,19 +18,15 @@ #[Entity] class GroupableEntity { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string', nullable: true)] - public $name; + #[Column(nullable: true)] + public ?string $name, - #[Column(type: 'string', nullable: true)] - public $groupName; - - public function __construct($id, $name, $groupName) - { - $this->id = $id; - $this->name = $name; - $this->groupName = $groupName; + #[Column(nullable: true)] + public ?string $groupName, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php index 80f0fda98478f..50b8512d5932e 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/GuidIdEntity.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Fixtures; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; @@ -18,11 +19,9 @@ #[Entity] class GuidIdEntity { - #[Id, Column(type: 'guid')] - protected $id; - - public function __construct($id) - { - $this->id = $id; + public function __construct( + #[Id, Column(type: Types::GUID)] + protected string $id, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php index fdac47f70ba12..7b84cbc752a35 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Person.php @@ -21,20 +21,17 @@ #[Entity, InheritanceType('SINGLE_TABLE'), DiscriminatorColumn(name: 'discr', type: 'string'), DiscriminatorMap(['person' => 'Person', 'employee' => 'Employee'])] class Person { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleAssociationToIntIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleAssociationToIntIdEntity.php index 4c068e9108a6d..94becf73b5795 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleAssociationToIntIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleAssociationToIntIdEntity.php @@ -19,20 +19,17 @@ #[Entity] class SingleAssociationToIntIdEntity { - #[Id, OneToOne(targetEntity: SingleIntIdNoToStringEntity::class, cascade: ['ALL'])] - protected $entity; + public function __construct( + #[Id, OneToOne(cascade: ['ALL'])] + protected SingleIntIdNoToStringEntity $entity, - #[Column(type: 'string', nullable: true)] - public $name; - - public function __construct(SingleIntIdNoToStringEntity $entity, $name) - { - $this->entity = $entity; - $this->name = $name; + #[Column(nullable: true)] + public ?string $name, + ) { } public function __toString(): string { - return (string) $this->name; + return $this->name; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php index ae0e24773f5c0..0970dea0669a9 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdEntity.php @@ -19,19 +19,16 @@ #[Entity] class SingleIntIdEntity { - #[Id, Column(type: 'integer')] - protected $id; - - #[Column(type: 'string', nullable: true)] - public $name; - #[Column(type: Types::JSON, nullable: true)] - public $phoneNumbers = []; + public mixed $phoneNumbers = []; - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + public function __construct( + #[Id, Column(type: 'integer')] + protected int $id, + + #[Column(type: 'string', nullable: true)] + public ?string $name, + ) { } public function __toString(): string diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdNoToStringEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdNoToStringEntity.php index e78823b83c751..f48e54c2fa3dc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdNoToStringEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdNoToStringEntity.php @@ -18,15 +18,12 @@ #[Entity] class SingleIntIdNoToStringEntity { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string', nullable: true)] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column(nullable: true)] + public ?string $name, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdStringWrapperNameEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdStringWrapperNameEntity.php index 1abafbdf34f18..ff81db65de01f 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdStringWrapperNameEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleIntIdStringWrapperNameEntity.php @@ -14,19 +14,17 @@ use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; +use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapper; #[Entity] class SingleIntIdStringWrapperNameEntity { - #[Id, Column(type: 'integer')] - protected $id; + public function __construct( + #[Id, Column] + protected int $id, - #[Column(type: 'string_wrapper', nullable: true)] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column(type: 'string_wrapper', nullable: true)] + public ?StringWrapper $name, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringCastableIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringCastableIdEntity.php index 192337d727783..b117183c79575 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringCastableIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringCastableIdEntity.php @@ -20,15 +20,15 @@ class SingleStringCastableIdEntity { #[Id, Column(type: 'string'), GeneratedValue(strategy: 'NONE')] - protected $id; + protected StringCastableObjectIdentity $id; - #[Column(type: 'string', nullable: true)] - public $name; + public function __construct( + int $id, - public function __construct($id, $name) - { + #[Column(nullable: true)] + public ?string $name, + ) { $this->id = new StringCastableObjectIdentity($id); - $this->name = $name; } public function __toString(): string @@ -39,11 +39,9 @@ public function __toString(): string class StringCastableObjectIdentity { - protected $id; - - public function __construct($id) - { - $this->id = $id; + public function __construct( + protected readonly int $id, + ) { } public function __toString(): string diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringIdEntity.php index 5e3aee53f94db..1cba78f7c247b 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/SingleStringIdEntity.php @@ -18,16 +18,13 @@ #[Entity] class SingleStringIdEntity { - #[Id, Column(type: 'string')] - protected $id; + public function __construct( + #[Id, Column] + protected string $id, - #[Column(type: 'string')] - public $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; + #[Column] + public string $name, + ) { } public function __toString(): string diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.php index 941ab3ed48ee8..299304016e45b 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/Type/StringWrapper.php @@ -13,11 +13,9 @@ class StringWrapper { - private $string; - - public function __construct(string $string = null) - { - $this->string = $string; + public function __construct( + private readonly ?string $string = null + ) { } public function getString(): string diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UlidIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UlidIdEntity.php index e101c01856941..aee40a699d74f 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UlidIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UlidIdEntity.php @@ -14,15 +14,14 @@ use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; +use Symfony\Component\Uid\Ulid; #[Entity] class UlidIdEntity { - #[Id, Column(type: 'ulid')] - protected $id; - - public function __construct($id) - { - $this->id = $id; + public function __construct( + #[Id, Column(type: 'ulid')] + protected Ulid $id, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/User.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/User.php index 44f01849d91b6..0fdc71abb434c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/User.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/User.php @@ -20,20 +20,16 @@ #[Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - #[Id, Column(type: 'integer')] - protected $id1; + public function __construct( + #[Id, Column] + protected ?int $id1, - #[Id, Column(type: 'integer')] - protected $id2; + #[Id, Column] + protected ?int $id2, - #[Column(type: 'string')] - public $name; - - public function __construct($id1, $id2, $name) - { - $this->id1 = $id1; - $this->id2 = $id2; - $this->name = $name; + #[Column] + public string $name, + ) { } public function getRoles(): array diff --git a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php index 84613b6157211..8399c5899fa67 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Fixtures/UuidIdEntity.php @@ -14,15 +14,14 @@ use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\Id; +use Symfony\Component\Uid\Uuid; #[Entity] class UuidIdEntity { - #[Id, Column(type: 'uuid')] - protected $id; - - public function __construct($id) - { - $this->id = $id; + public function __construct( + #[Id, Column(type: 'uuid')] + protected Uuid $id, + ) { } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 67f600f5d145e..a70f280bd0fce 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -115,7 +115,7 @@ public function testFilterNonIntegerValues() /** * @dataProvider provideGuidEntityClasses */ - public function testFilterEmptyUuids($entityClass) + public function testFilterEmptyUuids(string $entityClass) { $em = DoctrineTestHelper::createTestEntityManager(); @@ -149,7 +149,7 @@ public function testFilterEmptyUuids($entityClass) /** * @dataProvider provideUidEntityClasses */ - public function testFilterUid($entityClass) + public function testFilterUid(string $entityClass) { if (Type::hasType('uuid')) { Type::overrideType('uuid', UuidType::class); @@ -192,7 +192,7 @@ public function testFilterUid($entityClass) /** * @dataProvider provideUidEntityClasses */ - public function testUidThrowProperException($entityClass) + public function testUidThrowProperException(string $entityClass) { if (Type::hasType('uuid')) { Type::overrideType('uuid', UuidType::class); diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index a69bcad8ef323..186dffe92282c 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -27,11 +27,9 @@ */ class UniqueEntityValidator extends ConstraintValidator { - private ManagerRegistry $registry; - - public function __construct(ManagerRegistry $registry) - { - $this->registry = $registry; + public function __construct( + private readonly ManagerRegistry $registry, + ) { } /** diff --git a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php index 473405287203a..e3a939955ca84 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php +++ b/src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php @@ -33,13 +33,10 @@ final class DoctrineLoader implements LoaderInterface { use AutoMappingTrait; - private EntityManagerInterface $entityManager; - private ?string $classValidatorRegexp; - - public function __construct(EntityManagerInterface $entityManager, string $classValidatorRegexp = null) - { - $this->entityManager = $entityManager; - $this->classValidatorRegexp = $classValidatorRegexp; + public function __construct( + private readonly EntityManagerInterface $entityManager, + private readonly ?string $classValidatorRegexp = null, + ) { } public function loadClassMetadata(ClassMetadata $metadata): bool