Passed
Push — main ( 63b0eb...e16704 )
by Felix
03:05
created

AbstractExceptionHandler   F

Complexity

Total Complexity 80

Size/Duplication

Total Lines 383
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 83
c 1
b 0
f 1
dl 0
loc 383
ccs 150
cts 160
cp 0.9375
rs 2
wmc 80

78 Methods

Rating   Name   Duplication   Size   Complexity  
A handle906() 0 3 1
A handle449() 0 3 1
A __construct() 0 3 1
A handle904() 0 3 1
A handle901() 0 3 1
A handle409() 0 3 1
A handle429() 0 3 1
A handle202() 0 3 1
A handle428() 0 3 1
A handle201() 0 3 1
A handle405() 0 3 1
A handle431() 0 3 1
A handle509() 0 3 1
A handle401() 0 3 1
A handle410() 0 3 1
A handle503() 0 3 1
A handle414() 0 3 1
A handle504() 0 3 1
A handle413() 0 3 1
A handle408() 0 3 1
A handle507() 0 3 1
A handle207() 0 3 1
A handle430() 0 3 1
A handle308() 0 3 1
A handle100() 0 3 1
A handle421() 0 3 1
A handle305() 0 3 1
A handle423() 0 3 1
A handle205() 0 3 1
A handle400() 0 3 1
A handle406() 0 3 1
A handle304() 0 3 1
A handle303() 0 3 1
A getRestlerException() 0 7 3
A handle950() 0 3 1
A handle416() 0 3 1
A handle102() 0 3 1
A handle905() 0 3 1
A handle420() 0 3 1
A handle203() 0 3 1
A handle302() 0 3 1
A handle451() 0 3 1
A handle902() 0 3 1
A handle508() 0 3 1
A handle417() 0 3 1
A handle206() 0 3 1
A handle425() 0 3 1
A handle501() 0 3 1
A handle424() 0 3 1
A handle510() 0 3 1
A handle412() 0 3 1
A handle903() 0 3 1
A handle101() 0 3 1
A handle418() 0 3 1
A handle226() 0 3 1
A handle301() 0 3 1
A handle506() 0 3 1
A handle505() 0 3 1
A handle502() 0 3 1
A handle402() 0 3 1
A handle204() 0 3 1
A handle208() 0 3 1
A handle403() 0 3 1
A handle404() 0 3 1
A handle900() 0 3 1
A handle300() 0 3 1
A handle407() 0 3 1
A handle415() 0 3 1
A handle500() 0 3 1
A handle426() 0 3 1
A handle306() 0 3 1
A handle444() 0 3 1
A handle907() 0 3 1
A getRestler() 0 3 1
A handle200() 0 3 1
A handle411() 0 3 1
A handle307() 0 3 1
A handle422() 0 3 1

How to fix   Complexity   

Complex Class

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
2
3
namespace Aoe\Restler\System\Restler;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2015 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use Aoe\Restler\Configuration\ExtensionConfiguration;
30
use Luracast\Restler\RestException;
31
use Luracast\Restler\Restler;
32
use Luracast\Restler\Scope;
33
34
/**
35
 * This abstract class can be used to call ONE central method,
36
 * which handles ALL exceptions (the current HTTP-Status-Code doesn't matter)!
37
 *
38
 * @package Restler
39
 */
