| Total Complexity | 9 |
| Total Lines | 81 |
| Duplicated Lines | 0 % |
| Coverage | 29.63% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class AbstractResponse implements ResponseInterface |
||
| 11 | { |
||
| 12 | /** @var mixed[] */ |
||
| 13 | private $contents; |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | private $error; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param TelnetResponseInterface $telnetResponse |
||
| 20 | */ |
||
| 21 | 2 | public function __construct(TelnetResponseInterface $telnetResponse) |
|
| 22 | { |
||
| 23 | try { |
||
| 24 | 2 | $xml = @new SimpleXMLElement($telnetResponse->getResponseText(), 0, false, 'cw', true); |
|
| 25 | 2 | } catch (Exception $e) { |
|
| 26 | 2 | $this->setError($e->getMessage()); |
|
| 27 | 2 | return; |
|
| 28 | } |
||
| 29 | |||
| 30 | $xmlConverter = new XmlConverter(); |
||
| 31 | $this->contents = $xmlConverter->convertToArray($xml); |
||
| 32 | |||
| 33 | if ($telnetResponse->isError()) { |
||
| 34 | $error = 'unknown'; |
||
| 35 | if (isset($this->contents['error_info']['error_text'])) { |
||
| 36 | $error = $this->contents['error_info']['error_text']; |
||
| 37 | } |
||
| 38 | |||
| 39 | $this->setError('Telnet response error: '.$error); |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->parseContents($this->contents); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $error |
||
| 48 | */ |
||
| 49 | 2 | private function setError($error) |
|
| 50 | { |
||
| 51 | 2 | $this->error = $error; |
|
| 52 | 2 | } |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Whether an error was returned. |
||
| 56 | * |
||
| 57 | * @return bool |
||
| 58 | */ |
||
| 59 | public function hasError() |
||
| 60 | { |
||
| 61 | return (bool)$this->error; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the error message. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | public function getError() |
||
| 70 | { |
||
| 71 | return $this->error; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Extract specific information from the raw contents array for easier access. |
||
| 76 | * |
||
| 77 | * @param mixed[] $contents |
||
| 78 | */ |
||
| 79 | protected function parseContents(array $contents) |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Get the raw response as an array. |
||
| 85 | * |
||
| 86 | * @return mixed[] |
||
| 87 | */ |
||
| 88 | public function getContents() |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.