Conditions | 4 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | 6 | public function convert(Throwable $e): array |
|
18 | { |
||
19 | 6 | if (!$e instanceof HttpException) { |
|
20 | 1 | throw new InvalidArgumentException(sprintf('%s is not a %s', get_class($e), HttpException::class)); |
|
21 | } |
||
22 | |||
23 | 5 | $statusCode = $e->getStatusCode(); |
|
24 | 5 | $message = 'Internal Service Error.'; |
|
25 | 5 | if ($statusCode < 400) { |
|
26 | 1 | $statusCode = 500; |
|
27 | 5 | } elseif ($statusCode >= 600) { |
|
28 | 1 | $statusCode = 500; |
|
29 | } else { |
||
30 | 4 | $message = $e->getMessage(); |
|
31 | } |
||
32 | |||
33 | return [ |
||
34 | 5 | 'status' => $statusCode, |
|
35 | 5 | 'code' => (int) $e->getCode(), |
|
36 | 5 | 'message' => $message, |
|
37 | ]; |
||
40 |