Rotate::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 3
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Rotate the items in the collection with given offset.
9
 *
10
 * @param int $offset
11
 *
12
 * @mixin \Illuminate\Support\Collection
13
 *
14
 * @return \Illuminate\Support\Collection
15
 */
16
class Rotate
17
{
18
    public function __invoke()
19
    {
20
        return function (int $offset): Collection {
21
            if ($this->isEmpty()) {
0 ignored issues
show
Bug introduced by Lucas Michot
The method isEmpty() does not seem to exist on object<Spatie\CollectionMacros\Macros\Rotate>.

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...
22
                return new static;
23
            }
24
25
            $count = $this->count();
0 ignored issues
show
Bug introduced by Lucas Michot
The method count() does not seem to exist on object<Spatie\CollectionMacros\Macros\Rotate>.

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...
26
27
            $offset %= $count;
28
29
            if ($offset < 0) {
30
                $offset += $count;
31
            }
32
33
            return new static($this->slice($offset)->merge($this->take($offset)));
0 ignored issues
show
Bug introduced by Lucas Michot
The method slice() does not seem to exist on object<Spatie\CollectionMacros\Macros\Rotate>.

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...
Bug introduced by Lucas Michot
The method take() does not seem to exist on object<Spatie\CollectionMacros\Macros\Rotate>.

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...
Unused Code introduced by Lucas Michot
The call to Rotate::__construct() has too many arguments starting with $this->slice($offset)->m...e($this->take($offset)).

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...
34
        };
35
    }
36
}
37