| Total Complexity | 6 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | abstract class AbstractResponse extends Entity |
||
| 14 | { |
||
| 15 | /* |
||
| 16 | * Error identifier. |
||
| 17 | * 0 - no errors, operation completed successfully. |
||
| 18 | * >1 - error identifier. Error code and short description transferred in errorCode and errorDescription properties. |
||
| 19 | */ |
||
| 20 | public int $errorId = 0; |
||
| 21 | |||
| 22 | /* |
||
| 23 | * An error code, won't be included in the output if request produced no errors. |
||
| 24 | */ |
||
| 25 | public string $errorCode = ''; |
||
| 26 | |||
| 27 | /* |
||
| 28 | * Short description of the error |
||
| 29 | */ |
||
| 30 | public string $errorDescription = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ResponseInterface $httpResponse |
||
| 34 | * |
||
| 35 | * @return $this |
||
| 36 | * |
||
| 37 | * @throws Exception |
||
| 38 | */ |
||
| 39 | public static function fromHttpResponse(ResponseInterface $httpResponse): self |
||
| 40 | { |
||
| 41 | $properties = json_decode( |
||
| 42 | $httpResponse->getBody()->__toString(), |
||
| 43 | true, |
||
| 44 | JSON_THROW_ON_ERROR |
||
| 45 | ); |
||
| 46 | |||
| 47 | if (!is_array($properties)) { |
||
| 48 | throw new RuntimeException( |
||
| 49 | sprintf('Unexpected API response. Dump: %s', var_export($httpResponse, true)) |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | return new static($properties); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function hasError(): bool |
||
| 59 | } |
||
| 60 | |||
| 61 | public function getErrorId(): int |
||
| 62 | { |
||
| 63 | return $this->errorId; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function getErrorCode(): string |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getErrorDescription(): string |
||
| 74 | } |
||
| 75 | } |
||
| 76 |