Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd5556f

Browse files
committed
[EventDispatcher] Add types to private properties
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent bf5dc51 commit bd5556f

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@ class TraceableEventDispatcher implements EventDispatcherInterface, ResetInterfa
3232
protected $logger;
3333
protected $stopwatch;
3434

35-
private $callStack;
36-
private $dispatcher;
37-
private $wrappedListeners;
38-
private $orphanedEvents;
39-
private $requestStack;
40-
private $currentRequestHash = '';
35+
private ?\SplObjectStorage $callStack = null;
36+
private EventDispatcherInterface $dispatcher;
37+
private array $wrappedListeners = [];
38+
private array $orphanedEvents = [];
39+
private ?RequestStack $requestStack;
40+
private string $currentRequestHash = '';
4141

4242
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null, RequestStack $requestStack = null)
4343
{
4444
$this->dispatcher = $dispatcher;
4545
$this->stopwatch = $stopwatch;
4646
$this->logger = $logger;
47-
$this->wrappedListeners = [];
48-
$this->orphanedEvents = [];
4947
$this->requestStack = $requestStack;
5048
}
5149

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,24 @@
2121
*/
2222
final class WrappedListener
2323
{
24-
private $listener;
25-
private $optimizedListener;
26-
private $name;
27-
private $called;
28-
private $stoppedPropagation;
29-
private $stopwatch;
30-
private $dispatcher;
31-
private $pretty;
32-
private $stub;
33-
private $priority;
34-
private static $hasClassStub;
24+
private string|array|object $listener;
25+
private ?\Closure $optimizedListener;
26+
private string $name;
27+
private bool $called = false;
28+
private bool $stoppedPropagation = false;
29+
private Stopwatch $stopwatch;
30+
private ?EventDispatcherInterface $dispatcher;
31+
private string $pretty;
32+
private ClassStub|string $stub;
33+
private ?int $priority = null;
34+
private static bool $hasClassStub;
3535

3636
public function __construct(callable|array $listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
3737
{
3838
$this->listener = $listener;
3939
$this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null);
4040
$this->stopwatch = $stopwatch;
4141
$this->dispatcher = $dispatcher;
42-
$this->called = false;
43-
$this->stoppedPropagation = false;
4442

4543
if (\is_array($listener)) {
4644
$this->name = \is_object($listener[0]) ? get_debug_type($listener[0]) : $listener[0];
@@ -66,12 +64,10 @@ public function __construct(callable|array $listener, ?string $name, Stopwatch $
6664
$this->name = $name;
6765
}
6866

69-
if (null === self::$hasClassStub) {
70-
self::$hasClassStub = class_exists(ClassStub::class);
71-
}
67+
self::$hasClassStub ??= class_exists(ClassStub::class);
7268
}
7369

74-
public function getWrappedListener()
70+
public function getWrappedListener(): callable|array
7571
{
7672
return $this->listener;
7773
}
@@ -93,9 +89,7 @@ public function getPretty(): string
9389

9490
public function getInfo(string $eventName): array
9591
{
96-
if (null === $this->stub) {
97-
$this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
98-
}
92+
$this->stub ??= self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
9993

10094
return [
10195
'event' => $eventName,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class AddEventAliasesPass implements CompilerPassInterface
2323
{
24-
private $eventAliases;
24+
private array $eventAliases;
2525

2626
public function __construct(array $eventAliases)
2727
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
*/
2626
class RegisterListenersPass implements CompilerPassInterface
2727
{
28-
private $hotPathEvents = [];
29-
private $hotPathTagName;
30-
private $noPreloadEvents = [];
31-
private $noPreloadTagName;
28+
private array $hotPathEvents = [];
29+
private string $hotPathTagName;
30+
private array $noPreloadEvents = [];
31+
private string $noPreloadTagName;
3232

3333
/**
3434
* @return $this

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
*/
3232
class EventDispatcher implements EventDispatcherInterface
3333
{
34-
private $listeners = [];
35-
private $sorted = [];
36-
private $optimized;
34+
private array $listeners = [];
35+
private array $sorted = [];
36+
private array $optimized;
3737

3838
public function __construct()
3939
{
@@ -49,7 +49,7 @@ public function dispatch(object $event, string $eventName = null): object
4949
{
5050
$eventName = $eventName ?? \get_class($event);
5151

52-
if (null !== $this->optimized) {
52+
if (isset($this->optimized)) {
5353
$listeners = $this->optimized[$eventName] ?? (empty($this->listeners[$eventName]) ? [] : $this->optimizeListeners($eventName));
5454
} else {
5555
$listeners = $this->getListeners($eventName);

src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class ImmutableEventDispatcher implements EventDispatcherInterface
2020
{
21-
private $dispatcher;
21+
private EventDispatcherInterface $dispatcher;
2222

2323
public function __construct(EventDispatcherInterface $dispatcher)
2424
{

0 commit comments

Comments
 (0)