Completed
Push — master ( e4af37...216fab )
by Peter
03:05
created

VoterListenerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 27
ccs 0
cts 14
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 21 5
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
use Symfony\Component\DependencyInjection\Reference;
15
16
class VoterListenerPass implements CompilerPassInterface
17
{
18
    /**
19
     * @param ContainerBuilder $container
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->has('domain_event.locator.voter')) {
24
            return;
25
        }
26
27
        $current_locator = $container->findDefinition('domain_event.locator');
28
        $voter_locator = $container->findDefinition('domain_event.locator.voter');
29
30
        // register services only if current locator is voter locator
31
        if ($voter_locator === $current_locator) {
32
            foreach ($container->findTaggedServiceIds('domain_event.listener') as  $id => $attributes) {
33
                $voter_locator->addMethodCall('register', [new Reference($id)]);
34
            }
35
        }
36
37
        // BC: get services from old tag
38
        foreach ($container->findTaggedServiceIds('domain_event.voter_listener') as  $id => $attributes) {
39
            $voter_locator->addMethodCall('register', [new Reference($id)]);
40
        }
41
    }
42
}
43