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 | * Group a collection by an Eloquent model. |
||
9 | * |
||
10 | * @param string|callable $callback |
||
11 | * @param bool $preserveKeys |
||
12 | * @param mixed $modelKey |
||
13 | * @param mixed $itemsKey |
||
14 | * |
||
15 | * @mixin \Illuminate\Support\Collection |
||
16 | * |
||
17 | * @return \Illuminate\Support\Collection |
||
18 | */ |
||
19 | class GroupByModel |
||
20 | { |
||
21 | public function __invoke() |
||
22 | { |
||
23 | return function ($callback, bool $preserveKeys = false, $modelKey = 0, $itemsKey = 1): Collection { |
||
24 | $callback = $this->valueRetriever($callback); |
||
25 | |||
26 | return $this->groupBy(function ($item) use ($callback) { |
||
0 ignored issues
–
show
|
|||
27 | return $callback($item)->getKey(); |
||
28 | }, $preserveKeys)->map(function (Collection $items) use ($callback, $modelKey, $itemsKey) { |
||
29 | return [ |
||
30 | $modelKey => $callback($items->first()), |
||
31 | $itemsKey => $items, |
||
32 | ]; |
||
33 | })->values(); |
||
34 | }; |
||
35 | } |
||
36 | } |
||
37 |
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.