Completed
Push — master ( 785bde...8b4d11 )
by Freek
01:29
created

src/macros/after.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use Illuminate\Support\Collection;
4
5
/*
6
 * Get the next item from the collection.
7
 *
8
 * @param mixed $currentItem
9
 * @param mixed $fallback
10
 *
11
 * @return mixed
12
 */
13
Collection::macro('after', function ($currentItem, $fallback = null) {
14
    $currentKey = $this->search($currentItem, true);
0 ignored issues
show
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
15
16
    if ($currentKey === false) {
17
        return $fallback;
18
    }
19
20
    $currentOffset = $this->keys()->search($currentKey, true);
21
22
    $next = $this->slice($currentOffset, 2);
23
24
    if ($next->count() < 2) {
25
        return $fallback;
26
    }
27
28
    return $next->last();
29
});
30