Completed
Push — feature/EVO-8289_proxy_bundle_... ( 5c5976 )
by Bastian
11:46
created

ProxySourceRegistryPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 32
loc 32
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 22 22 4

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
 * ProxySourceRegistryPass
4
 */
5
6
namespace Graviton\ProxyBundle\DependencyInjection\Compiler;
7
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
/**
13
 * Class ProxySourceRegistryPass
14
 *
15
 * @package Graviton\ProxyExtensionBundle\Definition\Loader
16
 *
17
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
18
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
19
 * @link     http://swisscom.ch
20
 */
21 View Code Duplication
class ProxySourceRegistryPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
22
{
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @param ContainerBuilder $container Symfony Service container
27
     *
28
     * @return void
29
     */
30 2
    public function process(ContainerBuilder $container)
31
    {
32
        // always first check if the primary service is defined
33 2
        if (!$container->has('graviton.proxy.service.source_registry')) {
34
            return;
35
        }
36
37 2
        $definition = $container->findDefinition('graviton.proxy.service.source_registry');
38 2
        $taggedServices = $container->findTaggedServiceIds('graviton.proxy.source');
39
40 2
        foreach ($taggedServices as $id => $tags) {
41 2
            foreach ($tags as $attributes) {
42 2
                $definition->addMethodCall(
43 2
                    'add',
44
                    array(
45 2
                        new Reference($id),
46 2
                        $attributes["alias"]
47 1
                    )
48 1
                );
49 1
            }
50 1
        }
51 2
    }
52
}
53