Completed
Pull Request — master (#16)
by Christophe
06:47 queued 23s
created

ExtractorPass::process()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 1
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Alias;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class ExtractorPass implements CompilerPassInterface
11
{
12
    public function process(ContainerBuilder $container)
13
    {
14
        $extractors = array();
15
16
        foreach ($container->findTaggedServiceIds('incenteev_translation_checker.extractor') as $id => $tags) {
17
            $extractors[] = new Reference($id);
18
        }
19
20
        // If there is only one configured extractor, skip the chain one
21
        if (1 === count($extractors)) {
22
            $container->setAlias('incenteev_translation_checker.extractor', new Alias((string) $extractors[0], $container->getAlias('incenteev_translation_checker.extractor')->isPublic()));
23
24
            return;
25
        }
26
27
        $container->getDefinition('incenteev_translation_checker.extractor.chain')->replaceArgument(0, $extractors);
28
    }
29
}
30