Completed
Push — master ( f3c39a...26f1f7 )
by Tobias
08:36
created

ExternalTranslatorPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

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
    public function process(ContainerBuilder $container)
25
    {
26
        /* @var Definition $def */
27
        if (!$container->hasDefinition('php_translation.translator_service.external_translator')) {
28
            return;
29
        }
30
31
        $services = $container->findTaggedServiceIds('php_translation.external_translator');
32
        $translators = [];
33
        foreach ($services as $id => $tags) {
34
            foreach ($tags as $tag) {
35
                if (!isset($tag['priority'])) {
36
                    $tag['priority'] = 0;
37
                }
38
                $translators[$id] = $tag['priority'];
39
            }
40
        }
41
42
        // Sort by priority
43
        asort($translators);
44
45
        $def = $container->getDefinition('php_translation.translator_service.external_translator');
46
        foreach ($translators as $id => $prio) {
47
            $def->addMethodCall('addTranslatorService', [new Reference($id)]);
48
        }
49
    }
50
}
51