| 1 | <?php |
||
| 11 | class Guard |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * return collection of (guard_name) property if exist on class or object |
||
| 15 | * otherwise will return collection of guards names that exists in config/auth.php. |
||
| 16 | * |
||
| 17 | * @param $model |
||
| 18 | * |
||
| 19 | * @return Collection |
||
| 20 | * @throws \ReflectionException |
||
| 21 | */ |
||
| 22 | public function getNames($model) : Collection |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Return Default Guard name |
||
| 51 | * |
||
| 52 | * @param $class |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | * @throws \ReflectionException |
||
| 56 | */ |
||
| 57 | public function getDefaultName($class): string |
||
| 62 | } |
||
| 63 |
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: