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

NamedEventListenerPass::process()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 25
Code Lines 12

Duplication

Lines 10
Ratio 40 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 25
ccs 0
cts 18
cp 0
rs 6.7272
cc 7
eloc 12
nc 9
nop 1
crap 56
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 NamedEventListenerPass implements CompilerPassInterface
16
{
17
    /**
18
     * @param ContainerBuilder $container
19
     */
20
    public function process(ContainerBuilder $container)
21
    {
22
        if (!$container->has('domain_event.locator.named_event')) {
23
            return;
24
        }
25
26
        $current_locator = $container->findDefinition('domain_event.locator');
27
        $named_event_locator = $container->findDefinition('domain_event.locator.named_event');
28
29
        // register services only if current locator is named event locator
30
        if ($named_event_locator === $current_locator) {
31 View Code Duplication
            foreach ($container->findTaggedServiceIds('domain_event.listener') as $id => $attributes) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
                foreach ($attributes as $attribute) {
33
                    $named_event_locator->addMethodCall('registerService', [$attribute['event'], $id]);
34
                }
35
            }
36
        }
37
38
        // BC: get services from old tag
39 View Code Duplication
        foreach ($container->findTaggedServiceIds('domain_event.named_event_listener') as $id => $attributes) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            foreach ($attributes as $attribute) {
41
                $named_event_locator->addMethodCall('registerService', [$attribute['event'], $id]);
42
            }
43
        }
44
    }
45
}
46