From 214a912b37b6acbc686f64d22694e848816cc64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 15 Jun 2022 08:57:25 +0200 Subject: [PATCH] Migrate more code to PHP8 --- .../Tools/AttachEntityListenersListener.php | 16 ++++----- .../ORM/Tools/DebugUnitOfWorkListener.php | 36 +++++-------------- .../ORM/Tools/ResolveTargetEntityListener.php | 18 +++------- .../ORM/Utility/IdentifierFlattener.php | 28 ++++++--------- 4 files changed, 31 insertions(+), 67 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php index d1657367ee..72908a8663 100644 --- a/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php +++ b/lib/Doctrine/ORM/Tools/AttachEntityListenersListener.php @@ -14,7 +14,7 @@ class AttachEntityListenersListener { /** @var mixed[][] */ - private $entityListeners = []; + private array $entityListeners = []; /** * Adds a entity listener for a specific entity. @@ -23,11 +23,13 @@ class AttachEntityListenersListener * @param string $listenerClass The listener class. * @param string $eventName The entity lifecycle event. * @param string|null $listenerCallback The listener callback method or NULL to use $eventName. - * - * @return void */ - public function addEntityListener($entityClass, $listenerClass, $eventName, $listenerCallback = null) - { + public function addEntityListener( + string $entityClass, + string $listenerClass, + string $eventName, + $listenerCallback = null + ): void { $this->entityListeners[ltrim($entityClass, '\\')][] = [ 'event' => $eventName, 'class' => $listenerClass, @@ -37,10 +39,8 @@ public function addEntityListener($entityClass, $listenerClass, $eventName, $lis /** * Processes event and attach the entity listener. - * - * @return void */ - public function loadClassMetadata(LoadClassMetadataEventArgs $event) + public function loadClassMetadata(LoadClassMetadataEventArgs $event): void { $metadata = $event->getClassMetadata(); diff --git a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php index ab8b301c20..092b865710 100644 --- a/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php +++ b/lib/Doctrine/ORM/Tools/DebugUnitOfWorkListener.php @@ -26,40 +26,26 @@ */ class DebugUnitOfWorkListener { - /** @var string */ - private $file; - - /** @var string */ - private $context; - /** * Pass a stream and context information for the debugging session. * * The stream can be php://output to print to the screen. - * - * @param string $file - * @param string $context */ - public function __construct($file = 'php://output', $context = '') - { - $this->file = $file; - $this->context = $context; + public function __construct( + private string $file = 'php://output', + private string $context = '' + ) { } - /** - * @return void - */ - public function onFlush(OnFlushEventArgs $args) + public function onFlush(OnFlushEventArgs $args): void { $this->dumpIdentityMap($args->getEntityManager()); } /** * Dumps the contents of the identity map into a stream. - * - * @return void */ - public function dumpIdentityMap(EntityManagerInterface $em) + public function dumpIdentityMap(EntityManagerInterface $em): void { $uow = $em->getUnitOfWork(); $identityMap = $uow->getIdentityMap(); @@ -119,10 +105,7 @@ public function dumpIdentityMap(EntityManagerInterface $em) fclose($fh); } - /** - * @param mixed $var - */ - private function getType($var): string + private function getType(mixed $var): string { if (is_object($var)) { $refl = new ReflectionObject($var); @@ -133,10 +116,7 @@ private function getType($var): string return gettype($var); } - /** - * @param object $entity - */ - private function getIdString($entity, UnitOfWork $uow): string + private function getIdString(object $entity, UnitOfWork $uow): string { if ($uow->isInIdentityMap($entity)) { $ids = $uow->getEntityIdentifier($entity); diff --git a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php index e7f2fb3e46..663c4b681d 100644 --- a/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php +++ b/lib/Doctrine/ORM/Tools/ResolveTargetEntityListener.php @@ -23,12 +23,12 @@ class ResolveTargetEntityListener implements EventSubscriber { /** @var mixed[][] indexed by original entity name */ - private $resolveTargetEntities = []; + private array $resolveTargetEntities = []; /** * {@inheritDoc} */ - public function getSubscribedEvents() + public function getSubscribedEvents(): array { return [ Events::loadClassMetadata, @@ -39,13 +39,9 @@ public function getSubscribedEvents() /** * Adds a target-entity class name to resolve to a new class name. * - * @param string $originalEntity - * @param string $newEntity * @psalm-param array $mapping - * - * @return void */ - public function addResolveTargetEntity($originalEntity, $newEntity, array $mapping) + public function addResolveTargetEntity(string $originalEntity, string $newEntity, array $mapping): void { $mapping['targetEntity'] = ltrim($newEntity, '\\'); $this->resolveTargetEntities[ltrim($originalEntity, '\\')] = $mapping; @@ -53,10 +49,8 @@ public function addResolveTargetEntity($originalEntity, $newEntity, array $mappi /** * @internal this is an event callback, and should not be called directly - * - * @return void */ - public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args) + public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args): void { if (array_key_exists($args->getClassName(), $this->resolveTargetEntities)) { $args->setFoundMetadata( @@ -71,10 +65,8 @@ public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args) * Processes event and resolves new target entity names. * * @internal this is an event callback, and should not be called directly - * - * @return void */ - public function loadClassMetadata(LoadClassMetadataEventArgs $args) + public function loadClassMetadata(LoadClassMetadataEventArgs $args): void { $cm = $args->getClassMetadata(); diff --git a/lib/Doctrine/ORM/Utility/IdentifierFlattener.php b/lib/Doctrine/ORM/Utility/IdentifierFlattener.php index 837f2dc1d5..f8291c9239 100644 --- a/lib/Doctrine/ORM/Utility/IdentifierFlattener.php +++ b/lib/Doctrine/ORM/Utility/IdentifierFlattener.php @@ -19,27 +19,19 @@ */ final class IdentifierFlattener { - /** - * The UnitOfWork used to coordinate object-level transactions. - * - * @var UnitOfWork - */ - private $unitOfWork; - - /** - * The metadata factory, used to retrieve the ORM metadata of entity classes. - * - * @var ClassMetadataFactory - */ - private $metadataFactory; - /** * Initializes a new IdentifierFlattener instance, bound to the given EntityManager. */ - public function __construct(UnitOfWork $unitOfWork, ClassMetadataFactory $metadataFactory) - { - $this->unitOfWork = $unitOfWork; - $this->metadataFactory = $metadataFactory; + public function __construct( + /** + * The UnitOfWork used to coordinate object-level transactions. + */ + private UnitOfWork $unitOfWork, + /** + * The metadata factory, used to retrieve the ORM metadata of entity classes. + */ + private ClassMetadataFactory $metadataFactory + ) { } /**