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

EventDispatcherAdapter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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