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

JsonRpcRequest::getParamList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcServer\Domain\Model;
3
4
use \InvalidArgumentException;
5
6
/**
7
 * Class JsonRpcRequest
8
 */
9
class JsonRpcRequest
10
{
11
    /** @var string */
12
    private $jsonRpc;
13
    /** @var string */
14
    private $method;
15
    /** @var array */
16
    private $paramList = [];
17
    /** @var int|string|null */
18
    private $id = null;
19
20
    /**
21
     * @param string $jsonRpc
22
     * @param string $method
23
     */
24
    public function __construct(string $jsonRpc, string $method)
25
    {
26
        $this->jsonRpc = $jsonRpc;
27
        $this->method = $method;
28
    }
29
30
    /**
31
     * @param array $paramList
32
     *
33
     * @return JsonRpcRequest
34
     */
35
    public function setParamList(array $paramList) : JsonRpcRequest
36
    {
37
        $this->paramList = $paramList;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param mixed $id
44
     *
45
     * @throws InvalidArgumentException
46
     * @return JsonRpcRequest
47
     */
48
    public function setId($id) : JsonRpcRequest
49
    {
50
        if (!is_string($id) && !is_int($id)) {
51
            throw new InvalidArgumentException('Id must be an int or a string');
52
        }
53
54
        $this->id = $id;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getJsonRpc() : string
63
    {
64
        return $this->jsonRpc;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getMethod() : string
71
    {
72
        return $this->method;
73
    }
74
75
    /**
76
     * @return array
77
     */
78
    public function getParamList() : array
79
    {
80
        return $this->paramList;
81
    }
82
83
    /**
84
     * @return string|int|null
85
     */
86
    public function getId()
87
    {
88
        return $this->id;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94
    public function isNotification() : bool
95
    {
96
        return null === $this->id;
97
    }
98
}
99