Dispatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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