Total Complexity | 3 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
25 | final class JsonApiConverter implements Converter |
||
26 | { |
||
27 | |||
28 | use JsonMethods; |
||
29 | |||
30 | /** |
||
31 | * @inheritDoc |
||
32 | */ |
||
33 | public function convert(Throwable $throwable): string |
||
34 | { |
||
35 | $inspector = new ExceptionInspector($throwable); |
||
36 | $jsonApiError = new ErrorObject( |
||
37 | title: $this->clearTitle($throwable), |
||
38 | detail: $this->details($throwable, $inspector), |
||
39 | status: (string) $inspector->statusCode() |
||
40 | ); |
||
41 | $response = [ |
||
42 | "jsonapi" => ["version" => JsonApi::JSON_API_11], |
||
43 | "errors" => [ |
||
44 | $jsonApiError->withIdentifier(uniqid()) |
||
45 | ] |
||
46 | ]; |
||
47 | $jsonResponse = json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); |
||
48 | return $jsonResponse ?: ''; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @inheritDoc |
||
53 | */ |
||
54 | public function contentType(): string |
||
57 | } |
||
58 | } |
||
59 |