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

EventDispatcherAdapter::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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