Completed
Push — master ( 52d799...bb7198 )
by Tobias
13:11
created

ExternalTranslatorPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 29
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 26 6
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
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 Translation\Bundle\DependencyInjection\CompilerPass;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
class ExternalTranslatorPass implements CompilerPassInterface
23
{
24 3
    public function process(ContainerBuilder $container)
25
    {
26
        /* @var Definition $def */
27 3
        if (!$container->hasDefinition('php_translation.translator_service.external_translator')) {
28 2
            return;
29
        }
30
31 1
        $services = $container->findTaggedServiceIds('php_translation.external_translator');
32 1
        $translators = [];
33 1
        foreach ($services as $id => $tags) {
34 1
            foreach ($tags as $tag) {
35 1
                if (!isset($tag['priority'])) {
36 1
                    $tag['priority'] = 0;
37 1
                }
38 1
                $translators[$id] = $tag['priority'];
39 1
            }
40 1
        }
41
42
        // Sort by priority
43 1
        asort($translators);
44
45 1
        $def = $container->getDefinition('php_translation.translator_service.external_translator');
46 1
        foreach ($translators as $id => $prio) {
47 1
            $def->addMethodCall('addTranslatorService', [new Reference($id)]);
48 1
        }
49 1
    }
50
}
51