Failed Conditions
Pull Request — release/3.0.0-dev (#32)
by Yo
01:56
created

JsonRpcRequest::getId()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 10
    public function __construct(string $jsonRpc, string $method)
25
    {
26 10
        $this->jsonRpc = $jsonRpc;
27 10
        $this->method = $method;
28 10
    }
29
30
    /**
31
     * @param array $paramList
32
     *
33
     * @return JsonRpcRequest
34
     */
35 1
    public function setParamList(array $paramList) : JsonRpcRequest
36
    {
37 1
        $this->paramList = $paramList;
38
39 1
        return $this;
40
    }
41
42
    /**
43
     * @param mixed $id
44
     *
45
     * @throws InvalidArgumentException
46
     * @return JsonRpcRequest
47
     */
48 7
    public function setId($id) : JsonRpcRequest
49
    {
50 7
        if (!is_string($id) && !is_int($id)) {
51 5
            throw new InvalidArgumentException('Id must be either an int or a string');
52
        }
53
54 2
        $this->id = $id;
55
56 2
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 1
    public function getJsonRpc() : string
63
    {
64 1
        return $this->jsonRpc;
65
    }
66
67
    /**
68
     * @return string
69
     */
70 1
    public function getMethod() : string
71
    {
72 1
        return $this->method;
73
    }
74
75
    /**
76
     * @return array
77
     */
78 1
    public function getParamList() : array
79
    {
80 1
        return $this->paramList;
81
    }
82
83
    /**
84
     * @return string|int|null
85
     */
86 2
    public function getId()
87
    {
88 2
        return $this->id;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94 1
    public function isNotification() : bool
95
    {
96 1
        return null === $this->id;
97
    }
98
}
99