1 | <?php |
||
23 | class BlockDirective extends Directive implements DirectiveInterface |
||
24 | { |
||
25 | /** @var array orderd list of sub directives */ |
||
26 | private $directives = []; |
||
27 | |||
28 | /** |
||
29 | * Adds a Directive at the end of the list. |
||
30 | * |
||
31 | * @param DirectiveInterface $directive a directive to add |
||
32 | */ |
||
33 | 9 | public function add(DirectiveInterface $directive) |
|
39 | |||
40 | /** |
||
41 | * Confirms if the directive contains a specified directive. |
||
42 | * |
||
43 | * @param string $name the directive for which to check existence |
||
44 | * |
||
45 | * @return bool true if the sub-directive exists, false otherwise |
||
46 | */ |
||
47 | 1 | public function hasDirective($name) |
|
61 | |||
62 | /** |
||
63 | * Looks into sub directives to confirm if the actual contains a specified directive. |
||
64 | * |
||
65 | * @param string $name the directive for which to check existence |
||
66 | * @param bool $inSubDirective the actual state |
||
67 | * @param DirectiveInterface $directive the sub directive to look into |
||
68 | * |
||
69 | * @return bool true if the sub-directive exists, false otherwise |
||
70 | */ |
||
71 | 1 | private function hasInnerDirective($name, $inSubDirective, DirectiveInterface $directive) |
|
79 | |||
80 | /** |
||
81 | * Confirms if the directive is simple. |
||
82 | * |
||
83 | * Block directive can have sub directives |
||
84 | * |
||
85 | * @return bool true if the directive is simple, false otherwise |
||
86 | */ |
||
87 | 1 | public function isSimple() |
|
91 | |||
92 | /** |
||
93 | * Dumps the directive respecting a server syntax. |
||
94 | * |
||
95 | * @param ServerInterface $server a server instance |
||
96 | * @param int $spaces the indentation spaces |
||
97 | * |
||
98 | * @return string the dumped directive |
||
99 | */ |
||
100 | 1 | public function dump(ServerInterface $server, $spaces = 0) |
|
127 | |||
128 | /** |
||
129 | * Confirms if a Block directive is a 'main' context. |
||
130 | * |
||
131 | * @return bool true if the name of the block directive is 'main', false otherwise |
||
132 | */ |
||
133 | 1 | private function isMainContext() |
|
137 | } |
||
138 |
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: