Passed
Push — main ( bf434a...128b22 )
by Michael
02:11
created

CompilerPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
A getConfigValue() 0 12 3
1
<?php
2
3
namespace Braunstetter\LocalizedRoutes\DependencyInjection\Compiler;
4
5
use Braunstetter\LocalizedRoutes\EventSubscriber\LocaleRewriteSubscriber;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
class CompilerPass implements CompilerPassInterface
10
{
11
12 2
    public function process(ContainerBuilder $container)
13
    {
14
15 2
        if (!$container->hasDefinition(LocaleRewriteSubscriber::class)) {
16 1
            return;
17
        }
18
19 1
        $frameworkConfig = $container->getExtensionConfig('framework');
20 1
        $subscriberDefinition = $container->getDefinition(LocaleRewriteSubscriber::class);
21 1
        $subscriberDefinition->replaceArgument(1, $this->getConfigValue('enabled_locales', $frameworkConfig));
22
23 1
        if ($defaultLocale = $this->getConfigValue('default_locale', $frameworkConfig)) {
24 1
            $container->setParameter('default_locale', $defaultLocale);
25
        }
26
27 1
        if ($enabledLocales = $this->getConfigValue('enabled_locales', $frameworkConfig)) {
28 1
            $container->setParameter('enabled_locales', $enabledLocales);
29 1
            $container->setParameter('enabled_locales_string', implode('|', $enabledLocales));
30
        }
31
    }
32
33 1
    private function getConfigValue(string $key, array $config)
34
    {
35 1
        $value = null;
36
37 1
        foreach ($config as $configItem) {
38 1
            if (array_key_exists($key, $configItem)) {
39 1
                $value = $configItem[$key];
40 1
                break;
41
            }
42
        }
43
44 1
        return $value;
45
    }
46
}