Completed
Push — master ( 2d3688...ca6653 )
by Peter
03:43
created

EventListenerPass   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 32
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 26 8
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\Bundle\DomainEvent\DependencyInjection\Compiler;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
15
class EventListenerPass implements CompilerPassInterface
16
{
17
    /**
18
     * @param ContainerBuilder $container
19
     */
20 4
    public function process(ContainerBuilder $container)
21
    {
22 4
        if (!$container->has('domain_event.locator')) {
23 1
            return;
24
        }
25
26 3
        $current_locator = $container->findDefinition('domain_event.locator');
27 3
        $symfony_locator = $container->findDefinition('domain_event.locator.symfony');
28 3
        $container_locator = $container->findDefinition('domain_event.locator.container');
29
30 3
        if ($current_locator !== $symfony_locator && $current_locator !== $container_locator) {
31 1
            return;
32
        }
33
34 2
        foreach ($container->findTaggedServiceIds('domain_event.listener') as $id => $attributes) {
35 2
            foreach ($attributes as $attribute) {
36 2
                $method = !empty($attribute['method']) ? $attribute['method'] : '__invoke';
37 2
                $current_locator->addMethodCall('registerService', [$attribute['event'], $id, $method]);
38
            }
39
        }
40
41 2
        foreach ($container->findTaggedServiceIds('domain_event.subscriber') as $id => $attributes) {
42
            $subscriber = $container->findDefinition($id);
43
            $current_locator->addMethodCall('registerSubscriberService', [$id, $subscriber->getClass()]);
44
        }
45
    }
46
}
47