Dispatcher::dispatch()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.0466

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 1
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
crap 4.0466
rs 10
c 0
b 0
f 0
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