diff --git a/Debug/TraceableEventDispatcher.php b/Debug/TraceableEventDispatcher.php index f1b9823..1b9ae64 100644 --- a/Debug/TraceableEventDispatcher.php +++ b/Debug/TraceableEventDispatcher.php @@ -43,7 +43,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa private ?RequestStack $requestStack; private string $currentRequestHash = ''; - public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null) + public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, ?LoggerInterface $logger = null, ?RequestStack $requestStack = null) { $this->dispatcher = $dispatcher; $this->stopwatch = $stopwatch; @@ -93,7 +93,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber) $this->dispatcher->removeSubscriber($subscriber); } - public function getListeners(string $eventName = null): array + public function getListeners(?string $eventName = null): array { return $this->dispatcher->getListeners($eventName); } @@ -113,12 +113,12 @@ public function getListenerPriority(string $eventName, callable|array $listener) return $this->dispatcher->getListenerPriority($eventName, $listener); } - public function hasListeners(string $eventName = null): bool + public function hasListeners(?string $eventName = null): bool { return $this->dispatcher->hasListeners($eventName); } - public function dispatch(object $event, string $eventName = null): object + public function dispatch(object $event, ?string $eventName = null): object { $eventName ??= $event::class; @@ -153,7 +153,7 @@ public function dispatch(object $event, string $eventName = null): object return $event; } - public function getCalledListeners(Request $request = null): array + public function getCalledListeners(?Request $request = null): array { if (null === $this->callStack) { return []; @@ -171,7 +171,7 @@ public function getCalledListeners(Request $request = null): array return $called; } - public function getNotCalledListeners(Request $request = null): array + public function getNotCalledListeners(?Request $request = null): array { try { $allListeners = $this->dispatcher instanceof EventDispatcher ? $this->getListenersWithPriority() : $this->getListenersWithoutPriority(); @@ -213,7 +213,7 @@ public function getNotCalledListeners(Request $request = null): array return $notCalled; } - public function getOrphanedEvents(Request $request = null): array + public function getOrphanedEvents(?Request $request = null): array { if ($request) { return $this->orphanedEvents[spl_object_hash($request)] ?? []; diff --git a/Debug/WrappedListener.php b/Debug/WrappedListener.php index 6e0de1d..4dba883 100644 --- a/Debug/WrappedListener.php +++ b/Debug/WrappedListener.php @@ -34,7 +34,7 @@ final class WrappedListener private ?int $priority = null; private static bool $hasClassStub; - public function __construct(callable|array $listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null, int $priority = null) + public function __construct(callable|array $listener, ?string $name, Stopwatch $stopwatch, ?EventDispatcherInterface $dispatcher = null, ?int $priority = null) { $this->listener = $listener; $this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? $listener(...) : null); diff --git a/EventDispatcher.php b/EventDispatcher.php index 327803a..6052989 100644 --- a/EventDispatcher.php +++ b/EventDispatcher.php @@ -42,7 +42,7 @@ public function __construct() } } - public function dispatch(object $event, string $eventName = null): object + public function dispatch(object $event, ?string $eventName = null): object { $eventName ??= $event::class; @@ -59,7 +59,7 @@ public function dispatch(object $event, string $eventName = null): object return $event; } - public function getListeners(string $eventName = null): array + public function getListeners(?string $eventName = null): array { if (null !== $eventName) { if (empty($this->listeners[$eventName])) { @@ -108,7 +108,7 @@ public function getListenerPriority(string $eventName, callable|array $listener) return null; } - public function hasListeners(string $eventName = null): bool + public function hasListeners(?string $eventName = null): bool { if (null !== $eventName) { return !empty($this->listeners[$eventName]); diff --git a/EventDispatcherInterface.php b/EventDispatcherInterface.php index 3cd94c9..e95a7b1 100644 --- a/EventDispatcherInterface.php +++ b/EventDispatcherInterface.php @@ -59,7 +59,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber); * * @return array */ - public function getListeners(string $eventName = null): array; + public function getListeners(?string $eventName = null): array; /** * Gets the listener priority for a specific event. @@ -71,5 +71,5 @@ public function getListenerPriority(string $eventName, callable $listener): ?int /** * Checks whether an event has any registered listeners. */ - public function hasListeners(string $eventName = null): bool; + public function hasListeners(?string $eventName = null): bool; } diff --git a/ImmutableEventDispatcher.php b/ImmutableEventDispatcher.php index d385d3f..301a805 100644 --- a/ImmutableEventDispatcher.php +++ b/ImmutableEventDispatcher.php @@ -25,7 +25,7 @@ public function __construct(EventDispatcherInterface $dispatcher) $this->dispatcher = $dispatcher; } - public function dispatch(object $event, string $eventName = null): object + public function dispatch(object $event, ?string $eventName = null): object { return $this->dispatcher->dispatch($event, $eventName); } @@ -62,7 +62,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber) throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.'); } - public function getListeners(string $eventName = null): array + public function getListeners(?string $eventName = null): array { return $this->dispatcher->getListeners($eventName); } @@ -72,7 +72,7 @@ public function getListenerPriority(string $eventName, callable|array $listener) return $this->dispatcher->getListenerPriority($eventName, $listener); } - public function hasListeners(string $eventName = null): bool + public function hasListeners(?string $eventName = null): bool { return $this->dispatcher->hasListeners($eventName); }