ExtractorPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 4
nop 1
dl 0
loc 16
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 0
f 0
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
/**
11
 * @internal
12 5
 */
13
final class ExtractorPass implements CompilerPassInterface
14 5
{
15
    public function process(ContainerBuilder $container): void
16 5
    {
17 4
        $extractors = array();
18
19
        foreach ($container->findTaggedServiceIds('incenteev_translation_checker.extractor') as $id => $tags) {
20
            $extractors[] = new Reference($id);
21 5
        }
22 3
23
        // If there is only one configured extractor, skip the chain one
24 3
        if (1 === count($extractors)) {
25
            $container->setAlias('incenteev_translation_checker.extractor', new Alias((string) $extractors[0], $container->getAlias('incenteev_translation_checker.extractor')->isPublic()));
26
27 2
            return;
28 2
        }
29
30
        $container->getDefinition('incenteev_translation_checker.extractor.chain')->replaceArgument(0, $extractors);
31
    }
32
}
33