Completed
Pull Request — master (#3)
by thomas
25:38
created

HeadersNotification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 9
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace BitWasp\Stratum\Notification;
4
5
use BitWasp\Stratum\Api\ElectrumClient;
6
use BitWasp\Stratum\Request\Request;
7
8
class HeadersNotification implements NotificationInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    private $version;
14
15
    /**
16
     * @var string
17
     */
18
    private $prevBlock;
19
20
    /**
21
     * @var string
22
     */
23
    private $merkleRoot;
24
25
    /**
26
     * @var int
27
     */
28
    private $timestamp;
29
30
    /**
31
     * @var int
32
     */
33
    private $bits;
34
35
    /**
36
     * @var int
37
     */
38
    private $nonce;
39
40
    /**
41
     * @var int
42
     */
43
    private $height;
44
45
    /**
46
     * @var string
47
     */
48
    private $utxoRoot;
49
50
    /**
51
     * HeadersNotification constructor.
52
     * @param int $nonce
53
     * @param string $prevBlock
54
     * @param int $timestamp
55
     * @param string $merkleroot
56
     * @param int $height
57
     * @param string $utxoRoot
58
     * @param int $version
59
     * @param int $bits
60
     */
61
    public function __construct($nonce, $prevBlock, $timestamp, $merkleroot, $height, $utxoRoot, $version, $bits)
62
    {
63
        $this->nonce = $nonce;
64
        $this->prevBlock = $prevBlock;
65
        $this->timestamp = $timestamp;
66
        $this->merkleRoot = $merkleroot;
67
        $this->height = $height;
68
        $this->utxoRoot = $utxoRoot;
69
        $this->version = $version;
70
        $this->bits = $bits;
71
    }
72
73
    /**
74
     * @return int
75
     */
76
    public function getVersion()
77
    {
78
        return $this->version;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getPrevBlock()
85
    {
86
        return $this->prevBlock;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getMerkleRoot()
93
    {
94
        return $this->merkleRoot;
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getTimestamp()
101
    {
102
        return $this->timestamp;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getBits()
109
    {
110
        return $this->bits;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getNonce()
117
    {
118
        return $this->nonce;
119
    }
120
121
    /**
122
     * @return int
123
     */
124
    public function getHeight()
125
    {
126
        return $this->height;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getUtxoRoot()
133
    {
134
        return $this->utxoRoot;
135
    }
136
137
    /**
138
     * @return Request
139
     */
140
    public function toRequest()
141
    {
142
        return new Request(null, ElectrumClient::HEADERS_SUBSCRIBE, [[
143
            $this->nonce, $this->prevBlock, $this->timestamp,
144
            $this->merkleRoot, $this->height, $this->utxoRoot,
145
            $this->version, $this->bits
146
        ]]);
147
    }
148
}
149