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

EventDispatcher   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addSubscriber() 0 6 2
A hasListeners() 0 8 3
A dispatch() 0 10 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