Completed
Push — master ( e55918...6255e6 )
by Maxime
02:42 queued 35s
created

ConfigPass   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 26.47 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 9
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
A buildParameters() 9 9 4
A arrayHasStringKeys() 0 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    protected function buildParameters($name, &$parameters, $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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