| Conditions | 5 |
| Paths | 5 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 8 | public function parse(array $entity) |
|
| 13 | { |
||
| 14 | 8 | $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($entity)); |
|
| 15 | 8 | $current = []; |
|
| 16 | 8 | $res = []; |
|
| 17 | 8 | $depthMap = []; |
|
| 18 | 8 | $prevDepth = 0; |
|
| 19 | 8 | foreach ($iterator as $key => $value) { |
|
| 20 | 8 | $depth = $iterator->getDepth(); |
|
| 21 | 8 | if ($depth < $prevDepth) { |
|
| 22 | 1 | $res[] = $current; |
|
| 23 | 1 | $depthMap = []; |
|
| 24 | 1 | } |
|
| 25 | 8 | if (isset($depthMap[$depth]) && in_array($key, $depthMap[$depth])) { |
|
| 26 | 5 | $res[] = $current; |
|
| 27 | 5 | $depthMap = []; |
|
| 28 | 5 | $depthMap[$depth][] = $key; |
|
| 29 | 5 | } else { |
|
| 30 | 8 | $depthMap[$depth][] = $key; |
|
| 31 | } |
||
| 32 | 8 | $current[$key] = $value; |
|
| 33 | 8 | $prevDepth = $depth; |
|
| 34 | 8 | } |
|
| 35 | 8 | $res[] = $current; |
|
| 36 | 8 | return $res; |
|
| 37 | } |
||
| 38 | } |
||
| 39 |