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