Conditions | 9 |
Paths | 6 |
Total Lines | 33 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
20 | protected function setProperties(array $properties, array $mappings, string $column = null) |
||
21 | { |
||
22 | foreach ($properties as $key => $value) { |
||
23 | if (!isset($mappings[$key])) { |
||
24 | throw new \RuntimeException(sprintf('No mapping found for key "%s"', $key)); |
||
25 | } |
||
26 | |||
27 | if (is_array($value) && is_array($mappings[$key])) { |
||
28 | // recursion |
||
29 | /** |
||
30 | * @var array $value |
||
31 | */ |
||
32 | if (isset($mappings[$key]['__multi'])) { |
||
33 | // handle multi target structure (with columns) |
||
34 | foreach ($value as $_column => $_value) { |
||
35 | $this->setProperties($_value, $mappings[$key], $_column); |
||
36 | } |
||
37 | } else { |
||
38 | // handle single target structure |
||
39 | $this->setProperties($value, $mappings[$key]); |
||
40 | } |
||
41 | } elseif (is_callable($mappings[$key])) { |
||
42 | // call single and multi target mapping |
||
43 | // if column is set it is used to get object from the callback in __multi |
||
44 | $mappings[$key]( |
||
45 | $value, |
||
46 | $column !== null ? $mappings['__multi']($column) : null |
||
47 | ); |
||
48 | } else { |
||
49 | throw new \RuntimeException(sprintf('Invalid mapping for key "%s"', $key)); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 |