1 | <?php |
||
11 | class Transform implements Processor |
||
12 | { |
||
13 | use Processor\Implementation; |
||
14 | |||
15 | /** |
||
16 | * Default transformation functions |
||
17 | * @var array |
||
18 | */ |
||
19 | public static $defaultFunctions = [ |
||
20 | 'hash' => 'hash', |
||
21 | 'hash_hmac' => 'hash_hmac', |
||
22 | 'base64_encode' => 'base64_encode', |
||
23 | 'base64_decode' => 'base64_decode', |
||
24 | 'json_encode' => 'json_encode', |
||
25 | 'json_decode' => 'json_decode', |
||
26 | 'serialize' => 'serialize', |
||
27 | 'unserialize' => 'unserialize', |
||
28 | 'strtotime' => 'strtotime', |
||
29 | 'date' => 'date' |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Allowed transformation functions |
||
34 | * @var array |
||
35 | */ |
||
36 | public $functions; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Class constructor |
||
41 | * |
||
42 | * @param string $property Property key with the processing instruction |
||
43 | */ |
||
44 | 12 | public function __construct($property) |
|
49 | |||
50 | /** |
||
51 | * Apply processing to a single node |
||
52 | * |
||
53 | * @param Node $node |
||
54 | */ |
||
55 | 8 | public function applyToNode(Node $node) |
|
98 | |||
99 | /** |
||
100 | * Resolve instructions of nodes by getting their results |
||
101 | * |
||
102 | * @param Node $node |
||
103 | * |
||
104 | * @return mixed $result |
||
105 | */ |
||
106 | 7 | protected function resolveNodes($node) { |
|
113 | } |
||
114 |
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: