ConfigureTranslatorPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.7691

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 1
dl 0
loc 26
ccs 7
cts 11
cp 0.6364
crap 4.7691
rs 9.8666
c 0
b 0
f 0
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