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