Skip to content

Commit 9b9b0ca

Browse files
wouterjnicolas-grekas
authored andcommitted
[Components] Convert to native return types
1 parent 951bf61 commit 9b9b0ca

6 files changed

+22
-79
lines changed

Debug/TraceableEventDispatcher.php

+7-26
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,17 @@ public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $sto
5151
$this->requestStack = $requestStack;
5252
}
5353

54-
/**
55-
* @return void
56-
*/
57-
public function addListener(string $eventName, callable|array $listener, int $priority = 0)
54+
public function addListener(string $eventName, callable|array $listener, int $priority = 0): void
5855
{
5956
$this->dispatcher->addListener($eventName, $listener, $priority);
6057
}
6158

62-
/**
63-
* @return void
64-
*/
65-
public function addSubscriber(EventSubscriberInterface $subscriber)
59+
public function addSubscriber(EventSubscriberInterface $subscriber): void
6660
{
6761
$this->dispatcher->addSubscriber($subscriber);
6862
}
6963

70-
/**
71-
* @return void
72-
*/
73-
public function removeListener(string $eventName, callable|array $listener)
64+
public function removeListener(string $eventName, callable|array $listener): void
7465
{
7566
if (isset($this->wrappedListeners[$eventName])) {
7667
foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
@@ -85,10 +76,7 @@ public function removeListener(string $eventName, callable|array $listener)
8576
$this->dispatcher->removeListener($eventName, $listener);
8677
}
8778

88-
/**
89-
* @return void
90-
*/
91-
public function removeSubscriber(EventSubscriberInterface $subscriber)
79+
public function removeSubscriber(EventSubscriberInterface $subscriber): void
9280
{
9381
$this->dispatcher->removeSubscriber($subscriber);
9482
}
@@ -226,10 +214,7 @@ public function getOrphanedEvents(Request $request = null): array
226214
return array_merge(...array_values($this->orphanedEvents));
227215
}
228216

229-
/**
230-
* @return void
231-
*/
232-
public function reset()
217+
public function reset(): void
233218
{
234219
$this->callStack = null;
235220
$this->orphanedEvents = [];
@@ -249,19 +234,15 @@ public function __call(string $method, array $arguments): mixed
249234

250235
/**
251236
* Called before dispatching the event.
252-
*
253-
* @return void
254237
*/
255-
protected function beforeDispatch(string $eventName, object $event)
238+
protected function beforeDispatch(string $eventName, object $event): void
256239
{
257240
}
258241

259242
/**
260243
* Called after dispatching the event.
261-
*
262-
* @return void
263244
*/
264-
protected function afterDispatch(string $eventName, object $event)
245+
protected function afterDispatch(string $eventName, object $event): void
265246
{
266247
}
267248

DependencyInjection/RegisterListenersPass.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ public function setNoPreloadEvents(array $noPreloadEvents): static
4848
return $this;
4949
}
5050

