1 | <?php |
||
22 | class Router |
||
23 | { |
||
24 | |||
25 | private $route; |
||
26 | private $route_class; |
||
27 | private $secret_key; |
||
28 | private $use_guzzle=false; |
||
29 | |||
30 | const ID_KEY = 'id'; |
||
31 | const PAYSTACK_API_ROOT = 'https://api.paystack.co'; |
||
32 | const HEADER_KEY = 'header'; |
||
33 | const BODY_KEY = 'body'; |
||
34 | |||
35 | /** |
||
36 | * moveArgsToSentargs |
||
37 | * Insert description here |
||
38 | * |
||
39 | * @param $interface |
||
40 | * @param $payload |
||
41 | * @param $sentargs |
||
42 | * |
||
43 | * @return |
||
44 | * |
||
45 | * @access |
||
46 | * @static |
||
47 | * @see |
||
48 | * @since |
||
49 | */ |
||
50 | private function moveArgsToSentargs( |
||
51 | $interface, |
||
52 | &$payload, |
||
53 | &$sentargs |
||
54 | ) { |
||
55 | |||
56 | |||
57 | |||
58 | // check if interface supports args |
||
59 | if (array_key_exists(RouteInterface:: ARGS_KEY, $interface)) { |
||
60 | // to allow args to be specified in the payload, filter them out and put them in sentargs |
||
61 | $sentargs = (!$sentargs) ? [ ] : $sentargs; // Make sure $sentargs is not null |
||
62 | $args = $interface[RouteInterface::ARGS_KEY]; |
||
63 | while (list($key, $value) = each($payload)) { |
||
64 | // check that a value was specified |
||
65 | // with a key that was expected as an arg |
||
66 | if (in_array($key, $args)) { |
||
67 | $sentargs[$key] = $value; |
||
68 | unset($payload[$key]); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * putArgsIntoEndpoint |
||
76 | * Insert description here |
||
77 | * |
||
78 | * @param $endpoint |
||
79 | * @param $sentargs |
||
80 | * |
||
81 | * @return |
||
82 | * |
||
83 | * @access |
||
84 | * @static |
||
85 | * @see |
||
86 | * @since |
||
87 | */ |
||
88 | private function putArgsIntoEndpoint(&$endpoint, $sentargs) |
||
95 | |||
96 | /** |
||
97 | * callViaCurl |
||
98 | * Insert description here |
||
99 | * |
||
100 | * @param $interface |
||
101 | * @param $payload |
||
102 | * @param $sentargs |
||
103 | * |
||
104 | * @return |
||
105 | * |
||
106 | * @access |
||
107 | * @static |
||
108 | * @see |
||
109 | * @since |
||
110 | */ |
||
111 | private function callViaCurl($interface, $payload = [ ], $sentargs = [ ]) |
||
178 | |||
179 | private function headersFromLines($lines) |
||
180 | { |
||
181 | $headers = []; |
||
182 | foreach ($lines as $line) { |
||
183 | $parts = explode(':', $line, 2); |
||
184 | $headers[trim($parts[0])][] = isset($parts[1]) |
||
185 | ? trim($parts[1]) |
||
186 | : null; |
||
187 | } |
||
188 | return $headers; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * __call |
||
193 | * Insert description here |
||
194 | * |
||
195 | * @param $methd |
||
196 | * @param $sentargs |
||
197 | * |
||
198 | * @return |
||
199 | * |
||
200 | * @access |
||
201 | * @static |
||
202 | * @see |
||
203 | * @since |
||
204 | */ |
||
205 | public function __call($methd, $sentargs) |
||
215 | |||
216 | /** |
||
217 | * __construct |
||
218 | * Insert description here |
||
219 | * |
||
220 | * @param $route |
||
221 | * @param $secret_key |
||
222 | * |
||
223 | * @return |
||
224 | * |
||
225 | * @access |
||
226 | * @static |
||
227 | * @see |
||
228 | * @since |
||
229 | */ |
||
230 | public function __construct($route, $paystackObj) |
||
270 | } |
||
271 |
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: