Total Complexity | 79 |
Total Lines | 423 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Complex classes like AbstractExceptionHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractExceptionHandler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | abstract class AbstractExceptionHandler |
||
38 | { |
||
39 | /** |
||
40 | * handle HTTP-Status-Codes of type 1xx |
||
41 | */ |
||
42 | public function handle100(): bool |
||
43 | { |
||
44 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
45 | } |
||
46 | |||
47 | public function handle101(): bool |
||
48 | { |
||
49 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
50 | } |
||
51 | |||
52 | public function handle102(): bool |
||
53 | { |
||
54 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * handle HTTP-Status-Codes of type 2xx |
||
59 | */ |
||
60 | public function handle200(): bool |
||
61 | { |
||
62 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
63 | } |
||
64 | |||
65 | public function handle201(): bool |
||
66 | { |
||
67 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
68 | } |
||
69 | |||
70 | public function handle202(): bool |
||
71 | { |
||
72 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
73 | } |
||
74 | |||
75 | public function handle203(): bool |
||
76 | { |
||
77 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
78 | } |
||
79 | |||
80 | public function handle204(): bool |
||
81 | { |
||
82 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
83 | } |
||
84 | |||
85 | public function handle205(): bool |
||
86 | { |
||
87 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
88 | } |
||
89 | |||
90 | public function handle206(): bool |
||
91 | { |
||
92 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
93 | } |
||
94 | |||
95 | public function handle207(): bool |
||
96 | { |
||
97 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
98 | } |
||
99 | |||
100 | public function handle208(): bool |
||
101 | { |
||
102 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
103 | } |
||
104 | |||
105 | public function handle226(): bool |
||
106 | { |
||
107 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * handle HTTP-Status-Codes of type 3xx |
||
112 | */ |
||
113 | public function handle300(): bool |
||
114 | { |
||
115 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
116 | } |
||
117 | |||
118 | public function handle301(): bool |
||
119 | { |
||
120 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
121 | } |
||
122 | |||
123 | public function handle302(): bool |
||
124 | { |
||
125 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
126 | } |
||
127 | |||
128 | public function handle303(): bool |
||
129 | { |
||
130 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
131 | } |
||
132 | |||
133 | public function handle304(): bool |
||
134 | { |
||
135 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
136 | } |
||
137 | |||
138 | public function handle305(): bool |
||
139 | { |
||
140 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
141 | } |
||
142 | |||
143 | public function handle306(): bool |
||
144 | { |
||
145 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
146 | } |
||
147 | |||
148 | public function handle307(): bool |
||
149 | { |
||
150 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
151 | } |
||
152 | |||
153 | public function handle308(): bool |
||
154 | { |
||
155 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * handle HTTP-Status-Codes of type 4xx |
||
160 | */ |
||
161 | public function handle400(): bool |
||
162 | { |
||
163 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
164 | } |
||
165 | |||
166 | public function handle401(): bool |
||
167 | { |
||
168 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
169 | } |
||
170 | |||
171 | public function handle402(): bool |
||
172 | { |
||
173 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
174 | } |
||
175 | |||
176 | public function handle403(): bool |
||
179 | } |
||
180 | |||
181 | public function handle404(): bool |
||
182 | { |
||
183 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
184 | } |
||
185 | |||
186 | public function handle405(): bool |
||
187 | { |
||
188 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
189 | } |
||
190 | |||
191 | public function handle406(): bool |
||
192 | { |
||
193 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
194 | } |
||
195 | |||
196 | public function handle407(): bool |
||
197 | { |
||
198 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
199 | } |
||
200 | |||
201 | public function handle408(): bool |
||
202 | { |
||
203 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
204 | } |
||
205 | |||
206 | public function handle409(): bool |
||
207 | { |
||
208 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
209 | } |
||
210 | |||
211 | public function handle410(): bool |
||
212 | { |
||
213 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
214 | } |
||
215 | |||
216 | public function handle411(): bool |
||
217 | { |
||
218 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
219 | } |
||
220 | |||
221 | public function handle412(): bool |
||
222 | { |
||
223 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
224 | } |
||
225 | |||
226 | public function handle413(): bool |
||
227 | { |
||
228 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
229 | } |
||
230 | |||
231 | public function handle414(): bool |
||
232 | { |
||
233 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
234 | } |
||
235 | |||
236 | public function handle415(): bool |
||
237 | { |
||
238 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
239 | } |
||
240 | |||
241 | public function handle416(): bool |
||
242 | { |
||
243 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
244 | } |
||
245 | |||
246 | public function handle417(): bool |
||
247 | { |
||
248 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
249 | } |
||
250 | |||
251 | public function handle418(): bool |
||
252 | { |
||
253 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
254 | } |
||
255 | |||
256 | public function handle420(): bool |
||
257 | { |
||
258 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
259 | } |
||
260 | |||
261 | public function handle421(): bool |
||
262 | { |
||
263 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
264 | } |
||
265 | |||
266 | public function handle422(): bool |
||
267 | { |
||
268 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
269 | } |
||
270 | |||
271 | public function handle423(): bool |
||
272 | { |
||
273 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
274 | } |
||
275 | |||
276 | public function handle424(): bool |
||
277 | { |
||
278 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
279 | } |
||
280 | |||
281 | public function handle425(): bool |
||
282 | { |
||
283 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
284 | } |
||
285 | |||
286 | public function handle426(): bool |
||
287 | { |
||
288 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
289 | } |
||
290 | |||
291 | public function handle428(): bool |
||
292 | { |
||
293 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
294 | } |
||
295 | |||
296 | public function handle429(): bool |
||
297 | { |
||
298 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
299 | } |
||
300 | |||
301 | public function handle430(): bool |
||
302 | { |
||
303 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
304 | } |
||
305 | |||
306 | public function handle431(): bool |
||
307 | { |
||
308 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
309 | } |
||
310 | |||
311 | public function handle444(): bool |
||
312 | { |
||
313 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
314 | } |
||
315 | |||
316 | public function handle449(): bool |
||
317 | { |
||
318 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
319 | } |
||
320 | |||
321 | public function handle451(): bool |
||
322 | { |
||
323 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * handle HTTP-Status-Codes of type 5xx |
||
328 | */ |
||
329 | public function handle500(): bool |
||
330 | { |
||
331 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
332 | } |
||
333 | |||
334 | public function handle501(): bool |
||
335 | { |
||
336 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
337 | } |
||
338 | |||
339 | public function handle502(): bool |
||
340 | { |
||
341 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
342 | } |
||
343 | |||
344 | public function handle503(): bool |
||
345 | { |
||
346 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
347 | } |
||
348 | |||
349 | public function handle504(): bool |
||
350 | { |
||
351 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
352 | } |
||
353 | |||
354 | public function handle505(): bool |
||
355 | { |
||
356 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
357 | } |
||
358 | |||
359 | public function handle506(): bool |
||
360 | { |
||
361 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
362 | } |
||
363 | |||
364 | public function handle507(): bool |
||
365 | { |
||
366 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
367 | } |
||
368 | |||
369 | public function handle508(): bool |
||
370 | { |
||
371 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
372 | } |
||
373 | |||
374 | public function handle509(): bool |
||
375 | { |
||
376 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
377 | } |
||
378 | |||
379 | public function handle510(): bool |
||
380 | { |
||
381 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * handle HTTP-Status-Codes of type 9xx |
||
386 | */ |
||
387 | public function handle900(): bool |
||
388 | { |
||
389 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
390 | } |
||
391 | |||
392 | public function handle901(): bool |
||
393 | { |
||
394 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
395 | } |
||
396 | |||
397 | public function handle902(): bool |
||
398 | { |
||
399 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
400 | } |
||
401 | |||
402 | public function handle903(): bool |
||
403 | { |
||
404 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
405 | } |
||
406 | |||
407 | public function handle904(): bool |
||
408 | { |
||
409 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
410 | } |
||
411 | |||
412 | public function handle905(): bool |
||
413 | { |
||
414 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
415 | } |
||
416 | |||
417 | public function handle906(): bool |
||
420 | } |
||
421 | |||
422 | public function handle907(): bool |
||
423 | { |
||
424 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
425 | } |
||
426 | |||
427 | public function handle950(): bool |
||
428 | { |
||
429 | return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler()); |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * This is the right place, where we can handle exceptions, which were thrown in REST-API's! |
||
434 | * |
||
435 | * The return value (boolean) describes, if restler should display an error as output: |
||
436 | * TRUE means: restler should NOT display an error as output (so, we must do that) |
||
437 | * FALSE means: restler should display an error as output |
||
438 | */ |
||
439 | abstract protected function handleException(RestException $exception, Restler $restler): bool; |
||
440 | |||
441 | /** |
||
442 | * This method must be protected - otherwise we can't test this class in unittests |
||
443 | */ |
||
444 | protected function getRestler(): Restler |
||
445 | { |
||
446 | return Scope::get('Restler'); |
||
447 | } |
||
448 | |||
449 | /** |
||
450 | * This method must be protected - otherwise we can't test this class in unittests |
||
451 | */ |
||
452 | protected function getRestlerException(array $exceptionHandlerArgs = []): RestException |
||
460 | } |
||
461 | } |
||
462 |