Conditions | 2 |
Paths | 3 |
Total Lines | 11 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php namespace Modules\User\Repositories\Eloquent; |
||
24 | public function generateFor($userId) |
||
25 | { |
||
26 | try { |
||
27 | $uuid4 = Uuid::uuid4(); |
||
28 | $userToken = $this->model->create(['user_id' => $userId, 'access_token' => $uuid4]); |
||
29 | } catch (QueryException $e) { |
||
30 | $this->generateFor($userId); |
||
31 | } |
||
32 | |||
33 | return $userToken; |
||
|
|||
34 | } |
||
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: