Completed
Pull Request — master (#155)
by
unknown
01:37
created

AfterMacro::after()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\MacroClasses;
4
5
class AfterMacro
6
{
7
    /**
8
     * Get the next item from the collection.
9
     *
10
     * @return \Closure
11
     */
12
    public function after()
13
    {
14
        return function ($currentItem, $fallback = null) {
15
            $currentKey = $this->search($currentItem, true);
0 ignored issues
show
Bug introduced by
The method search() does not seem to exist on object<Spatie\Collection...acroClasses\AfterMacro>.

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...
16
17
            if ($currentKey === false) {
18
                return $fallback;
19
            }
20
21
            $currentOffset = $this->keys()->search($currentKey, true);
0 ignored issues
show
Bug introduced by
The method keys() does not seem to exist on object<Spatie\Collection...acroClasses\AfterMacro>.

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
23
            $next = $this->slice($currentOffset, 2);
0 ignored issues
show
Bug introduced by
The method slice() does not seem to exist on object<Spatie\Collection...acroClasses\AfterMacro>.

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...
24
25
            if ($next->count() < 2) {
26
                return $fallback;
27
            }
28
29
            return $next->last();
30
        };
31
    }
32
}
33