diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index ea946419ca15d..edea60f866f98 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -32,20 +32,18 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa protected $logger; protected $stopwatch; - private $callStack; - private $dispatcher; - private $wrappedListeners; - private $orphanedEvents; - private $requestStack; - private $currentRequestHash = ''; + private ?\SplObjectStorage $callStack = null; + private EventDispatcherInterface $dispatcher; + private array $wrappedListeners = []; + private array $orphanedEvents = []; + private ?RequestStack $requestStack; + private string $currentRequestHash = ''; public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null) { $this->dispatcher = $dispatcher; $this->stopwatch = $stopwatch; $this->logger = $logger; - $this->wrappedListeners = []; - $this->orphanedEvents = []; $this->requestStack = $requestStack; } diff --git a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php index 7a2cd6920e797..7df21922aa38e 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php +++ b/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php @@ -21,17 +21,17 @@ */ final class WrappedListener { - private $listener; - private $optimizedListener; - private $name; - private $called; - private $stoppedPropagation; - private $stopwatch; - private $dispatcher; - private $pretty; - private $stub; - private $priority; - private static $hasClassStub; + private string|array|object $listener; + private ?\Closure $optimizedListener; + private string $name; + private bool $called = false; + private bool $stoppedPropagation = false; + private Stopwatch $stopwatch; + private ?EventDispatcherInterface $dispatcher; + private string $pretty; + private ClassStub|string $stub; + private ?int $priority = null; + private static bool $hasClassStub; public function __construct(callable|array $listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null) { @@ -39,8 +39,6 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $ $this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null); $this->stopwatch = $stopwatch; $this->dispatcher = $dispatcher; - $this->called = false; - $this->stoppedPropagation = false; if (\is_array($listener)) { $this->name = \is_object($listener[0]) ? get_debug_type($listener[0]) : $listener[0]; @@ -66,12 +64,10 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $ $this->name = $name; } - if (null === self::$hasClassStub) { - self::$hasClassStub = class_exists(ClassStub::class); - } + self::$hasClassStub ??= class_exists(ClassStub::class); } - public function getWrappedListener() + public function getWrappedListener(): callable|array { return $this->listener; } @@ -93,9 +89,7 @@ public function getPretty(): string public function getInfo(string $eventName): array { - if (null === $this->stub) { - $this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()'; - } + $this->stub ??= self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()'; return [ 'event' => $eventName, diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php index b77811b38b17c..13b4336aa4eeb 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/AddEventAliasesPass.php @@ -21,7 +21,7 @@ */ class AddEventAliasesPass implements CompilerPassInterface { - private $eventAliases; + private array $eventAliases; public function __construct(array $eventAliases) { diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 352737572d1dc..cc481321c9abc 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -25,10 +25,10 @@ */ class RegisterListenersPass implements CompilerPassInterface { - private $hotPathEvents = []; - private $hotPathTagName = 'container.hot_path'; - private $noPreloadEvents = []; - private $noPreloadTagName = 'container.no_preload'; + private array $hotPathEvents = []; + private string $hotPathTagName = 'container.hot_path'; + private array $noPreloadEvents = []; + private string $noPreloadTagName = 'container.no_preload'; /** * @return $this diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 638c3f4830afe..021d668eaa004 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -31,9 +31,9 @@ */ class EventDispatcher implements EventDispatcherInterface { - private $listeners = []; - private $sorted = []; - private $optimized; + private array $listeners = []; + private array $sorted = []; + private array $optimized; public function __construct() { @@ -49,7 +49,7 @@ public function dispatch(object $event, string $eventName = null): object { $eventName = $eventName ?? \get_class($event); - if (null !== $this->optimized) { + if (isset($this->optimized)) { $listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName)); } else { $listeners = $this->getListeners($eventName); diff --git a/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php index fd04ff76f90fa..6bc8bfffaeb96 100644 --- a/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php @@ -18,7 +18,7 @@ */ class ImmutableEventDispatcher implements EventDispatcherInterface { - private $dispatcher; + private EventDispatcherInterface $dispatcher; public function __construct(EventDispatcherInterface $dispatcher) {