| 1 | <?php |
||
| 17 | class Guard |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * return collection of (guard_name) property if exist on class or object |
||
| 21 | * otherwise will return collection of guards names that exists in config/auth.php. |
||
| 22 | * |
||
| 23 | * @param $model |
||
| 24 | * |
||
| 25 | * @return Collection |
||
| 26 | * @throws \ReflectionException |
||
| 27 | */ |
||
| 28 | 121 | public static function getNames($model) : Collection |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Return Default Guard name |
||
| 54 | * |
||
| 55 | * @param $class |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | * @throws \ReflectionException |
||
| 59 | */ |
||
| 60 | 121 | public static function getDefaultName($class): string |
|
| 65 | } |
||
| 66 |
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: