RequestModifierCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
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