Completed
Push — master ( 5c78d7...6647db )
by thomas
8s
created

Request   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 67
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getMethod() 0 4 1
A getParams() 0 4 1
A write() 0 11 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