@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | $level = 0; |
48 | 48 | do { |
49 | 49 | $subLevelContainer = []; |
50 | - foreach($data as $datum) { |
|
51 | - if($childrenContainerKey !== null) { |
|
50 | + foreach ($data as $datum) { |
|
51 | + if ($childrenContainerKey !== null) { |
|
52 | 52 | yield $level => $datum; |
53 | 53 | $childrenContainer = MapAccess::get($datum, $childrenContainerKey); |
54 | 54 | } else { |
55 | - if(!is_iterable($datum)) { |
|
55 | + if (!is_iterable($datum)) { |
|
56 | 56 | yield $level => $datum; |
57 | 57 | } |
58 | 58 | $childrenContainer = $datum; |
59 | 59 | } |
60 | - if(is_iterable($childrenContainer)) { |
|
61 | - foreach($childrenContainer as $child) { |
|
60 | + if (is_iterable($childrenContainer)) { |
|
61 | + foreach ($childrenContainer as $child) { |
|
62 | 62 | $subLevelContainer[] = $child; |
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
66 | 66 | $data = $subLevelContainer; |
67 | 67 | ++$level; |
68 | - } while(count($subLevelContainer)); |
|
68 | + } while (count($subLevelContainer)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -83,18 +83,18 @@ discard block |
||
83 | 83 | int $initialLevel = 0 |
84 | 84 | ): Generator { |
85 | 85 | $level = $initialLevel; |
86 | - foreach($data as $datum) { |
|
87 | - if($childrenContainerKey !== null) { |
|
86 | + foreach ($data as $datum) { |
|
87 | + if ($childrenContainerKey !== null) { |
|
88 | 88 | yield $level => $datum; |
89 | 89 | $childrenContainer = MapAccess::get($datum, $childrenContainerKey); |
90 | 90 | } else { |
91 | - if(!is_iterable($datum)) { |
|
91 | + if (!is_iterable($datum)) { |
|
92 | 92 | yield $level => $datum; |
93 | 93 | } |
94 | 94 | $childrenContainer = $datum; |
95 | 95 | } |
96 | - if(is_iterable($childrenContainer)) { |
|
97 | - yield from static::traverseDepthFirstRecursive($childrenContainer, $childrenContainerKey, $level + 1); |
|
96 | + if (is_iterable($childrenContainer)) { |
|
97 | + yield from static::traverseDepthFirstRecursive($childrenContainer, $childrenContainerKey, $level+1); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $result = []; |
30 | 30 | $map = []; |
31 | 31 | |
32 | - foreach($list as $item) { |
|
32 | + foreach ($list as $item) { |
|
33 | 33 | $map[MapAccess::get($item, $idField)] = static::wrapItem( |
34 | 34 | $item, |
35 | 35 | $childrenContainerField, |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | ); |
38 | 38 | } |
39 | 39 | |
40 | - foreach($map as &$item) { |
|
41 | - if(($parentId = static::getParentId($item, $parentIdField, $itemContainerField)) !== null) { |
|
40 | + foreach ($map as &$item) { |
|
41 | + if (($parentId = static::getParentId($item, $parentIdField, $itemContainerField)) !== null) { |
|
42 | 42 | $childrenContainer = &static::getChildrenContainer($map[$parentId], $childrenContainerField); |
43 | 43 | $childrenContainer[] = &$item; |
44 | 44 | } else { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** @var scalar|null $parentId */ |
62 | 62 | $parentId = MapAccess::get($item, $parentIdField); |
63 | 63 | |
64 | - if($parentId !== null) { |
|
64 | + if ($parentId !== null) { |
|
65 | 65 | return $parentId; |
66 | 66 | } |
67 | 67 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected static function &getChildrenContainer(&$item, string $childrenContainerField): array |
78 | 78 | { |
79 | - if(is_array($item)) { |
|
79 | + if (is_array($item)) { |
|
80 | 80 | return $item[$childrenContainerField]; |
81 | 81 | } |
82 | 82 | |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected static function wrapItem($item, string $childrenContainerField, string $itemContainerField) |
94 | 94 | { |
95 | - if(is_array($item)) { |
|
95 | + if (is_array($item)) { |
|
96 | 96 | $item[$childrenContainerField] = []; |
97 | 97 | return $item; |
98 | 98 | } |
99 | 99 | |
100 | - if($item instanceof stdClass) { |
|
100 | + if ($item instanceof stdClass) { |
|
101 | 101 | $item->{$childrenContainerField} = []; |
102 | 102 | return $item; |
103 | 103 | } |