Completed
Pull Request — master (#156)
by Lucas
02:51
created

EachCons::eachCons()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 4
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
class EachCons
8
{
9
    /**
10
     * Get the consecutive values in the collection defined by the given chunk size.
11
     *
12
     * @param int $chunkSize
0 ignored issues
show
Bug introduced by
There is no parameter named $chunkSize. 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
     *
15
     * @return \Illuminate\Support\Collection
16
     */
17
    public function eachCons()
18
    {
19
        return function (int $chunkSize, bool $preserveKeys = false): Collection {
20
            $size = $this->count() - $chunkSize + 1;
0 ignored issues
show
Bug introduced by
The method count() does not seem to exist on object<Spatie\CollectionMacros\Macros\EachCons>.

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...
21
            $result = collect(range(0, $size))->reduce(function ($result, $index) use ($chunkSize, $preserveKeys) {
22
                $next = $this->slice($index, $chunkSize);
0 ignored issues
show
Bug introduced by
The method slice() does not seem to exist on object<Spatie\CollectionMacros\Macros\EachCons>.

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 $next->count() === $chunkSize ? $result->push($preserveKeys ? $next : $next->values()) : $result;
25
            }, new static([]));
0 ignored issues
show
Unused Code introduced by
The call to EachCons::__construct() has too many arguments starting with array().

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 @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
26
27
            return $preserveKeys ? $result : $result->values();
28
        };
29
    }
30
}
31