| Total Complexity | 12 |
| Total Lines | 113 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class JsonRpcResponse |
||
| 10 | { |
||
| 11 | const DEFAULT_VERSION = '2.0'; |
||
| 12 | |||
| 13 | /** @var string */ |
||
| 14 | private $jsonRpc; |
||
| 15 | /** @var mixed */ |
||
| 16 | private $result = null; |
||
| 17 | /** @var null|JsonRpcExceptionInterface */ |
||
| 18 | private $error = null; |
||
| 19 | /** @var mixed */ |
||
| 20 | private $id = null; |
||
| 21 | /** @var bool */ |
||
| 22 | private $isNotification = false; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $jsonRpc |
||
| 26 | */ |
||
| 27 | 54 | public function __construct(string $jsonRpc = self::DEFAULT_VERSION) |
|
| 28 | { |
||
| 29 | 54 | $this->jsonRpc = $jsonRpc; |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param mixed $result |
||
| 34 | * |
||
| 35 | * @return self |
||
| 36 | */ |
||
| 37 | 11 | public function setResult($result) : self |
|
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param JsonRpcExceptionInterface $error |
||
| 46 | * |
||
| 47 | * @return self |
||
| 48 | */ |
||
| 49 | 37 | public function setError(JsonRpcExceptionInterface $error) : self |
|
| 50 | { |
||
| 51 | 37 | $this->error = $error; |
|
| 52 | |||
| 53 | 37 | return $this; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param mixed $id |
||
| 58 | * |
||
| 59 | * @return self |
||
| 60 | */ |
||
| 61 | 23 | public function setId($id) : self |
|
| 62 | { |
||
| 63 | 23 | if (!is_string($id) && !is_int($id)) { |
|
| 64 | 5 | throw new \InvalidArgumentException('Id must be either an int or a string'); |
|
| 65 | } |
||
| 66 | |||
| 67 | 18 | $this->id = $id; |
|
| 68 | |||
| 69 | 18 | return $this; |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param bool $isNotification |
||
| 74 | * |
||
| 75 | * @return self |
||
| 76 | */ |
||
| 77 | 22 | public function setIsNotification(bool $isNotification) : self |
|
| 78 | { |
||
| 79 | 22 | $this->isNotification = $isNotification; |
|
| 80 | |||
| 81 | 22 | return $this; |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | 40 | public function getJsonRpc() : string |
|
| 88 | { |
||
| 89 | 40 | return $this->jsonRpc; |
|
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @return mixed |
||
| 94 | */ |
||
| 95 | 7 | public function getResult() |
|
| 96 | { |
||
| 97 | 7 | return $this->result; |
|
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return JsonRpcExceptionInterface|null |
||
| 102 | */ |
||
| 103 | 40 | public function getError() : ?JsonRpcExceptionInterface |
|
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return string|int|null |
||
| 110 | */ |
||
| 111 | 41 | public function getId() |
|
| 112 | { |
||
| 113 | 41 | return $this->id; |
|
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @return bool |
||
| 118 | */ |
||
| 119 | 44 | public function isNotification() : bool |
|
| 122 | } |
||
| 123 | } |
||
| 124 |