Completed
Push — master ( 7fae80...8ffdf8 )
by Matthew
07:25
created

EventDispatcher::dispatch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
nc 3
cc 3
eloc 5
nop 2
crap 3
1
<?php
2
3
namespace Dtc\QueueBundle\EventDispatcher;
4
5
class EventDispatcher
6
{
7
    private $listeners = array();
8
9 1
    public function addSubscriber(EventSubscriberInterface $subscriber)
10
    {
11 1
        foreach ($subscriber->getSubscribedEvents() as $key => $value) {
12 1
            $this->listeners[$key][] = [$subscriber, $value];
13
        }
14 1
    }
15
16 1
    public function hasListeners($eventName)
17
    {
18 1
        if (!isset($this->listeners[$eventName])) {
19 1
            return false;
20
        }
21
22 1
        return $this->listeners[$eventName] ? true : false;
23
    }
24
25 7
    public function dispatch($eventName, Event $event)
26
    {
27 7
        if (!isset($this->listeners[$eventName])) {
28 6
            return;
29
        }
30
31 1
        foreach ($this->listeners[$eventName] as $callback) {
32 1
            call_user_func($callback, $event);
33
        }
34 1
    }
35
}
36