| Total Complexity | 12 | 
| Total Lines | 111 | 
| Duplicated Lines | 0 % | 
| Coverage | 100% | 
| Changes | 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 | 11 | public function __construct(string $jsonRpc = self::DEFAULT_VERSION) | |
| 28 |     { | ||
| 29 | 11 | $this->jsonRpc = $jsonRpc; | |
| 30 | 11 | } | |
| 31 | |||
| 32 | /** | ||
| 33 | * @param mixed $result | ||
| 34 | * | ||
| 35 | * @return JsonRpcResponse | ||
| 36 | */ | ||
| 37 | 1 | public function setResult($result) : JsonRpcResponse | |
| 42 | } | ||
| 43 | |||
| 44 | /** | ||
| 45 | * @param JsonRpcExceptionInterface $error | ||
| 46 | * | ||
| 47 | * @return JsonRpcResponse | ||
| 48 | */ | ||
| 49 | 1 | public function setError(JsonRpcExceptionInterface $error) : JsonRpcResponse | |
| 50 |     { | ||
| 51 | 1 | $this->error = $error; | |
| 52 | |||
| 53 | 1 | return $this; | |
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * @param mixed $id | ||
| 58 | * | ||
| 59 | * @return JsonRpcResponse | ||
| 60 | */ | ||
| 61 | 7 | public function setId($id) : JsonRpcResponse | |
| 62 |     { | ||
| 63 | 7 |         if (!is_string($id) && !is_int($id)) { | |
| 64 | 5 |             throw new \InvalidArgumentException('Id must be either an int or a string'); | |
| 65 | } | ||
| 66 | |||
| 67 | 2 | $this->id = $id; | |
| 68 | |||
| 69 | 2 | return $this; | |
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * @param bool $isNotification | ||
| 74 | */ | ||
| 75 | 1 | public function setIsNotification(bool $isNotification) : JsonRpcResponse | |
| 76 |     { | ||
| 77 | 1 | $this->isNotification = $isNotification; | |
| 78 | |||
| 79 | 1 | return $this; | |
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * @return string | ||
| 84 | */ | ||
| 85 | 1 | public function getJsonRpc() : string | |
| 86 |     { | ||
| 87 | 1 | return $this->jsonRpc; | |
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * @return mixed | ||
| 92 | */ | ||
| 93 | 1 | public function getResult() | |
| 94 |     { | ||
| 95 | 1 | return $this->result; | |
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 | * @return JsonRpcExceptionInterface|null | ||
| 100 | */ | ||
| 101 | 1 | public function getError() | |
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * @return string|int|null | ||
| 108 | */ | ||
| 109 | 2 | public function getId() | |
| 110 |     { | ||
| 111 | 2 | return $this->id; | |
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 115 | * @return bool | ||
| 116 | */ | ||
| 117 | 1 | public function isNotification() : bool | |
| 120 | } | ||
| 121 | } | ||
| 122 |