Request::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BitWasp\Stratum\Request;
4
5
class Request
6
{
7
    /**
8
     * @var int
9
     */
10
    private $id;
11
12
    /**
13
     * @var string
14
     */
15
    private $method;
16
17
    /**
18
     * @var array
19
     */
20
    private $params = [];
21
22
    /**
23
     * @param string $method
24
     * @param array $params
25
     */
26 46
    public function __construct($id, $method, array $params = array())
27
    {
28 46
        $this->id = $id;
29 46
        $this->method = $method;
30 46
        $this->params = $params;
31 46
    }
32
33
    /**
34
     * @return int
35
     */
36 21
    public function getId()
37
    {
38 21
        return $this->id;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 20
    public function getMethod()
45
    {
46 20
        return $this->method;
47
    }
48
49
    /**
50
     * @return array
51
     */
52 20
    public function getParams()
53
    {
54 20
        return $this->params;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 4
    public function write()
61
    {
62 4
        return json_encode(
63
            [
64 4
                "json-rpc" => "2.0",
65 4
                "id" => $this->id,
66 4
                "method" => $this->method,
67 4
                "params" => $this->params
68 4
            ]
69 4
        ) . "\n";
70
    }
71
}
72