| Conditions | 6 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 6 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | 10 | public function encode(AbstractResponse $response) |
|
| 20 | { |
||
| 21 | 10 | $responseObject = $response->getResponseObject(); |
|
| 22 | 10 | if (null === $responseObject || is_array($responseObject) || is_scalar($responseObject)) { |
|
| 23 | 6 | return json_encode($responseObject); |
|
| 24 | 5 | } elseif (is_object($responseObject)) { |
|
| 25 | 4 | if (method_exists($responseObject, 'jsonSerialize')) { |
|
| 26 | 1 | return json_encode($responseObject->jsonSerialize()); |
|
| 27 | } else { |
||
| 28 | 3 | return json_encode(get_object_vars($responseObject)); |
|
| 29 | } |
||
| 30 | } else { |
||
| 31 | 1 | throw new EncoderException('Unable to encode response as JSON.'); |
|
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 |