| Conditions | 1 |
| Paths | 1 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 1 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | 32 | public function __invoke( |
|
| 13 | Request $request, |
||
| 14 | Response $response, |
||
| 15 | \Exception $exception |
||
| 16 | ): Response { |
||
| 17 | 32 | $statusCode = $this->getStatusCode($exception); |
|
| 18 | 32 | $className = new \ReflectionClass($exception::class); |
|
| 19 | $data = [ |
||
| 20 | 32 | 'message' => $exception->getMessage(), |
|
| 21 | 32 | 'class' => $className->getName(), |
|
| 22 | 32 | 'status' => 'error', |
|
| 23 | 32 | 'code' => $statusCode, |
|
| 24 | ]; |
||
| 25 | 32 | $body = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); |
|
| 26 | 32 | $response->getBody()->write((string) $body); |
|
| 27 | |||
| 28 | return $response |
||
| 29 | 32 | ->withStatus($statusCode) |
|
| 30 | 32 | ->withHeader('Content-type', 'application/problem+json'); |
|
| 31 | } |
||
| 47 |