| Total Complexity | 4 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class JsonErrorRenderer implements Renderer |
||
| 12 | { |
||
| 13 | 3 | public function __construct(protected ResponseFactory $response) |
|
| 15 | 3 | } |
|
| 16 | |||
| 17 | 2 | public function render(mixed $data, mixed ...$args): string |
|
| 18 | { |
||
| 19 | 2 | assert($data instanceof Error); |
|
| 20 | |||
| 21 | 2 | $json = ['error' => $data->error]; |
|
| 22 | |||
| 23 | 2 | if ($data->debug) { |
|
| 24 | 1 | $json['description'] = $data->description; |
|
| 25 | 1 | $json['traceback'] = $data->traceback; |
|
| 26 | } |
||
| 27 | |||
| 28 | 2 | return json_encode($json, JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR); |
|
| 29 | } |
||
| 30 | |||
| 31 | 2 | public function response(mixed $data, mixed ...$args): Response |
|
| 38 | } |
||
| 39 | } |
||
| 40 |