Test Failed
Push — feature/init ( ecfce8...b38e47 )
by Yo
05:12
created

JsonRpcResponse   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 10

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 5 1
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
    public function __construct(string $jsonRpc = self::DEFAULT_VERSION)
28
    {
29
        $this->jsonRpc = $jsonRpc;
30
    }
31
32
    /**
33
     * @param mixed $result
34
     *
35
     * @return JsonRpcResponse
36
     */
37
    public function setResult($result) : JsonRpcResponse
38
    {
39
        $this->result = $result;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param JsonRpcExceptionInterface $error
46
     *
47
     * @return JsonRpcResponse
48
     */
49
    public function setError(JsonRpcExceptionInterface $error) : JsonRpcResponse
50
    {
51
        $this->error = $error;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param mixed $id
58
     *
59
     * @return JsonRpcResponse
60
     */
61
    public function setId($id) : JsonRpcResponse
62
    {
63
        $this->id = $id;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param bool $isNotification
70
     */
71
    public function setIsNotification(bool $isNotification) : JsonRpcResponse
72
    {
73
        $this->isNotification = $isNotification;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getJsonRpc() : string
82
    {
83
        return $this->jsonRpc;
84
    }
85
86
    /**
87
     * @return mixed
88
     */
89
    public function getResult()
90
    {
91
        return $this->result;
92
    }
93
94
    /**
95
     * @return JsonRpcExceptionInterface|null
96
     */
97
    public function getError()
98
    {
99
        return $this->error;
100
    }
101
102
    /**
103
     * @return string|int|null
104
     */
105
    public function getId()
106
    {
107
        return $this->id;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113
    public function isNotification() : bool
114
    {
115
        return $this->isNotification;
116
    }
117
}
118