Completed
Pull Request — master (#156)
by Lucas
03:54 queued 01:43
created

GroupByModel::groupByModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
class GroupByModel
8
{
9
    /**
10
     * Group a collection by an Eloquent model.
11
     *
12
     * @param string|callable $callback
0 ignored issues
show
Bug introduced by
There is no parameter named $callback. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
13
     * @param bool $preserveKeys
0 ignored issues
show
Bug introduced by
There is no parameter named $preserveKeys. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
14
     * @param mixed $modelKey
0 ignored issues
show
Bug introduced by
There is no parameter named $modelKey. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
15
     * @param mixed $itemsKey
0 ignored issues
show
Bug introduced by
There is no parameter named $itemsKey. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
16
     *
17
     * @return \Illuminate\Support\Collection
18
     */
19
    public function groupByModel()
20
    {
21
        return function ($callback, bool $preserveKeys = false, $modelKey = 0, $itemsKey = 1): Collection {
22
            $callback = $this->valueRetriever($callback);
0 ignored issues
show
Bug introduced by
The method valueRetriever() does not seem to exist on object<Spatie\Collection...os\Macros\GroupByModel>.

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...
23
24
            return $this->groupBy(function ($item) use ($callback) {
0 ignored issues
show
Bug introduced by
The method groupBy() does not exist on Spatie\CollectionMacros\Macros\GroupByModel. Did you maybe mean groupByModel()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
                return $callback($item)->getKey();
26
            }, $preserveKeys)->map(function (Collection $items) use ($callback, $modelKey, $itemsKey) {
27
                return [
28
                    $modelKey => $callback($items->first()),
29
                    $itemsKey => $items,
30
                ];
31
            })->values();
32
        };
33
    }
34
}
35