EventDispatcher::dispatch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 15
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace NamespaceProtector\Event;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\EventDispatcher\ListenerProviderInterface;
9
10
final class EventDispatcher implements EventDispatcherInterface
11
{
12
    public function __construct(private ListenerProviderInterface $listenerProvider)
13
    {
14
    }
15
16
    public function dispatch(object $event)
17
    {
18
        $this->listenerProvider->getListenersForEvent($event);
19
20
        /** @var array<callable> */
21
        $listeners = $this->listenerProvider->getListenersForEvent($event);
22
23
        array_map(
24
            function (callable $listener) use ($event): void {
25
                $listener($event);
26
            },
27
            $listeners
0 ignored issues
show
Bug introduced by
$listeners of type iterable is incompatible with the type array expected by parameter $array of array_map(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            /** @scrutinizer ignore-type */ $listeners
Loading history...
28
        );
29
30
        return $event;
31
    }
32
}
33