These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Illuminate\Support\Collection; |
||
4 | |||
5 | /* |
||
6 | * Get the consecutive values in the collection defined by the given chunk size. |
||
7 | * |
||
8 | * @param int $chunkSize |
||
9 | * @param bool $preserveKeys |
||
10 | * |
||
11 | * @return \Illuminate\Support\Collection |
||
12 | */ |
||
13 | Collection::macro('eachCons', function (int $chunkSize, bool $preserveKeys = false): Collection { |
||
14 | $size = $this->count() - $chunkSize + 1; |
||
0 ignored issues
–
show
|
|||
15 | $result = collect(range(0, $size))->reduce(function ($result, $index) use ($chunkSize, $preserveKeys) { |
||
16 | $next = $this->slice($index, $chunkSize); |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | return $next->count() === $chunkSize ? $result->push($preserveKeys ? $next : $next->values()) : $result; |
||
19 | }, new static([])); |
||
20 | |||
21 | return $preserveKeys ? $result : $result->values(); |
||
22 | }); |
||
23 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.