| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | public static function flattenTree(array $nodeTree, int $parentId = null) |
||
| 35 | { |
||
| 36 | $nodeArrays = []; |
||
| 37 | $position = 0; |
||
| 38 | |||
| 39 | foreach ($nodeTree as $node) { |
||
| 40 | $nodeArrays[] = [ |
||
| 41 | 'id' => $node['id'], |
||
| 42 | 'position' => $position++, |
||
| 43 | 'parent_id' => $parentId, |
||
| 44 | ]; |
||
| 45 | |||
| 46 | if (count($node['children']) > 0) { |
||
| 47 | $childArrays = self::flattenTree($node['children'], $node['id']); |
||
| 48 | $nodeArrays = array_merge($nodeArrays, $childArrays); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | return $nodeArrays; |
||
| 53 | } |
||
| 55 |