RequestModifierCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 33
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 17 17 3

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
declare (strict_types=1);
4
5
namespace Oxidmod\RestBundle\DependencyInjection\Compiler;
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
/**
12
 * Add request modifiers to root modifier
13
 */
14 View Code Duplication
class RequestModifierCompilerPass 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...
15
{
16
    /**
17
     * @var string
18
     */
19
    const MODIFIER_SERVICE_ID = 'oxidmod_rest.request_modifier';
20
21
    /**
22
     * @var string
23
     */
24
    const MODIFIER_SERVICE_TAG = 'oxidmod_rest.request_modifier';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(static::MODIFIER_SERVICE_ID)) {
32
            return;
33
        }
34
35
        $definition = $container->getDefinition(static::MODIFIER_SERVICE_ID);
36
37
        $modifiers = array_keys($container->findTaggedServiceIds(static::MODIFIER_SERVICE_TAG));
38
39
        $modifiersSet = [];
40
        foreach ($modifiers as $modifier) {
41
            $modifiersSet[] = new Reference($modifier);
42
        }
43
44
        $definition->replaceArgument(0, $modifiersSet);
45
    }
46
}
47