Total Complexity | 42 |
Total Lines | 507 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like TickersDataItemAbstract often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TickersDataItemAbstract, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class TickersDataItemAbstract extends AbstractResponse |
||
11 | { |
||
12 | /** |
||
13 | * Symbol name |
||
14 | * @var string $symbol |
||
15 | */ |
||
16 | private ?string $symbol; |
||
17 | |||
18 | /** |
||
19 | * Tick direction |
||
20 | * @var string $tickDirection |
||
21 | */ |
||
22 | private ?string $tickDirection; |
||
23 | |||
24 | /** |
||
25 | * Percentage change of market price in the last 24 hours |
||
26 | * @var string $price24hPcnt |
||
27 | */ |
||
28 | private ?float $price24hPcnt; |
||
29 | |||
30 | /** |
||
31 | * Last price |
||
32 | * @var float $lastPrice |
||
33 | */ |
||
34 | private ?float $lastPrice; |
||
35 | |||
36 | /** |
||
37 | * Market price 24 hours ago |
||
38 | * @var float $prevPrice24h |
||
39 | */ |
||
40 | private ?float $prevPrice24h; |
||
41 | |||
42 | /** |
||
43 | * The highest price in the last 24 hours |
||
44 | * @var float $highPrice24h |
||
45 | */ |
||
46 | private ?float $highPrice24h; |
||
47 | |||
48 | /** |
||
49 | * The lowest price in the last 24 hours |
||
50 | * @var float $lowPrice24h |
||
51 | */ |
||
52 | private ?float $lowPrice24h; |
||
53 | |||
54 | /** |
||
55 | * Market price an hour ago |
||
56 | * @var float $prevPrice1h |
||
57 | */ |
||
58 | private ?float $prevPrice1h; |
||
59 | |||
60 | /** |
||
61 | * Mark price |
||
62 | * @var float $markPrice |
||
63 | */ |
||
64 | private ?float $markPrice; |
||
65 | |||
66 | /** |
||
67 | * Index price |
||
68 | * @var float $indexPrice |
||
69 | */ |
||
70 | private ?float $indexPrice; |
||
71 | |||
72 | /** |
||
73 | * Open interest size |
||
74 | * @var float $openInterest |
||
75 | */ |
||
76 | private ?float $openInterest; |
||
77 | |||
78 | /** |
||
79 | * openInterestValue |
||
80 | * @var float $openInterestValue |
||
81 | */ |
||
82 | private ?float $openInterestValue; |
||
83 | |||
84 | /** |
||
85 | * Turnover for 24h |
||
86 | * @var float $turnover24h |
||
87 | */ |
||
88 | private ?float $turnover24h; |
||
89 | |||
90 | /** |
||
91 | * Volume for 24h |
||
92 | * @var float $volume24h |
||
93 | */ |
||
94 | private ?float $volume24h; |
||
95 | |||
96 | /** |
||
97 | * Next funding timestamp (ms) |
||
98 | * @var \DateTime $nextFundingTime |
||
99 | */ |
||
100 | private ?\DateTime $nextFundingTime; |
||
101 | |||
102 | /** |
||
103 | * Funding rate |
||
104 | * @var float $fundingRate |
||
105 | */ |
||
106 | private ?float $fundingRate; |
||
107 | |||
108 | /** |
||
109 | * Best bid price |
||
110 | * @var float $bid1Price |
||
111 | */ |
||
112 | private ?float $bid1Price; |
||
113 | |||
114 | /** |
||
115 | * Best bid size |
||
116 | * @var float $bid1Size |
||
117 | */ |
||
118 | private ?float $bid1Size; |
||
119 | |||
120 | /** |
||
121 | * Best ask price |
||
122 | * @var float $ask1Price |
||
123 | */ |
||
124 | private ?float $ask1Price; |
||
125 | |||
126 | /** |
||
127 | * Best ask size |
||
128 | * @var float $ask1Size |
||
129 | */ |
||
130 | private ?float $ask1Size; |
||
131 | |||
132 | public function __construct(array $data) |
||
133 | { |
||
134 | $this |
||
135 | ->setSymbol($data['symbol'] ?? null) |
||
136 | ->setTickDirection($data['tickDirection'] ?? null) |
||
137 | ->setPrice24hPcnt($data['price24hPcnt'] ?? null) |
||
138 | ->setLastPrice($data['lastPrice'] ?? null) |
||
139 | ->setPrevPrice24h($data['prevPrice24h'] ?? null) |
||
140 | ->setHighPrice24h($data['highPrice24h'] ?? null) |
||
141 | ->setLowPrice24h($data['lowPrice24h'] ?? null) |
||
142 | ->setPrevPrice1h($data['prevPrice1h'] ?? null) |
||
143 | ->setMarkPrice($data['markPrice'] ?? null) |
||
144 | ->setIndexPrice($data['indexPrice'] ?? null) |
||
145 | ->setOpenInterest($data['openInterest'] ?? null) |
||
146 | ->setOpenInterestValue($data['openInterestValue'] ?? null) |
||
147 | ->setTurnover24h($data['turnover24h'] ?? null) |
||
148 | ->setVolume24h($data['volume24h'] ?? null) |
||
149 | ->setNextFundingTime($data['nextFundingTime'] ?? null) |
||
150 | ->setFundingRate($data['fundingRate'] ?? null) |
||
151 | ->setBid1Price($data['bid1Price'] ?? null) |
||
152 | ->setBid1Size($data['bid1Size'] ?? null) |
||
153 | ->setAsk1Price($data['ask1Price'] ?? null) |
||
154 | ->setAsk1Size($data['ask1Size'] ?? null); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param string|null $symbol |
||
159 | * @return self |
||
160 | */ |
||
161 | private function setSymbol(?string $symbol): self |
||
162 | { |
||
163 | $this->symbol = $symbol; |
||
164 | return $this; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @return string|null |
||
169 | */ |
||
170 | public function getSymbol(): ?string |
||
171 | { |
||
172 | return $this->symbol; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @param string|null $tickDirection |
||
177 | * @return self |
||
178 | */ |
||
179 | private function setTickDirection(?string $tickDirection): self |
||
180 | { |
||
181 | $this->tickDirection = $tickDirection; |
||
182 | return $this; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * @return string|null |
||
187 | */ |
||
188 | public function getTickDirection(): ?string |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @param float|null $price24hPcnt |
||
195 | * @return self |
||
196 | */ |
||
197 | private function setPrice24hPcnt(?float $price24hPcnt): self |
||
198 | { |
||
199 | $this->price24hPcnt = $price24hPcnt; |
||
200 | return $this; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return float|null |
||
205 | */ |
||
206 | public function getPrice24hPcnt(): ?float |
||
207 | { |
||
208 | return $this->price24hPcnt; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @param float|null $lastPrice |
||
213 | * @return self |
||
214 | */ |
||
215 | private function setLastPrice(?float $lastPrice): self |
||
216 | { |
||
217 | $this->lastPrice = $lastPrice; |
||
218 | return $this; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * @return float|null |
||
223 | */ |
||
224 | public function getLastPrice(): ?float |
||
225 | { |
||
226 | return $this->lastPrice; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @param float|null $prevPrice24h |
||
231 | * @return self |
||
232 | */ |
||
233 | private function setPrevPrice24h(?float $prevPrice24h): self |
||
234 | { |
||
235 | $this->prevPrice24h = $prevPrice24h; |
||
236 | return $this; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @return float|null |
||
241 | */ |
||
242 | public function getPrevPrice24h(): ?float |
||
243 | { |
||
244 | return $this->prevPrice24h; |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @param float|null $highPrice24h |
||
249 | * @return self |
||
250 | */ |
||
251 | private function setHighPrice24h(?float $highPrice24h): self |
||
252 | { |
||
253 | $this->highPrice24h = $highPrice24h; |
||
254 | return $this; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @return float|null |
||
259 | */ |
||
260 | public function getHighPrice24h(): ?float |
||
261 | { |
||
262 | return $this->highPrice24h; |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * @param float|null $lowPrice24h |
||
267 | * @return self |
||
268 | */ |
||
269 | private function setLowPrice24h(?float $lowPrice24h): self |
||
270 | { |
||
271 | $this->lowPrice24h = $lowPrice24h; |
||
272 | return $this; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @return float|null |
||
277 | */ |
||
278 | public function getLowPrice24h(): ?float |
||
279 | { |
||
280 | return $this->lowPrice24h; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @param float|null $prevPrice1h |
||
285 | * @return self |
||
286 | */ |
||
287 | private function setPrevPrice1h(?float $prevPrice1h): self |
||
288 | { |
||
289 | $this->prevPrice1h = $prevPrice1h; |
||
290 | return $this; |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @return float|null |
||
295 | */ |
||
296 | public function getPrevPrice1h(): ?float |
||
297 | { |
||
298 | return $this->prevPrice1h; |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * @param float|null $markPrice |
||
303 | * @return self |
||
304 | */ |
||
305 | private function setMarkPrice(?float $markPrice): self |
||
306 | { |
||
307 | $this->markPrice = $markPrice; |
||
308 | return $this; |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * @return float|null |
||
313 | */ |
||
314 | public function getMarkPrice(): ?float |
||
315 | { |
||
316 | return $this->markPrice; |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @param float|null $indexPrice |
||
321 | * @return self |
||
322 | */ |
||
323 | private function setIndexPrice(?float $indexPrice): self |
||
324 | { |
||
325 | $this->indexPrice = $indexPrice; |
||
326 | return $this; |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @return float|null |
||
331 | */ |
||
332 | public function getIndexPrice(): ?float |
||
333 | { |
||
334 | return $this->indexPrice; |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * @param float|null $openInterest |
||
339 | * @return self |
||
340 | */ |
||
341 | private function setOpenInterest(?float $openInterest): self |
||
342 | { |
||
343 | $this->openInterest = $openInterest; |
||
344 | return $this; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @return float|null |
||
349 | */ |
||
350 | public function getOpenInterest(): ?float |
||
351 | { |
||
352 | return $this->openInterest; |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * @param float|null $openInterestValue |
||
357 | * @return self |
||
358 | */ |
||
359 | private function setOpenInterestValue(?float $openInterestValue): self |
||
360 | { |
||
361 | $this->openInterestValue = $openInterestValue; |
||
362 | return $this; |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * @return float|null |
||
367 | */ |
||
368 | public function getOpenInterestValue(): ?float |
||
369 | { |
||
370 | return $this->openInterestValue; |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * @param float|null $turnover24h |
||
375 | * @return self |
||
376 | */ |
||
377 | private function setTurnover24h(?float $turnover24h): self |
||
378 | { |
||
379 | $this->turnover24h = $turnover24h; |
||
380 | return $this; |
||
381 | } |
||
382 | |||
383 | /** |
||
384 | * @return float|null |
||
385 | */ |
||
386 | public function getTurnover24h(): ?float |
||
387 | { |
||
388 | return $this->turnover24h; |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * @param float|null $volume24h |
||
393 | * @return self |
||
394 | */ |
||
395 | private function setVolume24h(?float $volume24h): self |
||
396 | { |
||
397 | $this->volume24h = $volume24h; |
||
398 | return $this; |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * @return float |
||
403 | */ |
||
404 | public function getVolume24h(): float |
||
405 | { |
||
406 | return $this->volume24h; |
||
|
|||
407 | } |
||
408 | |||
409 | /** |
||
410 | * @param string|null $nextFundingTime |
||
411 | * @return self |
||
412 | */ |
||
413 | private function setNextFundingTime(?string $nextFundingTime): self |
||
414 | { |
||
415 | if (!empty($nextFundingTime)) { |
||
416 | $this->nextFundingTime = DateTimeHelper::makeFromTimestamp($nextFundingTime); |
||
417 | } |
||
418 | return $this; |
||
419 | } |
||
420 | |||
421 | /** |
||
422 | * @return \DateTime|null |
||
423 | */ |
||
424 | public function getNextFundingTime(): ?\DateTime |
||
425 | { |
||
426 | return $this->nextFundingTime; |
||
427 | } |
||
428 | |||
429 | /** |
||
430 | * @param float|null $fundingRate |
||
431 | * @return self |
||
432 | */ |
||
433 | private function setFundingRate(?float $fundingRate): self |
||
434 | { |
||
435 | $this->fundingRate = $fundingRate; |
||
436 | return $this; |
||
437 | } |
||
438 | |||
439 | /** |
||
440 | * @return float|null |
||
441 | */ |
||
442 | public function getFundingRate(): ?float |
||
443 | { |
||
444 | return $this->fundingRate; |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * @param float|null $bid1Price |
||
449 | * @return self |
||
450 | */ |
||
451 | private function setBid1Price(?float $bid1Price): self |
||
452 | { |
||
453 | $this->bid1Price = $bid1Price; |
||
454 | return $this; |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * @return float|null |
||
459 | */ |
||
460 | public function getBid1Price(): ?float |
||
461 | { |
||
462 | return $this->bid1Price; |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * @param float|null $bid1Size |
||
467 | * @return self |
||
468 | */ |
||
469 | private function setBid1Size(?float $bid1Size): self |
||
470 | { |
||
471 | $this->bid1Size = $bid1Size; |
||
472 | return $this; |
||
473 | } |
||
474 | |||
475 | /** |
||
476 | * @return float|null |
||
477 | */ |
||
478 | public function getBid1Size(): ?float |
||
479 | { |
||
480 | return $this->bid1Size; |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * @param float|null $ask1Price |
||
485 | * @return self |
||
486 | */ |
||
487 | private function setAsk1Price(?float $ask1Price): self |
||
488 | { |
||
489 | $this->ask1Price = $ask1Price; |
||
490 | return $this; |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * @return float|null |
||
495 | */ |
||
496 | public function getAsk1Price(): ?float |
||
499 | } |
||
500 | |||
501 | /** |
||
502 | * @param float|null $ask1Size |
||
503 | * @return self |
||
504 | */ |
||
505 | private function setAsk1Size(?float $ask1Size): self |
||
506 | { |
||
507 | $this->ask1Size = $ask1Size; |
||
508 | return $this; |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * @return float|null |
||
513 | */ |
||
514 | public function getAsk1Size(): ?float |
||
515 | { |
||
516 | return $this->ask1Size; |
||
517 | } |
||
518 | } |