| Total Complexity | 2 |
| Total Lines | 31 |
| 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 | return json_encode($response, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @inheritDoc |
||
| 52 | */ |
||
| 53 | public function contentType(): string |
||
| 56 | } |
||
| 57 | } |
||
| 58 |