1 | <?php |
||
29 | class DelegateStrategy implements MultiStrategy |
||
30 | { |
||
31 | /** |
||
32 | * @var SplFixedArray<\Caridea\Acl\Loader> The loaders to consult |
||
33 | */ |
||
34 | private $loaders; |
||
35 | |||
36 | /** |
||
37 | * Creates a new DelegateStrategy. |
||
38 | * |
||
39 | * @param \Caridea\Acl\Loader[] $loaders An array of Loaders to use |
||
40 | * @throws \InvalidArgumentException if an entry in `loaders` isn't a `Loader` |
||
41 | */ |
||
42 | 6 | public function __construct(array $loaders) |
|
53 | |||
54 | /** |
||
55 | * Loads the ACL for a Target. |
||
56 | * |
||
57 | * @param \Caridea\Acl\Target $target The `Target` whose ACL will be loaded |
||
58 | * @param \Caridea\Acl\Subject[] $subjects An array of `Subject`s |
||
59 | * @param \Caridea\Acl\Service $service The calling service (to load parent ACLs) |
||
60 | * @return \Caridea\Acl\Acl The loaded ACL |
||
61 | * @throws \Caridea\Acl\Exception\Unloadable If the target provided is invalid |
||
62 | */ |
||
63 | 2 | public function load(Target $target, array $subjects, Service $service): Acl |
|
72 | |||
73 | /** |
||
74 | * Loads the ACLs for several Targets. |
||
75 | * |
||
76 | * @since 2.1.0 |
||
77 | * @param \Caridea\Acl\Target[] $targets The `Target` whose ACL will be loaded |
||
78 | * @param \Caridea\Acl\Subject[] $subjects An array of `Subject`s |
||
79 | * @param \Caridea\Acl\Service $service The ACL service (to load parent ACLs) |
||
80 | * @return array<string,\Caridea\Acl\Acl> The loaded ACLs |
||
81 | * @throws \Caridea\Acl\Exception\Unloadable If the target provided is invalid |
||
82 | * @throws \InvalidArgumentException If the `subjects` argument contains invalid values |
||
83 | */ |
||
84 | 3 | public function loadAll(array $targets, array $subjects, Service $service): array |
|
114 | } |
||
115 |
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: