ConfigPass   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A arrayHasStringKeys() 0 10 3
A process() 0 7 2
A buildParameters() 0 7 4
1
<?php
2
3
namespace Knp\FriendlyContexts\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class ConfigPass implements CompilerPassInterface
9
{
10
    public function process(ContainerBuilder $container)
11
    {
12
        $parameters = [];
13
        $this->buildParameters('friendly', $parameters, $container->getParameter('friendly.parameters'));
14
15
        foreach ($parameters as $key => $value) {
16
            $container->setParameter($key, $value);
17
        }
18
    }
19
20
    protected function buildParameters($name, &$parameters, $config)
21
    {
22
        foreach ($config as $key => $element) {
23
            if (is_array($element) && $this->arrayHasStringKeys($element)) {
24
                $this->buildParameters(sprintf('%s.%s', $name, $key), $parameters, $element);
25
            }
26
            $parameters[sprintf('%s.%s', $name, $key)] = $element;
27
        }
28
    }
29
30
    protected function arrayHasStringKeys(array $array)
31
    {
32
        foreach ($array as $key => $value) {
33
            if (is_string($key)) {
34
35
                return true;
36
            }
37
        }
38
39
        return false;
40
    }
41
}
42