JsonRpcResponse   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 23
c 2
b 0
f 0
dl 0
loc 113
ccs 26
cts 26
cp 1
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setResult() 0 5 1
A getError() 0 3 1
A isNotification() 0 3 1
A setIsNotification() 0 5 1
A __construct() 0 3 1
A getResult() 0 3 1
A getId() 0 3 1
A getJsonRpc() 0 3 1
A setId() 0 9 3
A setError() 0 5 1
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