TransformerCompilerPass::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
 * Collect all custom transformers
13
 */
14 View Code Duplication
class TransformerCompilerPass 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 TRANSFORMER_SERVICE_ID = 'oxidmod_rest.transformer';
20
21
    /**
22
     * @var string
23
     */
24
    const TRANSFORMER_SERVICE_TAG = 'oxidmod_rest.transformer';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(static::TRANSFORMER_SERVICE_ID)) {
32
            return;
33
        }
34
35
        $definition = $container->getDefinition(static::TRANSFORMER_SERVICE_ID);
36
37
        $transformers = array_keys($container->findTaggedServiceIds(static::TRANSFORMER_SERVICE_TAG));
38
39
        $transformersSet = [];
40
        foreach ($transformers as $transformer) {
41
            $transformersSet[] = new Reference($transformer);
42
        }
43
44
        $definition->replaceArgument(0, $transformersSet);
45
    }
46
}
47