Complex classes like AbstractOffer 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 AbstractOffer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | abstract class AbstractOffer implements OfferInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $id; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var bool |
||
| 26 | */ |
||
| 27 | private $available; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $url; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var float |
||
| 36 | */ |
||
| 37 | private $price; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var float |
||
| 41 | */ |
||
| 42 | private $oldPrice; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private $currencyId; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | private $categoryId; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $marketCategory; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | private $adult; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | private $salesNotes; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var bool |
||
| 71 | */ |
||
| 72 | private $manufacturerWarranty; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | private $pickup; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var bool |
||
| 81 | */ |
||
| 82 | private $downloadable; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var bool |
||
| 86 | */ |
||
| 87 | private $delivery; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var float |
||
| 91 | */ |
||
| 92 | private $localDeliveryCost; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | private $description; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | private $countryOfOrigin; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var int |
||
| 106 | */ |
||
| 107 | private $cpa; |
||
| 108 | |||
| 109 | /** @var string[] */ |
||
| 110 | private $barcodes; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | private $pictures = []; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | private $params = []; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var bool |
||
| 124 | */ |
||
| 125 | private $store; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return array |
||
| 129 | */ |
||
| 130 | public function toArray() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | public function getId() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @param string $id |
||
| 145 | * |
||
| 146 | * @return $this |
||
| 147 | */ |
||
| 148 | public function setId($id) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @return bool |
||
| 157 | */ |
||
| 158 | public function isAvailable() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param bool $available |
||
| 165 | * |
||
| 166 | * @return $this |
||
| 167 | */ |
||
| 168 | public function setAvailable($available) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | public function getUrl() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param string $url |
||
| 185 | * |
||
| 186 | * @return $this |
||
| 187 | */ |
||
| 188 | public function setUrl($url) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return float |
||
| 197 | */ |
||
| 198 | public function getPrice() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @param float $price |
||
| 205 | * |
||
| 206 | * @return $this |
||
| 207 | */ |
||
| 208 | public function setPrice($price) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return float |
||
| 217 | */ |
||
| 218 | public function getOldPrice() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param float $oldPrice |
||
| 225 | * |
||
| 226 | * @return $this |
||
| 227 | */ |
||
| 228 | public function setOldPrice($oldPrice) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return string |
||
| 237 | */ |
||
| 238 | public function getCurrencyId() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param string $currencyId |
||
| 245 | * |
||
| 246 | * @return $this |
||
| 247 | */ |
||
| 248 | public function setCurrencyId($currencyId) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @return int |
||
| 257 | */ |
||
| 258 | public function getCategoryId() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @param int $categoryId |
||
| 265 | * |
||
| 266 | * @return $this |
||
| 267 | */ |
||
| 268 | public function setCategoryId($categoryId) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @return string |
||
| 277 | */ |
||
| 278 | public function getMarketCategory() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @param string $marketCategory |
||
| 285 | * |
||
| 286 | * @return $this |
||
| 287 | */ |
||
| 288 | public function setMarketCategory($marketCategory) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @return bool |
||
| 297 | */ |
||
| 298 | public function isAdult() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @param bool $adult |
||
| 305 | * |
||
| 306 | * @return $this |
||
| 307 | */ |
||
| 308 | public function setAdult($adult) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getSalesNotes() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @param string $salesNotes |
||
| 325 | * |
||
| 326 | * @return $this |
||
| 327 | */ |
||
| 328 | public function setSalesNotes($salesNotes) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @return bool |
||
| 337 | */ |
||
| 338 | public function isManufacturerWarranty() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @param bool $manufacturerWarranty |
||
| 345 | * |
||
| 346 | * @return $this |
||
| 347 | */ |
||
| 348 | public function setManufacturerWarranty($manufacturerWarranty) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return bool |
||
| 357 | */ |
||
| 358 | public function isPickup() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param bool $pickup |
||
| 365 | * |
||
| 366 | * @return $this |
||
| 367 | */ |
||
| 368 | public function setPickup($pickup) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return bool |
||
| 377 | */ |
||
| 378 | public function isDownloadable() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @param bool $downloadable |
||
| 385 | * |
||
| 386 | * @return $this |
||
| 387 | */ |
||
| 388 | public function setDownloadable($downloadable) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @return bool |
||
| 397 | */ |
||
| 398 | public function isDelivery() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @param bool $delivery |
||
| 405 | * |
||
| 406 | * @return $this |
||
| 407 | */ |
||
| 408 | public function setDelivery($delivery) |
||
| 414 | |||
| 415 | |||
| 416 | /** |
||
| 417 | * @param bool $store |
||
| 418 | * |
||
| 419 | * @return $this |
||
| 420 | */ |
||
| 421 | public function setStore($store) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return bool |
||
| 430 | */ |
||
| 431 | public function isStore() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return float |
||
| 438 | */ |
||
| 439 | public function getLocalDeliveryCost() |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @param float $localDeliveryCost |
||
| 446 | * |
||
| 447 | * @return $this |
||
| 448 | */ |
||
| 449 | public function setLocalDeliveryCost($localDeliveryCost) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @return string |
||
| 458 | */ |
||
| 459 | public function getDescription() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @param string $description |
||
| 466 | * |
||
| 467 | * @return $this |
||
| 468 | */ |
||
| 469 | public function setDescription($description) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * @return string |
||
| 478 | */ |
||
| 479 | public function getCountryOfOrigin() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @param string $countryOfOrigin |
||
| 486 | * |
||
| 487 | * @return $this |
||
| 488 | */ |
||
| 489 | public function setCountryOfOrigin($countryOfOrigin) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @return int |
||
| 498 | */ |
||
| 499 | public function getCpa() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @param int $cpa |
||
| 506 | * |
||
| 507 | * @return $this |
||
| 508 | */ |
||
| 509 | public function setCpa($cpa) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @return array |
||
| 518 | */ |
||
| 519 | public function getParams() |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param OfferParam $param |
||
| 526 | * |
||
| 527 | * @return $this |
||
| 528 | */ |
||
| 529 | public function addParam(OfferParam $param) |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Add picture |
||
| 538 | * |
||
| 539 | * @param string $url |
||
| 540 | * |
||
| 541 | * @return $this |
||
| 542 | */ |
||
| 543 | public function addPicture($url) |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Set pictures |
||
| 554 | * |
||
| 555 | * @param array $pictures |
||
| 556 | * |
||
| 557 | * @return $this |
||
| 558 | */ |
||
| 559 | public function setPictures(array $pictures) |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Get picture list |
||
| 568 | * |
||
| 569 | * @return array |
||
| 570 | */ |
||
| 571 | public function getPictures() |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Get list of barcodes of the offer |
||
| 578 | * |
||
| 579 | * @return string[] |
||
| 580 | */ |
||
| 581 | public function getBarcodes() |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Set list of barcodes for that offer |
||
| 588 | * |
||
| 589 | * @param string[] $barcodes |
||
| 590 | * |
||
| 591 | * @return $this |
||
| 592 | */ |
||
| 593 | public function setBarcodes(array $barcodes = []) |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Add one barcode to the collection of barcodes of this offer |
||
| 602 | * |
||
| 603 | * @param string $barcode |
||
| 604 | * |
||
| 605 | * @return AbstractOffer |
||
| 606 | */ |
||
| 607 | public function addBarcode($barcode) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @return array |
||
| 616 | */ |
||
| 617 | abstract protected function getOptions(); |
||
| 618 | |||
| 619 | /** |
||
| 620 | * @return array |
||
| 621 | */ |
||
| 622 | private function getHeaderOptions() |
||
| 638 | |||
| 639 | /** |
||
| 640 | * @return array |
||
| 641 | */ |
||
| 642 | private function getFooterOptions() |
||
| 655 | } |
||
| 656 |