Completed
Push — master ( 35b0ee...93e632 )
by Daniel
77:46 queued 59:08
created

EventBusFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createEventBus() 0 10 3
1
<?php
2
/**
3
 * @package narrator-bundle
4
 */
5
6
7
namespace Mleko\Narrator\Bundle;
8
9
10
use Mleko\Narrator\EventNameExtractor;
11
use Symfony\Component\DependencyInjection\ContainerInterface;
12
13
class EventBusFactory
14
{
15
    /**
16
     * @var ContainerInterface
17
     */
18
    private $container;
19
20
    /**
21
     * EventBusFactory constructor.
22
     * @param ContainerInterface $container
23
     */
24
    public function __construct(ContainerInterface $container)
25
    {
26
        $this->container = $container;
27
    }
28
29
    /**
30
     * @param EventNameExtractor $nameExtractor
31
     * @param $listenerDefinitions
32
     * @return \Mleko\Narrator\BasicEventBus
33
     */
34
    public function createEventBus(EventNameExtractor $nameExtractor, $listenerDefinitions)
35
    {
36
        $listeners = [];
37
        foreach ($listenerDefinitions as $eventName => $listenerDefinition) {
38
            foreach ($listenerDefinition as $listenerData) {
39
                $listeners[$eventName][] = new Listener\ListenerService($listenerData['serviceId'], $this->container, $listenerData['methodName']);
40
            }
41
        }
42
        return new \Mleko\Narrator\BasicEventBus($nameExtractor, $listeners);
43
    }
44
45
}
46