diff --git a/src/Tools/AttachEntityListenersListener.php b/src/Tools/AttachEntityListenersListener.php index 63e8f7b5a13..9203cfe782c 100644 --- a/src/Tools/AttachEntityListenersListener.php +++ b/src/Tools/AttachEntityListenersListener.php @@ -5,8 +5,10 @@ namespace Doctrine\ORM\Tools; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; +use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\Builder\EntityListenerBuilder; +use function assert; use function ltrim; /** @@ -14,16 +16,22 @@ */ class AttachEntityListenersListener { - /** @var mixed[][] */ + /** + * @var array> + */ private array $entityListeners = []; /** * Adds an entity listener for a specific entity. * - * @param string $entityClass The entity to attach the listener. - * @param string $listenerClass The listener class. - * @param string|null $eventName The entity lifecycle event. - * @param string|null $listenerCallback The listener callback method or NULL to use $eventName. + * @param class-string $entityClass The entity to attach the listener. + * @param class-string $listenerClass The listener class. + * @param Events::*|null $eventName The entity lifecycle event. + * @param non-falsy-string|null $listenerCallback The listener callback method or NULL to use $eventName. */ public function addEntityListener( string $entityClass, @@ -34,7 +42,7 @@ public function addEntityListener( $this->entityListeners[ltrim($entityClass, '\\')][] = [ 'event' => $eventName, 'class' => $listenerClass, - 'method' => $listenerCallback ?: $eventName, + 'method' => $listenerCallback ?? $eventName, ]; } @@ -53,6 +61,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void if ($listener['event'] === null) { EntityListenerBuilder::bindEntityListener($metadata, $listener['class']); } else { + assert($listener['method'] !== null); $metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']); } }