40
abstract class AbstractExceptionHandler
41
{
42
    /**
43
     * This object can be used, to check the Extension-Configuration (maybe we want to
44
     * handle an exception in different ways - based on the Extension-Configuration)
45
     *
46
     * @var ExtensionConfiguration
47
     */
48
    protected $extensionConfiguration;
49
50
    /**
51
     * @param ExtensionConfiguration $extensionConfiguration
52
     */
53
    public function __construct(ExtensionConfiguration $extensionConfiguration)
54
    {
55
        $this->extensionConfiguration = $extensionConfiguration;
56
    }
57
58
59
    /**
60
     * handle HTTP-Status-Codes of type 1xx
61
     */
62 1
    public function handle100()
63
    {
64 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
65
    }
66 1
    public function handle101()
67
    {
68 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
69
    }
70 1
    public function handle102()
71
    {
72 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
73
    }
74
75
76
    /**
77
     * handle HTTP-Status-Codes of type 2xx
78
     */
79 1
    public function handle200()
80
    {
81 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
82
    }
83 1
    public function handle201()
84
    {
85 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
86
    }
87 1
    public function handle202()
88
    {
89 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
90
    }
91 1
    public function handle203()
92
    {
93 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
94
    }
95 1
    public function handle204()
96
    {
97 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
98
    }
99 1
    public function handle205()
100
    {
101 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
102
    }
103 1
    public function handle206()
104
    {
105 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
106
    }
107 1
    public function handle207()
108
    {
109 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
110
    }
111 1
    public function handle208()
112
    {
113 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
114
    }
115 1
    public function handle226()
116
    {
117 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
118
    }
119
120
121
    /**
122
     * handle HTTP-Status-Codes of type 3xx
123
     */
124 1
    public function handle300()
125
    {
126 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
127
    }
128 1
    public function handle301()
129
    {
130 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
131
    }
132 1
    public function handle302()
133
    {
134 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
135
    }
136 1
    public function handle303()
137
    {
138 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
139
    }
140 1
    public function handle304()
141
    {
142 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
143
    }
144 1
    public function handle305()
145
    {
146 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
147
    }
148 1
    public function handle306()
149
    {
150 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
151
    }
152 1
    public function handle307()
153
    {
154 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
155
    }
156 1
    public function handle308()
157
    {
158 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
159
    }
160
161
162
    /**
163
     * handle HTTP-Status-Codes of type 4xx
164
     */
165 1
    public function handle400()
166
    {
167 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
168
    }
169 1
    public function handle401()
170
    {
171 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
172
    }
173 1
    public function handle402()
174
    {
175 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
176
    }
177 1
    public function handle403()
178
    {
179 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
180
    }
181 1
    public function handle404()
182
    {
183 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
184
    }
185 1
    public function handle405()
186
    {
187 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
188
    }
189 1
    public function handle406()
190
    {
191 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
192
    }
193 1
    public function handle407()
194
    {
195 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
196
    }
197 1
    public function handle408()
198
    {
199 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
200
    }
201 1
    public function handle409()
202
    {
203 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
204
    }
205 1
    public function handle410()
206
    {
207 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
208
    }
209 1
    public function handle411()
210
    {
211 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
212
    }
213 1
    public function handle412()
214
    {
215 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
216
    }
217 1
    public function handle413()
218
    {
219 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
220
    }
221 1
    public function handle414()
222
    {
223 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
224
    }
225 1
    public function handle415()
226
    {
227 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
228
    }
229 1
    public function handle416()
230
    {
231 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
232
    }
233 1
    public function handle417()
234
    {
235 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
236
    }
237 1
    public function handle418()
238
    {
239 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
240
    }
241 1
    public function handle420()
242
    {
243 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
244
    }
245 1
    public function handle421()
246
    {
247 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
248
    }
249 1
    public function handle422()
250
    {
251 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
252
    }
253 1
    public function handle423()
254
    {
255 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
256
    }
257 1
    public function handle424()
258
    {
259 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
260
    }
261 1
    public function handle425()
262
    {
263 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
264
    }
265 1
    public function handle426()
266
    {
267 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
268
    }
269 1
    public function handle428()
270
    {
271 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
272
    }
273 1
    public function handle429()
274
    {
275 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
276
    }
277 1
    public function handle430()
278
    {
279 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
280
    }
281 1
    public function handle431()
282
    {
283 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
284
    }
285 1
    public function handle444()
286
    {
287 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
288
    }
289 1
    public function handle449()
290
    {
291 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
292
    }
293 1
    public function handle451()
294
    {
295 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
296
    }
297
298
    /**
299
     * handle HTTP-Status-Codes of type 5xx
300
     */
301 1
    public function handle500()
302
    {
303 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
304
    }
305 1
    public function handle501()
306
    {
307 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
308
    }
309 1
    public function handle502()
310
    {
311 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
312
    }
313 1
    public function handle503()
314
    {
315 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
316
    }
317 1
    public function handle504()
318
    {
319 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
320
    }
321 1
    public function handle505()
322
    {
323 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
324
    }
325 1
    public function handle506()
326
    {
327 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
328
    }
329 1
    public function handle507()
330
    {
331 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
332
    }
333 1
    public function handle508()
334
    {
335 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
336
    }
337 1
    public function handle509()
338
    {
339 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
340
    }
341 1
    public function handle510()
342
    {
343 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
344
    }
345
346
347
    /**
348
     * handle HTTP-Status-Codes of type 9xx
349
     */
350 1
    public function handle900()
351
    {
352 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
353
    }
354 1
    public function handle901()
355
    {
356 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
357
    }
358 1
    public function handle902()
359
    {
360 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
361
    }
362 1
    public function handle903()
363
    {
364 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
365
    }
366 1
    public function handle904()
367
    {
368 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
369
    }
370 1
    public function handle905()
371
    {
372 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
373
    }
374 1
    public function handle906()
375
    {
376 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
377
    }
378 1
    public function handle907()
379
    {
380 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
381
    }
382 1
    public function handle950()
383
    {
384 1
        return $this->handleException($this->getRestlerException(func_get_args()), $this->getRestler());
385
    }
386
387
    /**
388
     * This is the right place, where we can handle exceptions, which were thrown in REST-API's!
389
     *
390
     * The return value (boolean) describes, if restler should display an error as output:
391
     * TRUE means:  restler should NOT display an error as output (so, we must do that)
392
     * FALSE means: restler should dislay an error as output
393
     *
394
     * @param RestException $exception
395
     * @param Restler $restler
396
     * @return boolean
397
     */
398
    abstract protected function handleException(RestException $exception, Restler $restler);
399
400
    /**
401
     * This method must be protected - otherwise we can't test this class in unittests
402
     *
403
     * @return Restler
404
     */
405
    protected function getRestler()
406
    {
407
        return Scope::get('Restler');
408
    }
409
410
    /**
411
     * This method must be protected - otherwise we can't test this class in unittests
412
     *
413
     * @param array $exceptionHandlerArgs
414
     * @return RestException
415
     */
416
    protected function getRestlerException(array $exceptionHandlerArgs = [])
417
    {
418
        if (count($exceptionHandlerArgs) > 0 && $exceptionHandlerArgs[0] instanceof RestException) {
419
            return $exceptionHandlerArgs[0];
420
        }
421
        return $this->getRestler()
422
            ->exception;
423
    }
424
}
425