| 1 | <?php |
||
| 16 | class FindUserAction extends Action |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \App\Containers\User\Services\FindUserService |
||
| 21 | */ |
||
| 22 | private $findUserService; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * FindUserByIdAction constructor. |
||
| 26 | * |
||
| 27 | * @param \App\Containers\User\Services\FindUserService $findUserService |
||
| 28 | */ |
||
| 29 | public function __construct( |
||
| 34 | |||
| 35 | |||
| 36 | /** |
||
| 37 | * @param $id |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function run($id) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param $userId |
||
| 54 | * @param $visitorId |
||
| 55 | * @param $token |
||
| 56 | * |
||
| 57 | * @return mixed |
||
| 58 | */ |
||
| 59 | public function byEverything($userId, $visitorId, $token) |
||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | } |
||
| 75 |
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: