Passed
Push — 26-use-psr-14-event-dispatcher ( ab95da )
by Jakub
02:36
created

TesterEventDispatcher   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A dispatch() 0 10 4
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester;
5
6
use Psr\EventDispatcher\EventDispatcherInterface;
7
use Psr\EventDispatcher\ListenerProviderInterface;
8
use Psr\EventDispatcher\StoppableEventInterface;
9
10
/**
11
 * Event dispatcher for {@see Tester}
12
 *
13
 * @author Jakub Konečný
14
 * @internal
15
 */
16
final class TesterEventDispatcher implements EventDispatcherInterface
17
{
18
    private ListenerProviderInterface $listenerProvider;
19
20
    public function __construct(ListenerProviderInterface $listenerProvider)
21
    {
22 1
        $this->listenerProvider = $listenerProvider;
23 1
    }
24
25
    /**
26
     * @template T of object
27
     * @param T $event
28
     * @return T
29
     */
30
    public function dispatch(object $event): object
31
    {
32 1
        $listeners = $this->listenerProvider->getListenersForEvent($event);
33 1
        foreach ($listeners as $listener) {
34 1
            if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
35 1
                break;
36
            }
37 1
            $listener($event);
38
        }
39 1
        return $event;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $event also could return the type Psr\EventDispatcher\StoppableEventInterface which is incompatible with the documented return type MyTester\T.
Loading history...
40
    }
41
}
42