1 | <?php |
||
8 | class Guard |
||
9 | { |
||
10 | /** |
||
11 | * Return a collection of guard names suitable for the $model |
||
12 | * |
||
13 | * @param string|Model $model model class object or name |
||
14 | * @return Collection |
||
15 | */ |
||
16 | public static function getNames($model): Collection |
||
34 | |||
35 | /** |
||
36 | * Get list of relevant guards for the $class model based on config(auth) settings |
||
37 | * |
||
38 | * Lookup flow: |
||
39 | * - get names of models for guards defined in auth.guards where a provider is set |
||
40 | * - filter for provider models matching the model $class being checked |
||
41 | * - keys() gives just the names of the matched guards |
||
42 | * - if logged in, filter out any guards for which the user does not pass the auth->guard->check() test |
||
43 | * - return collection of guard names |
||
44 | * |
||
45 | * @param string $class |
||
46 | * @return Collection |
||
47 | */ |
||
48 | protected static function getConfigAuthGuards(string $class): Collection |
||
66 | |||
67 | /** |
||
68 | * Lookup a guard name relevant for the $class model and the current user |
||
69 | * |
||
70 | * @param string|Model $class model class object or name |
||
71 | * @return string guard name |
||
72 | */ |
||
73 | public static function getDefaultName($class): string |
||
79 | } |
||
80 |
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: