| Total Complexity | 8 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class ResponseObject implements ResponseObjectInterface |
||
| 19 | { |
||
| 20 | /** @var string */ |
||
| 21 | private $jsonrpc; |
||
| 22 | |||
| 23 | /** @var mixed */ |
||
| 24 | private $result; |
||
| 25 | |||
| 26 | /** @var ErrorObject|null */ |
||
| 27 | private $error; |
||
| 28 | |||
| 29 | /** @var string|int|null */ |
||
| 30 | 16 | private $id; |
|
| 31 | |||
| 32 | 16 | public function __construct(string $protocol, $result, $id) |
|
| 33 | { |
||
| 34 | $this->jsonrpc = $protocol; |
||
| 35 | 6 | $this->result = $result; |
|
| 36 | $this->id = $id; |
||
| 37 | 6 | } |
|
| 38 | |||
| 39 | public function getProtocol(): string |
||
| 40 | 15 | { |
|
| 41 | return $this->jsonrpc; |
||
| 42 | 15 | } |
|
| 43 | |||
| 44 | public function getId() |
||
| 45 | 17 | { |
|
| 46 | return $this->id; |
||
| 47 | 17 | } |
|
| 48 | |||
| 49 | public function getResult() |
||
| 50 | 6 | { |
|
| 51 | return $this->result; |
||
| 52 | 6 | } |
|
| 53 | |||
| 54 | public function hasError(): bool |
||
| 55 | { |
||
| 56 | return null !== $this->error; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function getError(): ErrorObject |
||
| 60 | { |
||
| 61 | if ($this->error === null) { |
||
| 62 | throw new JsonRpcClientException( |
||
| 63 | 'There is no error in response. Please, use hasError() method to check response for errors.' |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | return $this->error; |
||
| 68 | } |
||
| 69 | |||
| 70 | public function setError(ErrorObject $error): void |
||
| 73 | } |
||
| 74 | } |
||
| 75 |