ListenerLocatedEventBus   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publish() 0 6 2
A pullAndPublish() 0 6 2
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Domain\Event\Bus;
11
12
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
13
use GpsLab\Domain\Event\Event;
14
use GpsLab\Domain\Event\Listener\Locator\EventListenerLocator;
15
16
class ListenerLocatedEventBus implements EventBus
17
{
18
    /**
19
     * @var EventListenerLocator
20
     */
21
    private $locator;
22
23
    /**
24
     * @param EventListenerLocator $locator
25
     */
26 2
    public function __construct(EventListenerLocator $locator)
27
    {
28 2
        $this->locator = $locator;
29 2
    }
30
31
    /**
32
     * Publishes the event to every listener that wants to.
33
     *
34
     * @param Event $event
35
     */
36 2
    public function publish(Event $event)
37
    {
38 2
        foreach ($this->locator->listenersOfEvent($event) as $listener) {
39 2
            call_user_func($listener, $event);
40
        }
41 2
    }
42
43
    /**
44
     * @param AggregateEvents $aggregator
45
     */
46 1
    public function pullAndPublish(AggregateEvents $aggregator)
47
    {
48 1
        foreach ($aggregator->pullEvents() as $event) {
49 1
            $this->publish($event);
50
        }
51 1
    }
52
}
53