EventDispatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A dispatch() 0 11 3
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