1 | <?php |
||
10 | class TwoChanDriver extends AbstractDriver |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $encoding = 'Shift_JIS'; |
||
16 | |||
17 | /** |
||
18 | * get threads. |
||
19 | * |
||
20 | * @return \Illuminate\Support\Collection |
||
21 | * @throws MonarException |
||
22 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
23 | */ |
||
24 | public function threads(): Collection |
||
30 | |||
31 | /** |
||
32 | * get messages. |
||
33 | * |
||
34 | * @param int|null $start |
||
35 | * @param int|null $end |
||
36 | * |
||
37 | * @return \Illuminate\Support\Collection |
||
38 | * @throws MonarException |
||
39 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
40 | */ |
||
41 | public function messages(?int $start = null, ?int $end = null): Collection |
||
47 | |||
48 | /** |
||
49 | * post message. |
||
50 | * |
||
51 | * @param string $name |
||
52 | * @param string $email |
||
53 | * @param string|null $text |
||
54 | * |
||
55 | * @return string |
||
56 | * @throws MonarException |
||
57 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
58 | */ |
||
59 | public function post(string $name = '', string $email = 'sage', ?string $text = null): string |
||
99 | |||
100 | /** |
||
101 | * parse url. |
||
102 | * |
||
103 | * @return void |
||
104 | */ |
||
105 | protected function parse(): void |
||
121 | |||
122 | /** |
||
123 | * parse dat collection. |
||
124 | * |
||
125 | * @param string $body |
||
126 | * |
||
127 | * @return \Illuminate\Support\Collection |
||
128 | */ |
||
129 | protected function parseDatCollection(string $body, ?int $start = null, ?int $end = null): Collection |
||
166 | |||
167 | /** |
||
168 | * parse threads collection. |
||
169 | * |
||
170 | * @param string $body |
||
171 | * |
||
172 | * @return \Illuminate\Support\Collection |
||
173 | */ |
||
174 | protected function parseThreadsCollection(string $body): Collection |
||
194 | |||
195 | /** |
||
196 | * build message url. |
||
197 | * |
||
198 | * @param int $start |
||
199 | * @param int|null $end |
||
200 | * |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function messagesUrl(?int $start = null, ?int $end = null): string |
||
207 | |||
208 | /** |
||
209 | * build thread url. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | protected function threadsUrl(): string |
||
217 | |||
218 | /** |
||
219 | * build post url. |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | protected function postUrl(): string |
||
227 | |||
228 | /** |
||
229 | * 書き込み確認かどうか. |
||
230 | * |
||
231 | * @param string $html |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | private function confirm(string $html): bool |
||
239 | |||
240 | /** |
||
241 | * @param string $html |
||
242 | * |
||
243 | * @return bool |
||
244 | */ |
||
245 | private function isError(string $html): bool |
||
249 | } |
||
250 |
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: