Skip to content

Commit 98f4d5b

Browse files
committed
switched array() to []
1 parent d1cdd46 commit 98f4d5b

12 files changed

+163
-163
lines changed

ContainerAwareEventDispatcher.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class ContainerAwareEventDispatcher extends EventDispatcher
3030
/**
3131
* The service IDs of the event listeners and subscribers.
3232
*/
33-
private $listenerIds = array();
33+
private $listenerIds = [];
3434

3535
/**
3636
* The services registered as listeners.
3737
*/
38-
private $listeners = array();
38+
private $listeners = [];
3939

4040
public function __construct(ContainerInterface $container)
4141
{
@@ -70,7 +70,7 @@ public function addListenerService($eventName, $callback, $priority = 0)
7070
throw new \InvalidArgumentException('Expected an array("service", "method") argument');
7171
}
7272

73-
$this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
73+
$this->listenerIds[$eventName][] = [$callback[0], $callback[1], $priority];
7474
}
7575

7676
public function removeListener($eventName, $listener)
@@ -80,7 +80,7 @@ public function removeListener($eventName, $listener)
8080
if (isset($this->listenerIds[$eventName])) {
8181
foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) {
8282
$key = $serviceId.'.'.$method;
83-
if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
83+
if (isset($this->listeners[$eventName][$key]) && $listener === [$this->listeners[$eventName][$key], $method]) {
8484
unset($this->listeners[$eventName][$key]);
8585
if (empty($this->listeners[$eventName])) {
8686
unset($this->listeners[$eventName]);
@@ -150,12 +150,12 @@ public function addSubscriberService($serviceId, $class)
150150

151151
foreach ($class::getSubscribedEvents() as $eventName => $params) {
152152
if (\is_string($params)) {
153-
$this->listenerIds[$eventName][] = array($serviceId, $params, 0);
153+
$this->listenerIds[$eventName][] = [$serviceId, $params, 0];
154154
} elseif (\is_string($params[0])) {
155-
$this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
155+
$this->listenerIds[$eventName][] = [$serviceId, $params[0], isset($params[1]) ? $params[1] : 0];
156156
} else {
157157
foreach ($params as $listener) {
158-
$this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
158+
$this->listenerIds[$eventName][] = [$serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0];
159159
}
160160
}
161161
}
@@ -184,10 +184,10 @@ protected function lazyLoad($eventName)
184184

185185
$key = $serviceId.'.'.$method;
186186
if (!isset($this->listeners[$eventName][$key])) {
187-
$this->addListener($eventName, array($listener, $method), $priority);
187+
$this->addListener($eventName, [$listener, $method], $priority);
188188
} elseif ($this->listeners[$eventName][$key] !== $listener) {
189-
parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
190-
$this->addListener($eventName, array($listener, $method), $priority);
189+
parent::removeListener($eventName, [$this->listeners[$eventName][$key], $method]);
190+
$this->addListener($eventName, [$listener, $method], $priority);
191191
}
192192

193193
$this->listeners[$eventName][$key] = $listener;

Debug/TraceableEventDispatcher.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $sto
3838
$this->dispatcher = $dispatcher;
3939
$this->stopwatch = $stopwatch;
4040
$this->logger = $logger;
41-
$this->wrappedListeners = array();
41+
$this->wrappedListeners = [];
4242
}
4343

4444
/**
@@ -162,10 +162,10 @@ public function dispatch($eventName, Event $event = null)
162162
public function getCalledListeners()
163163
{
164164
if (null === $this->callStack) {
165-
return array();
165+
return [];
166166
}
167167

168-
$called = array();
168+
$called = [];
169169
foreach ($this->callStack as $listener) {
170170
list($eventName) = $this->callStack->getInfo();
171171

@@ -184,14 +184,14 @@ public function getNotCalledListeners()
184184
$allListeners = $this->getListeners();
185185
} catch (\Exception $e) {
186186
if (null !== $this->logger) {
187-
$this->logger->info('An exception was thrown while getting the uncalled listeners.', array('exception' => $e));
187+
$this->logger->info('An exception was thrown while getting the uncalled listeners.', ['exception' => $e]);
188188
}
189189

190190
// unable to retrieve the uncalled listeners
191-
return array();
191+
return [];
192192
}
193193

194-
$notCalled = array();
194+
$notCalled = [];
195195
foreach ($allListeners as $eventName => $listeners) {
196196
foreach ($listeners as $listener) {
197197
$called = false;
@@ -214,7 +214,7 @@ public function getNotCalledListeners()
214214
}
215215
}
216216

217-
uasort($notCalled, array($this, 'sortNotCalledListeners'));
217+
uasort($notCalled, [$this, 'sortNotCalledListeners']);
218218

219219
return $notCalled;
220220
}
@@ -234,7 +234,7 @@ public function reset()
234234
*/
235235
public function __call($method, $arguments)
236236
{
237-
return \call_user_func_array(array($this->dispatcher, $method), $arguments);
237+
return \call_user_func_array([$this->dispatcher, $method], $arguments);
238238
}
239239

240240
/**
@@ -265,7 +265,7 @@ private function preProcess($eventName)
265265
$this->wrappedListeners[$eventName][] = $wrappedListener;
266266
$this->dispatcher->removeListener($eventName, $listener);
267267
$this->dispatcher->addListener($eventName, $wrappedListener, $priority);
268-
$this->callStack->attach($wrappedListener, array($eventName));
268+
$this->callStack->attach($wrappedListener, [$eventName]);
269269
}
270270
}
271271

@@ -283,7 +283,7 @@ private function postProcess($eventName)
283283
$this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority);
284284

285285
if (null !== $this->logger) {
286-
$context = array('event' => $eventName, 'listener' => $listener->getPretty());
286+
$context = ['event' => $eventName, 'listener' => $listener->getPretty()];
287287
}
288288

289289
if ($listener->wasCalled()) {

Debug/WrappedListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public function getInfo($eventName)
9494
$this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
9595
}
9696

97-
return array(
97+
return [
9898
'event' => $eventName,
9999
'priority' => null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null,
100100
'pretty' => $this->pretty,
101101
'stub' => $this->stub,
102-
);
102+
];
103103
}
104104

105105
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)

DependencyInjection/RegisterListenersPass.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RegisterListenersPass implements CompilerPassInterface
2828
protected $listenerTag;
2929
protected $subscriberTag;
3030

31-
private $hotPathEvents = array();
31+
private $hotPathEvents = [];
3232
private $hotPathTagName;
3333

3434
/**
@@ -68,14 +68,14 @@ public function process(ContainerBuilder $container)
6868
}
6969

7070
if (!isset($event['method'])) {
71-
$event['method'] = 'on'.preg_replace_callback(array(
71+
$event['method'] = 'on'.preg_replace_callback([
7272
'/(?<=\b)[a-z]/i',
7373
'/[^a-z0-9]/i',
74-
), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
74+
], function ($matches) { return strtoupper($matches[0]); }, $event['event']);
7575
$event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
7676
}
7777

78-
$definition->addMethodCall('addListener', array($event['event'], array(new ServiceClosureArgument(new Reference($id)), $event['method']), $priority));
78+
$definition->addMethodCall('addListener', [$event['event'], [new ServiceClosureArgument(new Reference($id)), $event['method']], $priority]);
7979

8080
if (isset($this->hotPathEvents[$event['event']])) {
8181
$container->getDefinition($id)->addTag($this->hotPathTagName);
@@ -102,14 +102,14 @@ public function process(ContainerBuilder $container)
102102
ExtractingEventDispatcher::$subscriber = $class;
103103
$extractingDispatcher->addSubscriber($extractingDispatcher);
104104
foreach ($extractingDispatcher->listeners as $args) {
105-
$args[1] = array(new ServiceClosureArgument(new Reference($id)), $args[1]);
105+
$args[1] = [new ServiceClosureArgument(new Reference($id)), $args[1]];
106106
$definition->addMethodCall('addListener', $args);
107107

108108
if (isset($this->hotPathEvents[$args[0]])) {
109109
$container->getDefinition($id)->addTag('container.hot_path');
110110
}
111111
}
112-
$extractingDispatcher->listeners = array();
112+
$extractingDispatcher->listeners = [];
113113
}
114114
}
115115
}
@@ -119,18 +119,18 @@ public function process(ContainerBuilder $container)
119119
*/
120120
class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
121121
{
122-
public $listeners = array();
122+
public $listeners = [];
123123

124124
public static $subscriber;
125125

126126
public function addListener($eventName, $listener, $priority = 0)
127127
{
128-
$this->listeners[] = array($eventName, $listener[1], $priority);
128+
$this->listeners[] = [$eventName, $listener[1], $priority];
129129
}
130130

131131
public static function getSubscribedEvents()
132132
{
133-
$callback = array(self::$subscriber, 'getSubscribedEvents');
133+
$callback = [self::$subscriber, 'getSubscribedEvents'];
134134

135135
return $callback();
136136
}

EventDispatcher.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
*/
2929
class EventDispatcher implements EventDispatcherInterface
3030
{
31-
private $listeners = array();
32-
private $sorted = array();
31+
private $listeners = [];
32+
private $sorted = [];
3333

3434
/**
3535
* {@inheritdoc}
@@ -54,7 +54,7 @@ public function getListeners($eventName = null)
5454
{
5555
if (null !== $eventName) {
5656
if (empty($this->listeners[$eventName])) {
57-
return array();
57+
return [];
5858
}
5959

6060
if (!isset($this->sorted[$eventName])) {
@@ -166,12 +166,12 @@ public function addSubscriber(EventSubscriberInterface $subscriber)
166166
{
167167
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
168168
if (\is_string($params)) {
169-
$this->addListener($eventName, array($subscriber, $params));
169+
$this->addListener($eventName, [$subscriber, $params]);
170170
} elseif (\is_string($params[0])) {
171-
$this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
171+
$this->addListener($eventName, [$subscriber, $params[0]], isset($params[1]) ? $params[1] : 0);
172172
} else {
173173
foreach ($params as $listener) {
174-
$this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
174+
$this->addListener($eventName, [$subscriber, $listener[0]], isset($listener[1]) ? $listener[1] : 0);
175175
}
176176
}
177177
}
@@ -185,10 +185,10 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
185185
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
186186
if (\is_array($params) && \is_array($params[0])) {
187187
foreach ($params as $listener) {
188-
$this->removeListener($eventName, array($subscriber, $listener[0]));
188+
$this->removeListener($eventName, [$subscriber, $listener[0]]);
189189
}
190190
} else {
191-
$this->removeListener($eventName, array($subscriber, \is_string($params) ? $params : $params[0]));
191+
$this->removeListener($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]);
192192
}
193193
}
194194
}
@@ -221,7 +221,7 @@ protected function doDispatch($listeners, $eventName, Event $event)
221221
private function sortListeners($eventName)
222222
{
223223
krsort($this->listeners[$eventName]);
224-
$this->sorted[$eventName] = array();
224+
$this->sorted[$eventName] = [];
225225

226226
foreach ($this->listeners[$eventName] as $priority => $listeners) {
227227
foreach ($listeners as $k => $listener) {

GenericEvent.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
2929
* @param mixed $subject The subject of the event, usually an object or a callable
3030
* @param array $arguments Arguments to store in the event
3131
*/
32-
public function __construct($subject = null, array $arguments = array())
32+
public function __construct($subject = null, array $arguments = [])
3333
{
3434
$this->subject = $subject;
3535
$this->arguments = $arguments;
@@ -95,7 +95,7 @@ public function getArguments()
9595
*
9696
* @return $this
9797
*/
98-
public function setArguments(array $args = array())
98+
public function setArguments(array $args = [])
9999
{
100100
$this->arguments = $args;
101101

0 commit comments

Comments
 (0)