51-
/**
52-
* @return void
53-
*/
54-
public function process(ContainerBuilder $container)
51+
public function process(ContainerBuilder $container): void
5552
{
5653
if (!$container->hasDefinition('event_dispatcher') && !$container->hasAlias('event_dispatcher')) {
5754
return;

EventDispatcher.php

+5-19
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,13 @@ public function hasListeners(string $eventName = null): bool
123123
return false;
124124
}
125125

126-
/**
127-
* @return void
128-
*/
129-
public function addListener(string $eventName, callable|array $listener, int $priority = 0)
126+
public function addListener(string $eventName, callable|array $listener, int $priority = 0): void
130127
{
131128
$this->listeners[$eventName][$priority][] = $listener;
132129
unset($this->sorted[$eventName], $this->optimized[$eventName]);
133130
}
134131

135-
/**
136-
* @return void
137-
*/
138-
public function removeListener(string $eventName, callable|array $listener)
132+
public function removeListener(string $eventName, callable|array $listener): void
139133
{
140134
if (empty($this->listeners[$eventName])) {
141135
return;
@@ -163,10 +157,7 @@ public function removeListener(string $eventName, callable|array $listener)
163157
}
164158
}
165159

166-
/**
167-
* @return void
168-
*/
169-
public function addSubscriber(EventSubscriberInterface $subscriber)
160+
public function addSubscriber(EventSubscriberInterface $subscriber): void
170161
{
171162
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
172163
if (\is_string($params)) {
@@ -181,10 +172,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
181172
}
182173
}
183174

184-
/**
185-
* @return void
186-
*/
187-
public function removeSubscriber(EventSubscriberInterface $subscriber)
175+
public function removeSubscriber(EventSubscriberInterface $subscriber): void
188176
{
189177
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
190178
if (\is_array($params) && \is_array($params[0])) {
@@ -206,10 +194,8 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
206194
* @param callable[] $listeners The event listeners
207195
* @param string $eventName The name of the event to dispatch
208196
* @param object $event The event object to pass to the event handlers/listeners
209-
*
210-
* @return void
211197
*/
212-
protected function callListeners(iterable $listeners, string $eventName, object $event)
198+
protected function callListeners(iterable $listeners, string $eventName, object $event): void
213199
{
214200
$stoppable = $event instanceof StoppableEventInterface;
215201

EventDispatcherInterface.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,23 @@ interface EventDispatcherInterface extends ContractsEventDispatcherInterface
2727
*
2828
* @param int $priority The higher this value, the earlier an event
2929
* listener will be triggered in the chain (defaults to 0)
30-
*
31-
* @return void
3230
*/
33-
public function addListener(string $eventName, callable $listener, int $priority = 0);
31+
public function addListener(string $eventName, callable $listener, int $priority = 0): void;
3432

3533
/**
3634
* Adds an event subscriber.
3735
*
3836
* The subscriber is asked for all the events it is
3937
* interested in and added as a listener for these events.
40-
*
41-
* @return void
4238
*/
43-
public function addSubscriber(EventSubscriberInterface $subscriber);
39+
public function addSubscriber(EventSubscriberInterface $subscriber): void;
4440

4541
/**
4642
* Removes an event listener from the specified events.
47-
*
48-
* @return void
4943
*/
50-
public function removeListener(string $eventName, callable $listener);
44+
public function removeListener(string $eventName, callable $listener): void;
5145

52-
/**
53-
* @return void
54-
*/
55-
public function removeSubscriber(EventSubscriberInterface $subscriber);
46+
public function removeSubscriber(EventSubscriberInterface $subscriber): void;
5647

5748
/**
5849
* Gets the listeners of a specific event or all listeners sorted by descending priority.

EventSubscriberInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ interface EventSubscriberInterface
4545
*
4646
* @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
4747
*/
48-
public static function getSubscribedEvents();
48+
public static function getSubscribedEvents(): array;
4949
}

ImmutableEventDispatcher.php

+4-16
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,22 @@ public function dispatch(object $event, string $eventName = null): object
3030
return $this->dispatcher->dispatch($event, $eventName);
3131
}
3232

33-
/**
34-
* @return never
35-
*/
36-
public function addListener(string $eventName, callable|array $listener, int $priority = 0)
33+
public function addListener(string $eventName, callable|array $listener, int $priority = 0): never
3734
{
3835
throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
3936
}
4037

41-
/**
42-
* @return never
43-
*/
44-
public function addSubscriber(EventSubscriberInterface $subscriber)
38+
public function addSubscriber(EventSubscriberInterface $subscriber): never
4539
{
4640
throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
4741
}
4842

49-
/**
50-
* @return never
51-
*/
52-
public function removeListener(string $eventName, callable|array $listener)
43+
public function removeListener(string $eventName, callable|array $listener): never
5344
{
5445
throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
5546
}
5647

57-
/**
58-
* @return never
59-
*/
60-
public function removeSubscriber(EventSubscriberInterface $subscriber)
48+
public function removeSubscriber(EventSubscriberInterface $subscriber): never
6149
{
6250
throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
6351
}

0 commit comments

Comments
 (0)