From 3852fee95ec49812e0b3622825daa56a9e7cf7a3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 1 Jul 2021 09:59:11 +0200 Subject: [PATCH] [EventDispatcher] Add types to private properties Signed-off-by: Alexander M. Turek --- .../Debug/TraceableEventDispatcher.php | 14 ++++---- .../EventDispatcher/Debug/WrappedListener.php | 34 ++++++++----------- .../AddEventAliasesPass.php | 2 +- .../RegisterListenersPass.php | 8 ++--- .../EventDispatcher/EventDispatcher.php | 8 ++--- .../ImmutableEventDispatcher.php | 2 +- 6 files changed, 30 insertions(+), 38 deletions(-) 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) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy