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

AbstractWrapper   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C setProperties() 0 21 10
A setPropertiesByKey() 0 12 4
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