ConfigureTranslatorPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 26 4
1
<?php
2
3
namespace Incenteev\TranslationCheckerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
/**
9
 * @internal
10 1
 */
11
class ConfigureTranslatorPass implements CompilerPassInterface
12 1
{
13
    public function process(ContainerBuilder $container): void
14
    {
15
        if (!$container->hasDefinition('incenteev_translation_checker.exposing_translator')) {
16 1
            return;
17
        }
18
19
        if (!$container->has('translator.default')) {
20 1
            return;
21
        }
22
23 1
        $translatorDef = $container->findDefinition('translator.default');
24 1
25
        $optionsArgumentIndex = 4;
26
27
        $options = $translatorDef->getArgument($optionsArgumentIndex);
28
29 1
        if (!is_array($options)) {
30
            // Weird setup. Reset all options
31 1
            $options = array();
32
        }
33
34
        // use a separate cache as we have no fallback locales
35
        $options['cache_dir'] = '%kernel.cache_dir%/incenteev_translations';
36
37 1
        $container->findDefinition('incenteev_translation_checker.exposing_translator')
38
            ->replaceArgument($optionsArgumentIndex, $options);
39 1
    }
40
}
41