8000 [EventDispatcher] Add return type declarations. · symfony/symfony@7eb9d14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7eb9d14

Browse files
committed
[EventDispatcher] Add return type declarations.
1 parent 760160f commit 7eb9d14

35 files changed

+86
-103
lines changed

src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
class MergeDoctrineCollectionListener implements EventSubscriberInterface
2929
{
30-
public static function getSubscribedEvents()
30+
public static function getSubscribedEvents(): array
3131
{
3232
// Higher priority than core MergeCollectionListener so that this one
3333
// is called before

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function onTerminate(ConsoleTerminateEvent $event)
133133
/**
134134
* {@inheritdoc}
135135
*/
136-
public static function getSubscribedEvents()
136+
public static function getSubscribedEvents(): array
137137
{
138138
return [
139139
ConsoleEvents::COMMAND => ['onCommand', 255],

src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function addCommandData(ConsoleEvent $event)
6060
}
6161
}
6262

63-
public static function getSubscribedEvents()
63+
public static function getSubscribedEvents(): array
6464
{
6565
return [
6666
ConsoleEvents::COMMAND => ['addCommandData', 1],

src/Symfony/Bundle/SecurityBundle/EventListener/FirewallListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function onKernelFinishRequest(FinishRequestEvent $event)
5959
/**
6060
* {@inheritdoc}
6161
*/
62-
public static function getSubscribedEvents()
62+
public static function getSubscribedEvents(): array
6363
{
6464
return [
6565
KernelEvents::REQUEST => [

src/Symfony/Component/Console/EventListener/ErrorListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event)
6969
$this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]);
7070
}
7171

72-
public static function getSubscribedEvents()
72+
public static function getSubscribedEvents(): array
7373
{
7474
return [
7575
ConsoleEvents::ERROR => ['onConsoleError', -128],

src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $sto
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function addListener(string $eventName, $listener, int $priority = 0)
56+
public function addListener(string $eventName, $listener, int $priority = 0): void
5757
{
5858
$this->dispatcher->addListener($eventName, $listener, $priority);
5959
}
6060

6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function addSubscriber(EventSubscriberInterface $subscriber)
64+
public function addSubscriber(EventSubscriberInterface $subscriber): void
6565
{
6666
$this->dispatcher->addSubscriber($subscriber);
6767
}
6868

6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function removeListener(string $eventName, $listener)
72+
public function removeListener(string $eventName, $listener): void
7373
{
7474
if (isset($this->wrappedListeners[$eventName])) {
7575
foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
@@ -81,29 +81,29 @@ public function removeListener(string $eventName, $listener)
8181
}
8282
}
8383

84-
return $this->dispatcher->removeListener($eventName, $listener);
84+
$this->dispatcher->removeListener($eventName, $listener);
8585
}
8686

8787
/**
8888
* {@inheritdoc}
8989
*/
90-
public function removeSubscriber(EventSubscriberInterface $subscriber)
90+
public function removeSubscriber(EventSubscriberInterface $subscriber): void
9191
{
92-
return $this->dispatcher->removeSubscriber($subscriber);
92+
$this->dispatcher->removeSubscriber($subscriber);
9393
}
9494

9595
/**
9696
* {@inheritdoc}
9797
*/
98-
public function getListeners(string $eventName = null)
98+
public function getListeners(string $eventName = null): array
9999
{
100100
return $this->dispatcher->getListeners($eventName);
101101
}
102102

103103
/**
104104
* {@inheritdoc}
105105
*/
106-
F438 public function getListenerPriority(string $eventName, $listener)
106+
public function getListenerPriority(string $eventName, $listener): ?int
107107
{
108108
// we might have wrapped listeners for the event (if called while dispatching)
109109
// in that case get the priority by wrapper
@@ -121,7 +121,7 @@ public function getListenerPriority(string $eventName, $listener)
121121
/**
122122
* {@inheritdoc}
123123
*/
124-
public function hasListeners(string $eventName = null)
124+
public function hasListeners(string $eventName = null): bool
125125
{
126126
return $this->dispatcher->hasListeners($eventName);
127127
}
@@ -170,10 +170,7 @@ public function dispatch($event, string $eventName = null): object
170170
return $event;
171171
}
172172

173-
/**
174-
* @return array
175-
*/
176-
public function getCalledListeners(Request $request = null)
173+
public function getCalledListeners(Request $request = null): array
177174
{
178175
if (null === $this->callStack) {
179176
return [];
@@ -191,10 +188,7 @@ public function getCalledListeners(Request $request = null)
191188
return $called;
192189
}
193190

194-
/**
195-
* @return array
196-
*/
197-
public function getNotCalledListeners(Request $request = null)
191+
public function getNotCalledListeners(Request $request = null): array
198192
{
199193
try {
200194
$allListeners = $this->getListeners();
@@ -250,7 +244,7 @@ public function getOrphanedEvents(Request $request = null): array
250244
return array_merge(...array_values($this->orphanedEvents));
251245
}
252246

253-
public function reset()
247+
public function reset(): void
254248
{
255249
$this->callStack = null;
256250
$this->orphanedEvents = [];
@@ -260,9 +254,6 @@ public function reset()
260254
/**
261255
* Proxies all method calls to the original event dispatcher.
262256
*
263-
* @param string $method The method name
264-
* @param array $arguments The method arguments
265-
*
266257
* @return mixed
267258
*/
268259
public function __call(string $method, array $arguments)
@@ -273,14 +264,14 @@ public function __call(string $method, array $arguments)
273264
/**
274265
* Called before dispatching the event.
275266
*/
276-
protected function beforeDispatch(string $eventName, object $event)
267+
protected function beforeDispatch(string $eventName, object $event): void
277268
{
278269
}
279270

280271
/**
281272
* Called after dispatching the event.
282273
*/
283-
protected function afterDispatch(string $eventName, object $event)
274+
protected function afterDispatch(string $eventName, object $event): void
284275
{
285276
}
286277

@@ -341,7 +332,7 @@ private function postProcess(string $eventName): void
341332
}
342333
}
343334

344-
private function sortNotCalledListeners(array $a, array $b)
335+
private function sortNotCalledListeners(array $a, array $b): int
345336
{
346337
if (0 !== $cmp = strcmp($a['event'], $b['event'])) {
347338
return $cmp;

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function setHotPathEvents(array $hotPathEvents, $tagName = 'container.hot
4848
return $this;
4949
}
5050

51-
public function process(ContainerBuilder $container)
51+
public function process(ContainerBuilder $container): void
5252
{
5353
if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
5454
return;
@@ -134,7 +134,7 @@ class ExtractingEventDispatcher extends EventDispatcher implements EventSubscrib
134134
public static $aliases = [];
135135
public static $subscriber;
136136

137-
public function addListener(string $eventName, $listener, int $priority = 0)
137+
public function addListener(string $eventName, $listener, int $priority = 0): void
138138
{
139139
$this->listeners[] = [$eventName, $listener[1], $priority];
140140
}

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function dispatch($event, string $eventName = null): object
7070
/**
7171
* {@inheritdoc}
7272
*/
73-
public function getListeners(string $eventName = null)
73+
public function getListeners(string $eventName = null): array
7474
{
7575
if (null !== $eventName) {
7676
if (empty($this->listeners[$eventName])) {
@@ -96,7 +96,7 @@ public function getListeners(string $eventName = null)
9696
/**
9797
* {@inheritdoc}
9898
*/
99-
public function getListenerPriority(string $eventName, $listener)
99+
public function getListenerPriority(string $eventName, $listener): ?int
100100
{
101101
if (empty($this->listeners[$eventName])) {
102102
return null;
@@ -123,7 +123,7 @@ public function getListenerPriority(string $eventName, $listener)
123123
/**
124124
* {@inheritdoc}
125125
*/
126-
public function hasListeners(string $eventName = null)
126+
public function hasListeners(string $eventName = null): bool
127127
{
128128
if (null !== $eventName) {
129129
return !empty($this->listeners[$eventName]);
@@ -141,7 +141,7 @@ public function hasListeners(string $eventName = null)
141141
/**
142142
* {@inheritdoc}
143143
*/
144-
public function addListener(string $eventName, $listener, int $priority = 0)
144+
public function addListener(string $eventName, $listener, int $priority = 0): void
145145
{
146146
$this->listeners[$eventName][$priority][] = $listener;
147147
unset($this->sorted[$eventName], $this->optimized[$eventName]);
@@ -150,7 +150,7 @@ public function addListener(string $eventName, $listener, int $priority = 0)
150150
/**
151151
* {@inheritdoc}
152152
*/
153-
public function removeListener(string $eventName, $listener)
153+
public function removeListener(string $eventName, $listener): void
154154
{
155155
if (empty($this->listeners[$eventName])) {
156156
return;
@@ -179,7 +179,7 @@ public function removeListener(string $eventName, $listener)
179179
/**
180180
* {@inheritdoc}
181181
*/
182-
public function addSubscriber(EventSubscriberInterface $subscriber)
182+
public function addSubscriber(EventSubscriberInterface $subscriber): void
183183
{
184184
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
185185
if (\is_string($params)) {
@@ -197,7 +197,7 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
197197
/**
198198
* {@inheritdoc}
199199
*/
200-
public function removeSubscriber(EventSubscriberInterface $subscriber)
200+
public function removeSubscriber(EventSubscriberInterface $subscriber): void
201201
{
202202
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
203203
if (\is_array($params) && \is_array($params[0])) {
@@ -220,7 +220,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
220220
* @param string $eventName The name of the event to dispatch
221221
* @param object $event The event object to pass to the event handlers/listeners
222222
*/
223-
protected function callListeners(iterable $listeners, string $eventName, object $event)
223+
protected function callListeners(iterable $listeners, string $eventName, object $event): void
224224
{
225225
$stoppable = $event instanceof Event || $event instanceof StoppableEventInterface;
226226

@@ -235,7 +235,7 @@ protected function callListeners(iterable $listeners, string $eventName, object
235235
/**
236236
* Sorts the internal list of listeners for the given event by priority.
237237
*/
238-
private function sortListeners(string $eventName)
238+
private function sortListeners(string $eventName): void
239239
{
240240
krsort($this->listeners[$eventName]);
241241
$this->sorted[$eventName] = [];

src/Symfony/Component/EventDispatcher/EventDispatcherInterface.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,43 @@ public function dispatch($event, string $eventName = null): object;
3434
* @param int $priority The higher this value, the earlier an event
3535
* listener will be triggered in the chain (defaults to 0)
3636
*/
37-
public function addListener(string $eventName, $listener, int $priority = 0);
37+
public function addListener(string $eventName, $listener, int $priority = 0): void;
3838

3939
/**
4040
* Adds an event subscriber.
4141
*
4242
* The subscriber is asked for all the events it is
4343
* interested in and added as a listener for these events.
4444
*/
45-
public function addSubscriber(EventSubscriberInterface $subscriber);
45+
public function addSubscriber(EventSubscriberInterface $subscriber): void;
4646

4747
/**
4848
* Removes an event listener from the specified 341A events.
4949
*
5050
* @param callable $listener The listener to remove
5151
*/
52-
public function removeListener(string $eventName, $listener);
52+
public function removeListener(string $eventName, $listener): void;
5353

54-
public function removeSubscriber(EventSubscriberInterface $subscriber);
54+
public function removeSubscriber(EventSubscriberInterface $subscriber): void;
5555

5656
/**
5757
* Gets the listeners of a specific event or all listeners sorted by descending priority.
58-
*
59-
* @return array The event listeners for the specified event, or all event listeners by event name
6058
*/
61-
public function getListeners(string $eventName = null);
59+
public function getListeners(string $eventName = null): array;
6260

6361
/**
6462
* Gets the listener priority for a specific event.
6563
*
6664
* Returns null if the event or the listener does not exist.
6765
*
6866
* @param callable $listener The listener
69-
*
70-
* @return int|null The event listener priority
7167
*/
72-
public function getListenerPriority(string $eventName, $listener);
68+
public function getListenerPriority(string $eventName, $listener): ?int;
7369

7470
/**
7571
* Checks whether an event has any registered listeners.
7672
*
7773
* @return bool true if the specified event has any listeners, false otherwise
7874
*/
79-
public function hasListeners(string $eventName = null);
75+
public function hasListeners(string $eventName = null): bool;
8076
}

src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ interface EventSubscriberInterface
3939
* * ['eventName' => 'methodName']
4040
* * ['eventName' => ['methodName', $priority]]
4141
* * ['eventName' => [['methodName1', $priority], ['methodName2']]]
42-
*
43-
* @return array The event names to listen to
4442
*/
45-
public static function getSubscribedEvents();
43+
public static function getSubscribedEvents(): array;
4644
}

0 commit comments

Comments
 (0)
0