Passed
Push — master ( 83ac3f...15f95c )
by Alexander
11:33 queued 10:26
created

Dispatcher::dispatch()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 5
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 4
rs 10
1
<?php
2
3
namespace Yiisoft\EventDispatcher\Dispatcher;
4
5
use Psr\EventDispatcher\EventDispatcherInterface;
6
use Psr\EventDispatcher\ListenerProviderInterface;
7
use Psr\EventDispatcher\StoppableEventInterface;
8
9
/**
10
 * Dispatcher executes listeners attached to event passed
11
 * @see https://www.php-fig.org/psr/psr-14/
12
 */
13
final class Dispatcher implements EventDispatcherInterface
14
{
15
    private ListenerProviderInterface $listenerProvider;
16
17 2
    public function __construct(ListenerProviderInterface $listenerProvider)
18
    {
19 2
        $this->listenerProvider = $listenerProvider;
20
    }
21
22 2
    public function dispatch(object $event): object
23
    {
24 2
        foreach ($this->listenerProvider->getListenersForEvent($event) as $listener) {
25 2
            if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
26 1
                return $event;
27
            }
28 2
            $listener($event);
29
        }
30
31 1
        return $event;
32
    }
33
}
34