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 | use Spatie\CollectionMacros\Exceptions\CollectionItemNotFound; |
||
5 | |||
6 | /* |
||
7 | * Get the first item. Throws Exception when collection is empty. |
||
8 | * |
||
9 | * @return mixed |
||
10 | */ |
||
11 | Collection::macro('firstOrFail', function () { |
||
12 | if (! is_null($item = $this->first())) { |
||
0 ignored issues
–
show
|
|||
13 | return $item; |
||
14 | } |
||
15 | |||
16 | throw new CollectionItemNotFound('No items found in collection.'); |
||
17 | }); |
||
18 |
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.