Dispatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 7
c 0
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 13 4
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\EventDispatcher\Dispatcher;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\EventDispatcher\ListenerProviderInterface;
9
use Psr\EventDispatcher\StoppableEventInterface;
10
11
/**
12
 * Dispatcher executes listeners attached to event passed.
13
 *
14
 * @see https://www.php-fig.org/psr/psr-14/
15
 */
16
final class Dispatcher implements EventDispatcherInterface
17
{
18 3
    public function __construct(private ListenerProviderInterface $listenerProvider)
19
    {
20 3
    }
21
22 3
    public function dispatch(object $event): object
23
    {
24
        /** @var callable $listener */
25 3
        foreach ($this->listenerProvider->getListenersForEvent($event) as $listener) {
26 3
            if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
27 1
                return $event;
28
            }
29
30 3
            $spoofableEvent = $event;
31 3
            $listener($spoofableEvent);
32
        }
33
34 2
        return $event;
35
    }
36
}
37