These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\CollectionMacros\Macros; |
||
4 | |||
5 | use Illuminate\Support\Collection; |
||
6 | |||
7 | /* |
||
8 | * Slice a collection before a given callback is met into separate chunks |
||
9 | * |
||
10 | * @param callable $callback |
||
11 | * @param bool $preserveKeys |
||
12 | * |
||
13 | * @return \Illuminate\Support\Collection |
||
14 | */ |
||
15 | class SliceBefore |
||
16 | { |
||
17 | public function __invoke() |
||
18 | { |
||
19 | return function ($callback, bool $preserveKeys = false): Collection { |
||
20 | if ($this->isEmpty()) { |
||
0 ignored issues
–
show
|
|||
21 | return new static(); |
||
22 | } |
||
23 | |||
24 | if (! $preserveKeys) { |
||
25 | $sliced = new static([ |
||
0 ignored issues
–
show
The call to
SliceBefore::__construct() has too many arguments starting with array(new static(array($this->first()))) .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
26 | new static([$this->first()]), |
||
0 ignored issues
–
show
The method
first() does not seem to exist on object<Spatie\Collection...ros\Macros\SliceBefore> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The call to
SliceBefore::__construct() has too many arguments starting with array($this->first()) .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
27 | ]); |
||
28 | |||
29 | return $this->eachCons(2)->reduce(function ($sliced, $previousAndCurrent) use ($callback) { |
||
0 ignored issues
–
show
The method
eachCons() does not seem to exist on object<Spatie\Collection...ros\Macros\SliceBefore> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
30 | list($previousItem, $item) = $previousAndCurrent; |
||
31 | |||
32 | $callback($item, $previousItem) |
||
33 | ? $sliced->push(new static([$item])) |
||
0 ignored issues
–
show
The call to
SliceBefore::__construct() has too many arguments starting with array($item) .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
34 | : $sliced->last()->push($item); |
||
35 | |||
36 | return $sliced; |
||
37 | }, $sliced); |
||
38 | } |
||
39 | |||
40 | $sliced = new static([$this->take(1)]); |
||
0 ignored issues
–
show
The method
take() does not seem to exist on object<Spatie\Collection...ros\Macros\SliceBefore> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
The call to
SliceBefore::__construct() has too many arguments starting with array($this->take(1)) .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
41 | |||
42 | return $this->eachCons(2, $preserveKeys)->reduce(function ($sliced, $previousAndCurrent) use ($callback) { |
||
0 ignored issues
–
show
The method
eachCons() does not seem to exist on object<Spatie\Collection...ros\Macros\SliceBefore> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
43 | $previousItem = $previousAndCurrent->take(1); |
||
44 | $item = $previousAndCurrent->take(-1); |
||
45 | |||
46 | $itemKey = $item->keys()->first(); |
||
47 | $valuesItem = $item->first(); |
||
48 | $valuesPreviousItem = $previousItem->first(); |
||
49 | |||
50 | $callback($valuesItem, $valuesPreviousItem) |
||
51 | ? $sliced->push($item) |
||
52 | : $sliced->last()->put($itemKey, $valuesItem); |
||
53 | |||
54 | return $sliced; |
||
55 | }, $sliced); |
||
56 | }; |
||
57 | } |
||
58 | } |
||
59 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.