| Total Complexity | 7 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class ResponseException extends RuntimeException |
||
| 12 | { |
||
| 13 | /** @var ResponseInterface */ |
||
| 14 | private $response; |
||
| 15 | |||
| 16 | public function __construct( |
||
| 17 | ResponseInterface $response, |
||
| 18 | ?string $message = null, |
||
| 19 | ?int $code = null, |
||
| 20 | ?Throwable $previous = null |
||
| 21 | ) { |
||
| 22 | $this->response = $response; |
||
| 23 | $code = $code ?? $response->getStatusCode(); |
||
| 24 | $message = $message ?? sprintf("%s %s", $response->getStatusCode(), $response->getReasonPhrase()); |
||
| 25 | |||
| 26 | try { |
||
| 27 | $result = $this->parseResult(); |
||
| 28 | |||
| 29 | if (isset($result['title'])) { |
||
| 30 | $message .= ': ' . $result['title']; |
||
| 31 | } |
||
| 32 | |||
| 33 | if (isset($result['detail'])) { |
||
| 34 | $message .= ': ' . $result['detail']; |
||
| 35 | } |
||
| 36 | } catch (RuntimeException $e) { |
||
| 37 | $message .= ': ' . $e->getMessage(); |
||
| 38 | } |
||
| 39 | |||
| 40 | parent::__construct($message, $code, $previous); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Access its underlying response object. |
||
| 45 | */ |
||
| 46 | public function getResponse(): ResponseInterface |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return mixed[] |
||
| 53 | */ |
||
| 54 | protected function parseResult(): array |
||
| 63 | } |
||
| 64 | } |
||
| 65 |