Dispatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

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