Conditions | 6 |
Paths | 12 |
Total Lines | 23 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | protected function hierarchical(array $result): array |
||
22 | { |
||
23 | foreach ($result as $key => $node) { |
||
24 | $node->setRelation('children', new BaseCollection()); |
||
25 | } |
||
26 | |||
27 | $nestedKeys = []; |
||
28 | |||
29 | foreach ($result as $key => $node) { |
||
30 | $parentKey = $node->getParentId(); |
||
31 | |||
32 | if (!is_null($parentKey) && array_key_exists($parentKey, $result)) { |
||
33 | $result[$parentKey]->children[] = $node; |
||
34 | |||
35 | $nestedKeys[] = $node->getKey(); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | foreach ($nestedKeys as $key) { |
||
40 | unset($result[$key]); |
||
41 | } |
||
42 | |||
43 | return $result; |
||
44 | } |
||
46 |