1 | <?php |
||
15 | class Parser |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $whitespace = " \r\n\t"; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $mappers = []; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $languages = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $nicknameDelimiters = []; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $maxSalutationIndex = 0; |
||
41 | |||
42 | public function __construct(array $languages = []) |
||
50 | |||
51 | /** |
||
52 | * split full names into the following parts: |
||
53 | * - prefix / salutation (Mr., Mrs., etc) |
||
54 | * - given name / first name |
||
55 | * - middle initials |
||
56 | * - surname / last name |
||
57 | * - suffix (II, Phd, Jr, etc) |
||
58 | * |
||
59 | * @param string $name |
||
60 | * @return Name |
||
61 | */ |
||
62 | public function parse($name): Name |
||
80 | |||
81 | /** |
||
82 | * handles split-parsing of comma-separated name parts |
||
83 | * |
||
84 | * @param $left - the name part left of the comma |
||
85 | * @param $right - the name part right of the comma |
||
86 | * |
||
87 | * @return Name |
||
88 | */ |
||
89 | protected function parseSplitName($first, $second, $third): Name |
||
99 | |||
100 | /** |
||
101 | * @return Parser |
||
102 | */ |
||
103 | protected function getFirstSegmentParser(): Parser |
||
117 | |||
118 | /** |
||
119 | * @return Parser |
||
120 | */ |
||
121 | protected function getSecondSegmentParser(): Parser |
||
137 | |||
138 | protected function getThirdSegmentParser(): Parser |
||
148 | |||
149 | /** |
||
150 | * get the mappers for this parser |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | public function getMappers(): array |
||
171 | |||
172 | /** |
||
173 | * set the mappers for this parser |
||
174 | * |
||
175 | * @param array $mappers |
||
176 | * @return Parser |
||
177 | */ |
||
178 | public function setMappers(array $mappers): Parser |
||
184 | |||
185 | /** |
||
186 | * normalize the name |
||
187 | * |
||
188 | * @param string $name |
||
189 | * @return string |
||
190 | */ |
||
191 | protected function normalize(string $name): string |
||
199 | |||
200 | /** |
||
201 | * get a string of characters that are supposed to be treated as whitespace |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getWhitespace(): string |
||
209 | |||
210 | /** |
||
211 | * set the string of characters that are supposed to be treated as whitespace |
||
212 | * |
||
213 | * @param $whitespace |
||
214 | * @return Parser |
||
215 | */ |
||
216 | public function setWhitespace($whitespace): Parser |
||
222 | |||
223 | /** |
||
224 | * @return array |
||
225 | */ |
||
226 | protected function getPrefixes() |
||
237 | |||
238 | /** |
||
239 | * @return array |
||
240 | */ |
||
241 | protected function getSuffixes() |
||
252 | |||
253 | /** |
||
254 | * @return array |
||
255 | */ |
||
256 | protected function getSalutations() |
||
267 | |||
268 | protected function initialsAllowed() |
||
274 | |||
275 | /** |
||
276 | * @return array |
||
277 | */ |
||
278 | public function getNicknameDelimiters(): array |
||
282 | |||
283 | /** |
||
284 | * @param array $nicknameDelimiters |
||
285 | * @return Parser |
||
286 | */ |
||
287 | public function setNicknameDelimiters(array $nicknameDelimiters): Parser |
||
293 | |||
294 | /** |
||
295 | * @return int |
||
296 | */ |
||
297 | public function getMaxSalutationIndex(): int |
||
301 | |||
302 | /** |
||
303 | * @param int $maxSalutationIndex |
||
304 | * @return Parser |
||
305 | */ |
||
306 | public function setMaxSalutationIndex(int $maxSalutationIndex): Parser |
||
312 | } |
||
313 |
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: