Complex classes like Variant 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Variant, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Variant extends Model |
||
| 18 | { |
||
| 19 | use AdminGraphqlApiId; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var int |
||
| 23 | */ |
||
| 24 | protected $productId; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $title; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var float |
||
| 33 | */ |
||
| 34 | protected $price; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $sku; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | protected $position; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | protected $grams; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $inventoryPolicy; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | protected $compareAtPrice; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $fulfillmentService; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | protected $inventoryManagement; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $option1; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | protected $option2; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | protected $option3; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var \DateTimeInterface |
||
| 88 | */ |
||
| 89 | protected $createdAt; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var \DateTimeInterface |
||
| 93 | */ |
||
| 94 | protected $updatedAt; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var bool |
||
| 98 | */ |
||
| 99 | protected $taxable; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var string |
||
| 103 | */ |
||
| 104 | protected $barcode; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var int |
||
| 108 | */ |
||
| 109 | protected $imageId; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var int |
||
| 113 | */ |
||
| 114 | protected $inventoryQuantity; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var float |
||
| 118 | */ |
||
| 119 | protected $weight; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var string |
||
| 123 | */ |
||
| 124 | protected $weightUnit; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var int |
||
| 128 | */ |
||
| 129 | protected $inventoryItemId; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var int |
||
| 133 | */ |
||
| 134 | protected $oldInventoryQuantity; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var bool |
||
| 138 | */ |
||
| 139 | protected $requiresShipping; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return int |
||
| 143 | */ |
||
| 144 | public function getProductId() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param int $productId |
||
| 151 | * |
||
| 152 | * @return Variant |
||
| 153 | */ |
||
| 154 | public function setProductId($productId) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getTitle() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $title |
||
| 171 | * |
||
| 172 | * @return Variant |
||
| 173 | */ |
||
| 174 | public function setTitle($title) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return float |
||
| 183 | */ |
||
| 184 | public function getPrice() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param float $price |
||
| 191 | * |
||
| 192 | * @return Variant |
||
| 193 | */ |
||
| 194 | public function setPrice($price) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function getSku() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $sku |
||
| 211 | * |
||
| 212 | * @return Variant |
||
| 213 | */ |
||
| 214 | public function setSku($sku) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return int |
||
| 223 | */ |
||
| 224 | public function getPosition() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param int $position |
||
| 231 | * |
||
| 232 | * @return Variant |
||
| 233 | */ |
||
| 234 | public function setPosition($position) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return int |
||
| 243 | */ |
||
| 244 | public function getGrams() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param int $grams |
||
| 251 | * |
||
| 252 | * @return Variant |
||
| 253 | */ |
||
| 254 | public function setGrams($grams) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getInventoryPolicy() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $inventoryPolicy |
||
| 271 | * |
||
| 272 | * @return Variant |
||
| 273 | */ |
||
| 274 | public function setInventoryPolicy($inventoryPolicy) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @return string |
||
| 283 | */ |
||
| 284 | public function getCompareAtPrice() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @param string $compareAtPrice |
||
| 291 | * |
||
| 292 | * @return Variant |
||
| 293 | */ |
||
| 294 | public function setCompareAtPrice($compareAtPrice) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getFulfillmentService() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param string $fulfillmentService |
||
| 311 | * |
||
| 312 | * @return Variant |
||
| 313 | */ |
||
| 314 | public function setFulfillmentService($fulfillmentService) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @return string |
||
| 323 | */ |
||
| 324 | public function getInventoryManagement() |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @param string $inventoryManagement |
||
| 331 | * |
||
| 332 | * @return Variant |
||
| 333 | */ |
||
| 334 | public function setInventoryManagement($inventoryManagement) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return string |
||
| 343 | */ |
||
| 344 | public function getOption1() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param string $option1 |
||
| 351 | * |
||
| 352 | * @return Variant |
||
| 353 | */ |
||
| 354 | public function setOption1($option1) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @return string |
||
| 363 | */ |
||
| 364 | public function getOption2() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param string $option2 |
||
| 371 | * |
||
| 372 | * @return Variant |
||
| 373 | */ |
||
| 374 | public function setOption2($option2) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @return string |
||
| 383 | */ |
||
| 384 | public function getOption3() |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @param string $option3 |
||
| 391 | * |
||
| 392 | * @return Variant |
||
| 393 | */ |
||
| 394 | public function setOption3($option3) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @return \DateTimeInterface |
||
| 403 | */ |
||
| 404 | public function getCreatedAt() |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @param \DateTimeInterface $createdAt |
||
| 411 | * |
||
| 412 | * @return Variant |
||
| 413 | */ |
||
| 414 | public function setCreatedAt($createdAt) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return \DateTimeInterface |
||
| 423 | */ |
||
| 424 | public function getUpdatedAt() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param \DateTimeInterface $updatedAt |
||
| 431 | * |
||
| 432 | * @return Variant |
||
| 433 | */ |
||
| 434 | public function setUpdatedAt($updatedAt) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @return bool |
||
| 443 | */ |
||
| 444 | public function isTaxable() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param bool $taxable |
||
| 451 | * |
||
| 452 | * @return Variant |
||
| 453 | */ |
||
| 454 | public function setTaxable($taxable) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @return string |
||
| 463 | */ |
||
| 464 | public function getBarcode() |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param string $barcode |
||
| 471 | * |
||
| 472 | * @return Variant |
||
| 473 | */ |
||
| 474 | public function setBarcode($barcode) |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @return int |
||
| 483 | */ |
||
| 484 | public function getImageId() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @param int $imageId |
||
| 491 | * |
||
| 492 | * @return Variant |
||
| 493 | */ |
||
| 494 | public function setImageId($imageId) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * @return int |
||
| 503 | */ |
||
| 504 | public function getInventoryQuantity() |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @param int $inventoryQuantity |
||
| 511 | * |
||
| 512 | * @return Variant |
||
| 513 | */ |
||
| 514 | public function setInventoryQuantity($inventoryQuantity) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @return float |
||
| 523 | */ |
||
| 524 | public function getWeight() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * @param float $weight |
||
| 531 | * |
||
| 532 | * @return Variant |
||
| 533 | */ |
||
| 534 | public function setWeight($weight) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @return string |
||
| 543 | */ |
||
| 544 | public function getWeightUnit() |
||
| 548 | |||
| 549 | /** |
||
| 550 | * @param string $weightUnit |
||
| 551 | * |
||
| 552 | * @return Variant |
||
| 553 | */ |
||
| 554 | public function setWeightUnit($weightUnit) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * @param int $inventoryItemId |
||
| 563 | */ |
||
| 564 | public function setInventoryItemId($inventoryItemId) |
||
| 568 | |||
| 569 | /** |
||
| 570 | * @return int |
||
| 571 | */ |
||
| 572 | public function getInventoryItemId() |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @return int |
||
| 579 | */ |
||
| 580 | public function getOldInventoryQuantity() |
||
| 584 | |||
| 585 | /** |
||
| 586 | * @param int $oldInventoryQuantity |
||
| 587 | * |
||
| 588 | * @return Variant |
||
| 589 | */ |
||
| 590 | public function setOldInventoryQuantity($oldInventoryQuantity) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * @return bool |
||
| 599 | */ |
||
| 600 | public function isRequiresShipping() |
||
| 604 | |||
| 605 | /** |
||
| 606 | * @param bool $requiresShipping |
||
| 607 | * |
||
| 608 | * @return Variant |
||
| 609 | */ |
||
| 610 | public function setRequiresShipping($requiresShipping) |
||
| 616 | } |