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

EventListenerPass::process()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8.4218

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 13
cts 16
cp 0.8125
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 15
nc 10
nop 1
crap 8.4218
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