| 1 | <?php namespace Modules\User\Repositories\Eloquent; |
||
| 8 | class EloquentUserTokenRepository extends EloquentBaseRepository implements UserTokenRepository |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Get all tokens for the given user |
||
| 12 | * @param int $userId |
||
| 13 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 14 | */ |
||
| 15 | public function allForUser($userId) |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param int $userId |
||
| 22 | * @return \Modules\User\Entities\UserToken |
||
| 23 | */ |
||
| 24 | public function generateFor($userId) |
||
| 35 | } |
||
| 36 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: