| Conditions | 5 |
| Paths | 9 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | 30 | public function transform(\Exception $exception) |
|
| 28 | { |
||
| 29 | 30 | if ($exception instanceof BadResponseException === false) { |
|
| 30 | 2 | return new ApiException($exception); |
|
| 31 | } |
||
| 32 | |||
| 33 | try { |
||
| 34 | /** @var BadResponseException $exception */ |
||
| 35 | 28 | $errorResponse = $exception->getResponse(); |
|
| 36 | 28 | $errorStatusCode = $errorResponse->getStatusCode(); |
|
| 37 | 28 | $bodyString = (string) $errorResponse->getBody(); |
|
| 38 | 27 | $bodyArray = json_decode($bodyString, true); |
|
| 39 | 27 | $errorStatusName = ''; |
|
| 40 | 27 | if (is_array($bodyArray) && array_key_exists('error', $bodyArray)) { |
|
| 41 | 27 | $errorStatusName = $bodyArray['error']; |
|
| 42 | } |
||
| 43 | 1 | } catch (\Exception $e) { |
|
| 44 | 1 | return new ApiException($exception); |
|
| 45 | } |
||
| 46 | |||
| 47 | 27 | return $this->transformByStatusCodeAndName($exception, $errorStatusCode, $errorStatusName); |
|
| 48 | } |
||
| 49 | } |
||
| 50 |