Conditions | 4 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 4.0092 |
Changes | 0 |
1 | <?php |
||
13 | 2 | public function createFromResponse(DataResponse $response): ApiResponseData |
|
14 | { |
||
15 | 2 | if ($response->getStatusCode() !== Status::OK) { |
|
16 | 1 | return $this |
|
17 | 1 | ->createErrorResponse() |
|
18 | 1 | ->setErrorCode($response->getStatusCode()) |
|
19 | 1 | ->setErrorMessage($this->getErrorMessage($response)); |
|
20 | } |
||
21 | |||
22 | 1 | $data = $response->getData(); |
|
23 | |||
24 | 1 | if ($data !== null && !is_array($data)) { |
|
25 | throw new RuntimeException('The response data must be either null or an array'); |
||
26 | } |
||
27 | |||
28 | 1 | return $this |
|
29 | 1 | ->createSuccessResponse() |
|
30 | 1 | ->setData($data); |
|
31 | } |
||
62 |