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