Completed
Push — master ( 8dd935...0e2bba )
by Peter
04:33
created

EventListenerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 21 7
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 2
    }
41
}
42