Completed
Push — 3.1.x ( b8b6d2...fd2df9 )
by Karel
14:12 queued 11:28
created

TransformerPass   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 77.78%
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 33
ccs 14
cts 18
cp 0.7778
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 27 8
1
<?php
2
3
namespace FOS\ElasticaBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\Reference;
8
use InvalidArgumentException;
9
10
/**
11
 * Registers Transformer implementations into the TransformerCollection.
12
 *
13
 * @author Tim Nagel <[email protected]>
14
 */
15
class TransformerPass implements CompilerPassInterface
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20 6
    public function process(ContainerBuilder $container)
21
    {
22 6
        if (!$container->hasDefinition('fos_elastica.elastica_to_model_transformer.collection')) {
23
            return;
24
        }
25
26 6
        $transformers = array();
27
28 6
        foreach ($container->findTaggedServiceIds('fos_elastica.elastica_to_model_transformer') as $id => $tags) {
29 2
            foreach ($tags as $tag) {
30 2
                if (empty($tag['index']) || empty($tag['type'])) {
31
                    throw new InvalidArgumentException('The Transformer must have both a type and an index defined.');
32
                }
33
34 2
                $transformers[$tag['index']][$tag['type']] = new Reference($id);
35 2
            }
36 6
        }
37
38 6
        foreach ($transformers as $index => $indexTransformers) {
39 2
            if (!$container->hasDefinition(sprintf('fos_elastica.elastica_to_model_transformer.collection.%s', $index))) {
40 2
                continue;
41
            }
42
43
            $index = $container->getDefinition(sprintf('fos_elastica.elastica_to_model_transformer.collection.%s', $index));
44
            $index->replaceArgument(0, $indexTransformers);
45 6
        }
46 6
    }
47
}
48