Passed
Push — master ( 8e7304...5050b5 )
by Vladislav
05:53 queued 14s
created

BooktickerAbstract   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 229
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 229
rs 10
c 0
b 0
f 0
wmc 19

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setTopic() 0 4 1
A getSymbol() 0 3 1
A getBidQuantity() 0 3 1
A setType() 0 4 1
A setResponseTimestamp() 0 4 1
A setSymbol() 0 4 1
A setAskQuantity() 0 4 1
A setBestAskPrice() 0 4 1
A getBestAskPrice() 0 3 1
A __construct() 0 12 1
A getRequestTimestamp() 0 3 1
A getType() 0 3 1
A setRequestTimestamp() 0 4 1
A getResponseTimestamp() 0 3 1
A getBestBidPrice() 0 3 1
A setBidQuantity() 0 4 1
A getTopic() 0 3 1
A setBestBidPrice() 0 4 1
A getAskQuantity() 0 3 1
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Bookticker\Entities;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
6
7
class BooktickerAbstract extends AbstractResponse
8
{
9
    /**
10
     * Topic name
11
     * @var string
12
     */
13
    private string $topic;
14
15
    /**
16
     * The timestamp (ms) that message is sent out
17
     * @var \DateTime $requestTimestamp
18
     */
19
    private \DateTime $requestTimestamp;
20
21
    /**
22
     * Data type. snapshot
23
     * @var string $type
24
     */
25
    private string $type;
26
27
    /**
28
     * Trading pair
29
     * @var string
30
     */
31
    private string $symbol;
32
33
    /**
34
     * Best bid price
35
     * @var float $bestBidPrice
36
     */
37
    private float $bestBidPrice;
38
39
    /**
40
     * Bid quantity
41
     * @var float $bidQuantity
42
     */
43
    private float $bidQuantity;
44
45
    /**
46
     * Best ask price
47
     * @var float $bestAskPrice
48
     */
49
    private float $bestAskPrice;
50
51
    /**
52
     * Ask quantity
53
     * @var float $askQuantity
54
     */
55
    private float $askQuantity;
56
57
    /**
58
     * @var \DateTime $responseTimestamp
59
     */
60
    private \DateTime $responseTimestamp;
61
62
    public function __construct(array $data)
63
    {
64
        $this
65
            ->setTopic($data['topic'])
66
            ->setRequestTimestamp($data['ts'])
67
            ->setType($data['type'])
68
            ->setSymbol($data['data']['s'])
69
            ->setBestAskPrice($data['data']['bp'])
70
            ->setAskQuantity($data['data']['aq'])
71
            ->setBestBidPrice($data['data']['bq'])
72
            ->setBidQuantity($data['data']['bq'])
73
            ->setResponseTimestamp($data['data']['t']);
74
    }
75
76
    /**
77
     * @param string $responseTimestamp
78
     * @return BooktickerAbstract
79
     */
80
    public function setResponseTimestamp(string $responseTimestamp): self
81
    {
82
        $this->responseTimestamp = DateTimeHelper::makeFromTimestamp($responseTimestamp);
0 ignored issues
show
Bug introduced by
$responseTimestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $this->responseTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $responseTimestamp);
Loading history...
83
        return $this;
84
    }
85
86
    /**
87
     * @return \DateTime
88
     */
89
    public function getResponseTimestamp(): \DateTime
90
    {
91
        return $this->responseTimestamp;
92
    }
93
94
    /**
95
     * @param float $bestBidPrice
96
     * @return BooktickerAbstract
97
     */
98
    private function setBestBidPrice(float $bestBidPrice): self
99
    {
100
        $this->bestBidPrice = $bestBidPrice;
101
        return $this;
102
    }
103
104
    /**
105
     * @return float
106
     */
107
    public function getBestBidPrice(): float
108
    {
109
        return $this->bestBidPrice;
110
    }
111
112
    /**
113
     * @param float $bidQuantity
114
     * @return BooktickerAbstract
115
     */
116
    private function setBidQuantity(float $bidQuantity): self
117
    {
118
        $this->bidQuantity = $bidQuantity;
119
        return $this;
120
    }
121
122
    /**
123
     * @return float
124
     */
125
    public function getBidQuantity(): float
126
    {
127
        return $this->bidQuantity;
128
    }
129
130
    /**
131
     * @param float $bestAskPrice
132
     * @return BooktickerAbstract
133
     */
134
    private function setBestAskPrice(float $bestAskPrice): self
135
    {
136
        $this->bestAskPrice = $bestAskPrice;
137
        return $this;
138
    }
139
140
    /**
141
     * @return float
142
     */
143
    public function getBestAskPrice(): float
144
    {
145
        return $this->bestAskPrice;
146
    }
147
148
    /**
149
     * @param float $askQuantity
150
     * @return BooktickerAbstract
151
     */
152
    public function setAskQuantity(float $askQuantity): self
153
    {
154
        $this->askQuantity = $askQuantity;
155
        return $this;
156
    }
157
158
    /**
159
     * @return float
160
     */
161
    public function getAskQuantity(): float
162
    {
163
        return $this->askQuantity;
164
    }
165
166
    /**
167
     * @param string $symbol
168
     * @return BooktickerAbstract
169
     */
170
    public function setSymbol(string $symbol): self
171
    {
172
        $this->symbol = $symbol;
173
        return $this;
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function getSymbol(): string
180
    {
181
        return $this->symbol;
182
    }
183
184
    /**
185
     * @param string $topic
186
     * @return BooktickerAbstract
187
     */
188
    private function setTopic(string $topic): self
189
    {
190
        $this->topic = $topic;
191
        return $this;
192
    }
193
194
    /**
195
     * @return string
196
     */
197
    public function getTopic(): string
198
    {
199
        return $this->topic;
200
    }
201
202
    /**
203
     * @param string $requestTimestamp
204
     * @return BooktickerAbstract
205
     */
206
    private function setRequestTimestamp(string $requestTimestamp): self
207
    {
208
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($requestTimestamp);
0 ignored issues
show
Bug introduced by
$requestTimestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

208
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $requestTimestamp);
Loading history...
209
        return $this;
210
    }
211
212
    /**
213
     * @return \DateTime
214
     */
215
    public function getRequestTimestamp(): \DateTime
216
    {
217
        return $this->requestTimestamp;
218
    }
219
220
    /**
221
     * @param string $type
222
     * @return BooktickerAbstract
223
     */
224
    private function setType(string $type): self
225
    {
226
        $this->type = $type;
227
        return $this;
228
    }
229
230
    /**
231
     * @return string
232
     */
233
    public function getType(): string
234
    {
235
        return $this->type;
236
    }
237
}