Passed
Push — master ( 4da179...4cded1 )
by Yannick
02:33
created

EventDispatcherAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 3 1
A __construct() 0 6 2
A addListener() 0 3 1
1
<?php
2
3
namespace Star\Component\State\Port\Symfony;
4
5
use Star\Component\State\Event\StateEvent;
6
use Star\Component\State\EventRegistry;
7
use Symfony\Component\EventDispatcher\EventDispatcher;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
10
final class EventDispatcherAdapter implements EventRegistry
11
{
12
    /**
13
     * @var EventDispatcherInterface
14
     */
15
    private $dispatcher;
16
17
    /**
18
     * @param EventDispatcherInterface $dispatcher
19
     */
20 36
    public function __construct(EventDispatcherInterface $dispatcher = null)
21
    {
22 36
        if (! $dispatcher) {
23 36
            $dispatcher = new EventDispatcher();
24
        }
25 36
        $this->dispatcher = $dispatcher;
26 36
    }
27
28
    /**
29
     * @param string $name
30
     * @param StateEvent $event
31
     */
32 23
    public function dispatch($name, StateEvent $event)
33
    {
34 23
        $this->dispatcher->dispatch($name, $event);
35 23
    }
36
37
    /**
38
     * @param string $event
39
     * @param callable $listener
40
     */
41
    public function addListener($event, $listener)
42
    {
43
        $this->dispatcher->addListener($event, $listener);
44
    }
45
}
46