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 | private $id; |
||
31 | |||
32 | 51 | public function __construct(string $protocol, $result, $id) |
|
33 | { |
||
34 | 51 | $this->jsonrpc = $protocol; |
|
35 | 51 | $this->result = $result; |
|
36 | 51 | $this->id = $id; |
|
37 | 51 | } |
|
38 | |||
39 | 40 | public function getProtocol(): string |
|
40 | { |
||
41 | 40 | return $this->jsonrpc; |
|
42 | } |
||
43 | |||
44 | 24 | public function getId() |
|
45 | { |
||
46 | 24 | return $this->id; |
|
47 | } |
||
48 | |||
49 | 40 | public function getResult() |
|
50 | { |
||
51 | 40 | return $this->result; |
|
52 | } |
||
53 | |||
54 | 44 | public function hasError(): bool |
|
55 | { |
||
56 | 44 | return null !== $this->error; |
|
57 | } |
||
58 | |||
59 | 17 | public function getError(): ErrorObject |
|
60 | { |
||
61 | 17 | if (null === $this->error) { |
|
62 | 1 | throw new JsonRpcClientException( |
|
63 | 1 | 'There is no error in response. Please, use hasError() method to check response for errors.' |
|
64 | ); |
||
65 | } |
||
66 | |||
67 | 16 | return $this->error; |
|
68 | } |
||
69 | |||
70 | 16 | public function setError(ErrorObject $error): void |
|
73 | 16 | } |
|
74 | } |
||
75 |