Completed
Push — master ( 4109b7...859c70 )
by Matthew
08:07 queued 02:26
created

EventDispatcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 31
ccs 3
cts 16
cp 0.1875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasListeners() 0 8 2
A addSubscriber() 0 6 2
A dispatch() 0 10 3
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 4
    public function dispatch($eventName, Event $event)
26
    {
27 4
        if (!isset($this->listeners[$eventName])) {
28 4
            return;
29
        }
30
31
        foreach ($this->listeners[$eventName] as $callback) {
32
            call_user_func($callback, $event);
33
        }
34
    }
35
}
36