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