@@ -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 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $result = []; |
| 31 | 31 | $map = []; |
| 32 | 32 | |
| 33 | - foreach($collection as $item) { |
|
| 33 | + foreach ($collection as $item) { |
|
| 34 | 34 | $map[MapAccess::get($item, $idField)] = static::wrapItem( |
| 35 | 35 | $item, |
| 36 | 36 | $childrenContainerField, |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - foreach($map as &$item) { |
|
| 42 | - if(($parentId = static::getParentId($item, $parentIdField, $itemContainerField)) !== null) { |
|
| 41 | + foreach ($map as &$item) { |
|
| 42 | + if (($parentId = static::getParentId($item, $parentIdField, $itemContainerField)) !== null) { |
|
| 43 | 43 | $childrenContainer = &static::getChildrenContainer($map[$parentId], $childrenContainerField); |
| 44 | 44 | $childrenContainer[] = &$item; |
| 45 | 45 | } else { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** @var scalar|null $parentId */ |
| 65 | 65 | $parentId = MapAccess::get($item, $parentIdField); |
| 66 | 66 | |
| 67 | - if($parentId !== null) { |
|
| 67 | + if ($parentId !== null) { |
|
| 68 | 68 | return $parentId; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | protected static function &getChildrenContainer(&$item, string $childrenContainerField): array |
| 83 | 83 | { |
| 84 | - if(is_array($item)) { |
|
| 84 | + if (is_array($item)) { |
|
| 85 | 85 | return $item[$childrenContainerField]; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | protected static function wrapItem($item, string $childrenContainerField, string $itemContainerField) |
| 101 | 101 | { |
| 102 | - if(is_array($item)) { |
|
| 102 | + if (is_array($item)) { |
|
| 103 | 103 | $item[$childrenContainerField] = []; |
| 104 | 104 | return $item; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - if($item instanceof stdClass) { |
|
| 107 | + if ($item instanceof stdClass) { |
|
| 108 | 108 | $item->{$childrenContainerField} = []; |
| 109 | 109 | return $item; |
| 110 | 110 | } |