1 | <?php |
||
62 | class ParseNetInterface |
||
63 | { |
||
64 | /** |
||
65 | * parse a single network interface from the output of the Linux 'ip' |
||
66 | * command |
||
67 | * |
||
68 | * @param mixed $output |
||
69 | * the command output to parse |
||
70 | * @return NetInterface |
||
71 | * the network interface definition obtained from the command |
||
72 | * output |
||
73 | */ |
||
74 | public function __invoke($output) |
||
78 | |||
79 | /** |
||
80 | * parse a single network interface from the output of the Linux 'ip' |
||
81 | * command |
||
82 | * |
||
83 | * @param mixed $output |
||
84 | * the command output to parse |
||
85 | * @return NetInterface |
||
86 | * the network interface definition obtained from the command |
||
87 | * output |
||
88 | */ |
||
89 | public static function from($output) |
||
94 | |||
95 | /** |
||
96 | * parse a single network interface from the output of the Linux 'ip' |
||
97 | * command |
||
98 | * |
||
99 | * @param mixed $output |
||
100 | * the command output to parse |
||
101 | * @return NetInterface |
||
102 | * the network interface definition obtained from the command |
||
103 | * output |
||
104 | */ |
||
105 | private static function fromTraversable($output) |
||
123 | |||
124 | /** |
||
125 | * take the output from 'ip addr show <interface>' and break it up into |
||
126 | * the individual groups that we can parse |
||
127 | * |
||
128 | * @param array $lines |
||
129 | * the output to break up |
||
130 | * @return array |
||
131 | * the grouped output |
||
132 | */ |
||
133 | private static function breakupOutput($lines) |
||
191 | |||
192 | /** |
||
193 | * convert the isolated lines of text for inet (IPv4) addresses into a |
||
194 | * list of InetAddress objects |
||
195 | * |
||
196 | * @param array $inets |
||
197 | * the 'ip addr' lines for the inet addresses |
||
198 | * @return array<InetAddress> |
||
199 | * a list of InetAddress entries |
||
200 | */ |
||
201 | private static function convertToInetAddresses($inets) |
||
213 | |||
214 | /** |
||
215 | * convert the isolated lines of text for inet6 (IPv6) addresses into a |
||
216 | * list of Inet6Address objects |
||
217 | * |
||
218 | * @param array $inet6s |
||
219 | * the 'ip addr' lines for the inet6 addresses |
||
220 | * @return array<Inet6Address> |
||
221 | * a list of Inet6Address entries |
||
222 | */ |
||
223 | private static function convertToInet6Addresses($inet6s) |
||
235 | |||
236 | /** |
||
237 | * convert the isolated lines of text for the physical link into a |
||
238 | * single NetLink object |
||
239 | * |
||
240 | * @param array $lines |
||
241 | * the 'ip addr' lines for the physical link |
||
242 | * @return NetLink |
||
243 | * the value object extracted from the lines of output |
||
244 | */ |
||
245 | private static function convertToLink($lines) |
||
249 | |||
250 | /** |
||
251 | * parse a single network interface from the output of the Linux 'ip' |
||
252 | * command |
||
253 | * |
||
254 | * @param mixed $output |
||
255 | * the command output to parse |
||
256 | * @return NetInterface |
||
257 | * the network interface definition obtained from the command |
||
258 | * output |
||
259 | */ |
||
260 | private static function fromString($output) |
||
265 | |||
266 | /** |
||
267 | * called when we've been asked to parse a datatype that we do not support |
||
268 | * |
||
269 | * @param mixed $output |
||
270 | * the command output to parse |
||
271 | * @return void |
||
272 | * @throws E4xx_UnsupportedType |
||
273 | */ |
||
274 | private static function nothingMatchesTheInputType($output) |
||
278 | |||
279 | /** |
||
280 | * our map of how to handle each data type we are passed |
||
281 | * @var array |
||
282 | */ |
||
283 | private static $dispatchMap = [ |
||
284 | 'String' => 'fromString', |
||
285 | 'Traversable' => 'fromTraversable', |
||
286 | ]; |
||
287 | } |
||
288 |
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: