EventDispatcher::dispatch()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Event;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Psr\EventDispatcher\ListenerProviderInterface;
9
use Psr\EventDispatcher\StoppableEventInterface;
10
11
class EventDispatcher implements EventDispatcherInterface
12
{
13
    private ListenerProviderInterface $listenerProvider;
14
15 5
    public function __construct(ListenerProviderInterface $listenerProvider)
16
    {
17 5
        $this->listenerProvider = $listenerProvider;
18 5
    }
19
20
    /**
21
     * @param StoppableEventInterface $event
22
     * @return object
23
     */
24 3
    public function dispatch(object $event): object
25
    {
26 3
        $listeners = $this->listenerProvider->getListenersForEvent($event);
27 3
        foreach ($listeners as $listener) {
28 3
            if ($event->isPropagationStopped()) {
29 1
                return $event;
30
            }
31 2
            $listener($event);
32
        }
33
34 2
        return $event;
35
    }
36
}
37