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

NamedEventListenerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 2
dl 10
loc 31
ccs 0
cts 18
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 10 25 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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