EventBus   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publish() 0 6 1
A getRegisteredEventListeners() 0 4 1
A handleListenersForEvent() 0 10 2
1
<?php
2
3
namespace PhpDDD\Domain\Event\Bus;
4
5
use PhpDDD\Domain\Event\EventInterface;
6
use PhpDDD\Domain\Event\Listener\EventListenerCollection;
7
use PhpDDD\Domain\Event\Listener\EventListenerInterface;
8
use PhpDDD\Domain\Event\Listener\Locator\EventListenerLocatorInterface;
9
10
/**
11
 * Implementation of EventBusInterface.
12
 */
13
class EventBus implements EventBusInterface
14
{
15
    /**
16
     * @var EventListenerLocatorInterface
17
     */
18
    private $locator;
19
20
    /**
21
     * @param EventListenerLocatorInterface $locator
22
     */
23
    public function __construct(EventListenerLocatorInterface $locator)
24
    {
25
        $this->locator = $locator;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function publish(EventInterface $event)
32
    {
33
        $listeners = $this->locator->getEventListenersForEvent($event);
34
35
        return $this->handleListenersForEvent($event, $listeners);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getRegisteredEventListeners()
42
    {
43
        return $this->locator->getRegisteredEventListeners();
44
    }
45
46
    /**
47
     * @param EventInterface                                   $event
48
     * @param EventListenerCollection|EventListenerInterface[] $listeners
49
     *
50
     * @return array
51
     */
52
    private function handleListenersForEvent(EventInterface $event, $listeners)
53
    {
54
        $return = array();
55
56
        foreach ($listeners as $listener) {
57
            $return[] = $listener->handle($event);
58
        }
59
60
        return $return;
61
    }
62
}
63