| 1 | <?php |
||
| 10 | class EloquentUserTokenRepository extends EloquentBaseRepository implements UserTokenRepository |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Get all tokens for the given user |
||
| 14 | * @param int $userId |
||
| 15 | * @return \Illuminate\Database\Eloquent\Collection |
||
| 16 | */ |
||
| 17 | public function allForUser($userId) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param int $userId |
||
| 24 | * @return \Modules\User\Entities\UserToken |
||
| 25 | */ |
||
| 26 | public function generateFor($userId) |
||
| 37 | } |
||
| 38 |
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: