JsonRpcResponse::getResult()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
namespace Yoanm\JsonRpcServer\Domain\Model;
3
4
use Yoanm\JsonRpcServer\Domain\Exception\JsonRpcExceptionInterface;
5
6
/**
7
 * Class JsonRpcResponse
8
 */
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
38
    {
39 11
        $this->result = $result;
40
41 11
        return $this;
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
104
    {
105 40
        return $this->error;
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
120
    {
121 44
        return $this->isNotification;
122
    }
123
}
124