Completed
Push — master ( 3cdfc2...4aa078 )
by Maksim
03:09
created

TransformerPass   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 33
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 27 8
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\DependencyInjection\Compiler;
13
14
use InvalidArgumentException;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * Registers Transformer implementations into the TransformerCollection.
21
 *
22
 * @author Tim Nagel <[email protected]>
23
 */
24
class TransformerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 3
    public function process(ContainerBuilder $container)
30
    {
31 3
        if (!$container->hasDefinition('fos_elastica.elastica_to_model_transformer.collection')) {
32
            return;
33
        }
34
35 3
        $transformers = [];
36
37 3
        foreach ($container->findTaggedServiceIds('fos_elastica.elastica_to_model_transformer') as $id => $tags) {
38 2
            foreach ($tags as $tag) {
39 2
                if (empty($tag['index']) || empty($tag['type'])) {
40
                    throw new InvalidArgumentException('The Transformer must have both a type and an index defined.');
41
                }
42
43 2
                $transformers[$tag['index']][$tag['type']] = new Reference($id);
44
            }
45
        }
46
47 3
        foreach ($transformers as $index => $indexTransformers) {
48 2
            if (!$container->hasDefinition(sprintf('fos_elastica.elastica_to_model_transformer.collection.%s', $index))) {
49 2
                continue;
50
            }
51
52
            $index = $container->getDefinition(sprintf('fos_elastica.elastica_to_model_transformer.collection.%s', $index));
53
            $index->replaceArgument(0, $indexTransformers);
54
        }
55 3
    }
56
}
57