| Total Complexity | 8 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 5 | class Response |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * status of the server response - fail is not nessisary a fail in this case. |
||
| 9 | * |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | public $status; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * status code of the server response. |
||
| 16 | * |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | public $statusCode; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * message from the response. |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | * @author Craig Smith <[email protected]> |
||
| 26 | */ |
||
| 27 | public $message; |
||
| 28 | |||
| 29 | public function __construct($body, $format) |
||
| 30 | { |
||
| 31 | switch ($format) { |
||
| 32 | case 'xml': |
||
| 33 | libxml_use_internal_errors(true); |
||
| 34 | $res = simplexml_load_string((string) $body); |
||
| 35 | if ($res) { |
||
| 36 | $res = json_decode(json_encode($res)); |
||
| 37 | } |
||
| 38 | break; |
||
| 39 | case 'json': |
||
| 40 | $res = json_decode((string) $body); |
||
| 41 | break; |
||
| 42 | default: |
||
| 43 | $res = (string) $body; |
||
| 44 | break; |
||
| 45 | } |
||
| 46 | $this->parseResponseBody($res); |
||
| 47 | } |
||
| 48 | |||
| 49 | protected function parseResponseBody($body) |
||
| 65 | } |
||
| 66 | } |
||
| 68 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.