ConfigPass::buildParameters()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 4
nc 3
nop 3
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