Completed
Push — master ( bf06df...afb281 )
by Mewes
02:20
created

AbstractWrapper::setProperties()   C

Complexity

Conditions 10
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 6.6746
c 0
b 0
f 0
cc 10
eloc 11
nc 5
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace MewesK\TwigExcelBundle\Wrapper;
4
5
/**
6
 * Class AbstractWrapper
7
 *
8
 * @package MewesK\TwigExcelBundle\Wrapper
9
 */
10
abstract class AbstractWrapper
11
{
12
    /**
13
     * @param array $properties
14
     * @param array $mappings
15
     */
16
    protected function setProperties(array $properties, array $mappings)
17
    {
18
        foreach ($properties as $key => $value) {
19
            if (array_key_exists($key, $mappings)) {
20
                if (is_array($value) && is_array($mappings) && $key !== 'style' && $key !== 'defaultStyle') {
21
                    /**
22
                     * @var array $value
23
                     */
24
                    if (array_key_exists('__multi', $mappings[$key]) && $mappings[$key]['__multi'] === true) {
25
                        foreach ($value as $_key => $_value) {
26
                            $this->setPropertiesByKey($_key, $_value, $mappings[$key]);
27
                        }
28
                    } else {
29
                        $this->setProperties($value, $mappings[$key]);
30
                    }
31
                } else {
32
                    $mappings[$key]($value);
33
                }
34
            }
35
        }
36
    }
37
38
    /**
39
     * @param string $key
40
     * @param array $properties
41
     * @param array $mappings
42
     */
43
    protected function setPropertiesByKey($key, array $properties, array $mappings)
44
    {
45
        foreach ($properties as $_key => $value) {
46
            if (array_key_exists($_key, $mappings)) {
47
                if (is_array($value)) {
48
                    $this->setPropertiesByKey($key, $value, $mappings[$_key]);
49
                } else {
50
                    $mappings[$_key]($key, $value);
51
                }
52
            }
53
        }
54
    }
55
}
56