Completed
Push — master ( 6255e6...e55918 )
by Maxime
02:20
created

ConfigPass::buildParameters()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 8
nc 9
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
    /**
21
     * @param string $name
22
     * @param array  $parameters
23
     * @param array  $config
24
     */
25
    protected function buildParameters($name, &$parameters, $config)
26
    {
27
        foreach ($config as $key => $element) {
28
            if (is_array($element) && $this->arrayHasStringKeys($element)) {
29
                $this->buildParameters(sprintf('%s.%s', $name, $key), $parameters, $element);
30
            }
31
            $parameters[sprintf('%s.%s', $name, $key)] = $element;
32
        }
33
34
        if (!empty($parameters['friendly.smartTag'])) {
35
           if ($parameters['friendly.smartStep.tagName'] === 'smartStep') {
36
               $parameters['friendly.smartStep.tagName'] = $parameters['friendly.smartTag'];
37
           }
38
39
           // TODO: trigger deprecation error
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
40
        }
41
    }
42
43
    protected function arrayHasStringKeys(array $array)
44
    {
45
        foreach ($array as $key => $value) {
46
            if (is_string($key)) {
47
48
                return true;
49
            }
50
        }
51
52
        return false;
53
    }
54
}
55