Skip to content

Commit 49cb0bb

Browse files
Add return types - batch 5/n
1 parent 29a4bd8 commit 49cb0bb

6 files changed

+23
-35
lines changed

Debug/TraceableEventDispatcher.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
9292
/**
9393
* {@inheritdoc}
9494
*/
95-
public function getListeners(string $eventName = null)
95+
public function getListeners(string $eventName = null): array
9696
{
9797
return $this->dispatcher->getListeners($eventName);
9898
}
9999

100100
/**
101101
* {@inheritdoc}
102102
*/
103-
public function getListenerPriority(string $eventName, callable|array $listener)
103+
public function getListenerPriority(string $eventName, callable|array $listener): ?int
104104
{
105105
// we might have wrapped listeners for the event (if called while dispatching)
106106
// in that case get the priority by wrapper
@@ -118,7 +118,7 @@ public function getListenerPriority(string $eventName, callable|array $listener)
118118
/**
119119
* {@inheritdoc}
120120
*/
121-
public function hasListeners(string $eventName = null)
121+
public function hasListeners(string $eventName = null): bool
122122
{
123123
return $this->dispatcher->hasListeners($eventName);
124124
}
@@ -163,10 +163,7 @@ public function dispatch(object $event, string $eventName = null): object
163163
return $event;
164164
}
165165

166-
/**
167-
* @return array
168-
*/
169-
public function getCalledListeners(Request $request = null)
166+
public function getCalledListeners(Request $request = null): array
170167
{
171168
if (null === $this->callStack) {
172169
return [];
@@ -184,10 +181,7 @@ public function getCalledListeners(Request $request = null)
184181
return $called;
185182
}
186183

187-
/**
188-
* @return array
189-
*/
190-
public function getNotCalledListeners(Request $request = null)
184+
public function getNotCalledListeners(Request $request = null): array
191185
{
192186
try {
193187
$allListeners = $this->getListeners();
@@ -255,10 +249,8 @@ public function reset()
255249
*
256250
* @param string $method The method name
257251
* @param array $arguments The method arguments
258-
*
259-
* @return mixed
260252
*/
261-
public function __call(string $method, array $arguments)
253+
public function __call(string $method, array $arguments): mixed
262254
{
263255
return $this->dispatcher->{$method}(...$arguments);
264256
}

DependencyInjection/RegisterListenersPass.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RegisterListenersPass implements CompilerPassInterface
3131
/**
3232
* @return $this
3333
*/
34-
public function setHotPathEvents(array $hotPathEvents)
34+
public function setHotPathEvents(array $hotPathEvents): static
3535
{
3636
$this->hotPathEvents = array_flip($hotPathEvents);
3737

@@ -41,7 +41,7 @@ public function setHotPathEvents(array $hotPathEvents)
4141
/**
4242
* @return $this
4343
*/
44-
public function setNoPreloadEvents(array $noPreloadEvents): self
44+
public function setNoPreloadEvents(array $noPreloadEvents): static
4545
{
4646
$this->noPreloadEvents = array_flip($noPreloadEvents);
4747

EventDispatcher.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function dispatch(object $event, string $eventName = null): object
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function getListeners(string $eventName = null)
68+
public function getListeners(string $eventName = null): array
6969
{
7070
if (null !== $eventName) {
7171
if (empty($this->listeners[$eventName])) {
@@ -91,7 +91,7 @@ public function getListeners(string $eventName = null)
9191
/**
9292
* {@inheritdoc}
9393
*/
94-
public function getListenerPriority(string $eventName, callable|array $listener)
94+
public function getListenerPriority(string $eventName, callable|array $listener): ?int
9595
{
9696
if (empty($this->listeners[$eventName])) {
9797
return null;
@@ -120,7 +120,7 @@ public function getListenerPriority(string $eventName, callable|array $listener)
120120
/**
121121
* {@inheritdoc}
122122
*/
123-
public function hasListeners(string $eventName = null)
123+
public function hasListeners(string $eventName = null): bool
124124
{
125125
if (null !== $eventName) {
126126
return !empty($this->listeners[$eventName]);

EventDispatcherInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber);
5050
*
5151
* @return array The event listeners for the specified event, or all event listeners by event name
5252
*/
53-
public function getListeners(string $eventName = null);
53+
public function getListeners(string $eventName = null): array;
5454

5555
/**
5656
* Gets the listener priority for a specific event.
@@ -59,12 +59,12 @@ public function getListeners(string $eventName = null);
5959
*
6060
* @return int|null The event listener priority
6161
*/
62-
public function getListenerPriority(string $eventName, callable $listener);
62+
public function getListenerPriority(string $eventName, callable $listener): ?int;
6363

6464
/**
6565
* Checks whether an event has any registered listeners.
6666
*
6767
* @return bool true if the specified event has any listeners, false otherwise
6868
*/
69-
public function hasListeners(string $eventName = null);
69+
public function hasListeners(string $eventName = null): bool;
7070
}

GenericEvent.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(mixed $subject = null, array $arguments = [])
4242
*
4343
* @return mixed The observer subject
4444
*/
45-
public function getSubject()
45+
public function getSubject(): mixed
4646
{
4747
return $this->subject;
4848
}
@@ -54,7 +54,7 @@ public function getSubject()
5454
*
5555
* @throws \InvalidArgumentException if key is not found
5656
*/
57-
public function getArgument(string $key)
57+
public function getArgument(string $key): mixed
5858
{
5959
if ($this->hasArgument($key)) {
6060
return $this->arguments[$key];
@@ -68,7 +68,7 @@ public function getArgument(string $key)
6868
*
6969
* @return $this
7070
*/
71-
public function setArgument(string $key, mixed $value)
71+
public function setArgument(string $key, mixed $value): static
7272
{
7373
$this->arguments[$key] = $value;
7474

@@ -77,10 +77,8 @@ public function setArgument(string $key, mixed $value)
7777

7878
/**
7979
* Getter for all arguments.
80-
*
81-
* @return array
8280
*/
83-
public function getArguments()
81+
public function getArguments(): array
8482
{
8583
return $this->arguments;
8684
}
@@ -90,7 +88,7 @@ public function getArguments()
9088
*
9189
* @return $this
9290
*/
93-
public function setArguments(array $args = [])
91+
public function setArguments(array $args = []): static
9492
{
9593
$this->arguments = $args;
9694

@@ -99,10 +97,8 @@ public function setArguments(array $args = [])
9997

10098
/**
10199
* Has argument.
102-
*
103-
* @return bool
104100
*/
105-
public function hasArgument(string $key)
101+
public function hasArgument(string $key): bool
106102
{
107103
return \array_key_exists($key, $this->arguments);
108104
}

ImmutableEventDispatcher.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,23 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
6868
/**
6969
* {@inheritdoc}
7070
*/
71-
public function getListeners(string $eventName = null)
71+
public function getListeners(string $eventName = null): array
7272
{
7373
return $this->dispatcher->getListeners($eventName);
7474
}
7575

7676
/**
7777
* {@inheritdoc}
7878
*/
79-
public function getListenerPriority(string $eventName, callable|array $listener)
79+
public function getListenerPriority(string $eventName, callable|array $listener): ?int
8080
{
8181
return $this->dispatcher->getListenerPriority($eventName, $listener);
8282
}
8383

8484
/**
8585
* {@inheritdoc}
8686
*/
87-
public function hasListeners(string $eventName = null)
87+
public function hasListeners(string $eventName = null): bool
8888
{
8989
return $this->dispatcher->hasListeners($eventName);
9090
}

0 commit comments

Comments
 (0)