| 1 | <?php |
||
| 14 | class FindUserByAnythingAction extends Action |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var \App\Containers\User\Services\FindUserService |
||
| 19 | */ |
||
| 20 | private $findUserService; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * FindUserByAnythingAction constructor. |
||
| 24 | * |
||
| 25 | * @param \App\Containers\User\Services\FindUserService $findUserService |
||
| 26 | */ |
||
| 27 | public function __construct( |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param $userId |
||
| 35 | * @param $visitorId |
||
| 36 | * @param $token |
||
| 37 | * |
||
| 38 | * @return mixed |
||
| 39 | */ |
||
| 40 | public function run($userId, $visitorId, $token) |
||
| 56 | |||
| 57 | } |
||
| 58 |
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: