Completed
Push — master ( d448ac...513048 )
by Matthew
31:40 queued 17:02
created

EventDispatcher::dispatch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.125

Importance

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