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 | /** |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | private $pictures = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | private $params = []; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function toArray() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getId() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param string $id |
||
| 137 | * |
||
| 138 | * @return $this |
||
| 139 | */ |
||
| 140 | public function setId($id) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return bool |
||
| 149 | */ |
||
| 150 | public function isAvailable() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param bool $available |
||
| 157 | * |
||
| 158 | * @return $this |
||
| 159 | */ |
||
| 160 | public function setAvailable($available) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | public function getUrl() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $url |
||
| 177 | * |
||
| 178 | * @return $this |
||
| 179 | */ |
||
| 180 | public function setUrl($url) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @return float |
||
| 189 | */ |
||
| 190 | public function getPrice() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param float $price |
||
| 197 | * |
||
| 198 | * @return $this |
||
| 199 | */ |
||
| 200 | public function setPrice($price) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return float |
||
| 209 | */ |
||
| 210 | public function getOldPrice() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param float $oldPrice |
||
| 217 | * |
||
| 218 | * @return $this |
||
| 219 | */ |
||
| 220 | public function setOldPrice($oldPrice) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function getCurrencyId() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param string $currencyId |
||
| 237 | * |
||
| 238 | * @return $this |
||
| 239 | */ |
||
| 240 | public function setCurrencyId($currencyId) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return int |
||
| 249 | */ |
||
| 250 | public function getCategoryId() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param int $categoryId |
||
| 257 | * |
||
| 258 | * @return $this |
||
| 259 | */ |
||
| 260 | public function setCategoryId($categoryId) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function getMarketCategory() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param string $marketCategory |
||
| 277 | * |
||
| 278 | * @return $this |
||
| 279 | */ |
||
| 280 | public function setMarketCategory($marketCategory) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return bool |
||
| 289 | */ |
||
| 290 | public function isAdult() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param bool $adult |
||
| 297 | * |
||
| 298 | * @return $this |
||
| 299 | */ |
||
| 300 | public function setAdult($adult) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | public function getSalesNotes() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @param string $salesNotes |
||
| 317 | * |
||
| 318 | * @return $this |
||
| 319 | */ |
||
| 320 | public function setSalesNotes($salesNotes) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @return bool |
||
| 329 | */ |
||
| 330 | public function isManufacturerWarranty() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @param bool $manufacturerWarranty |
||
| 337 | * |
||
| 338 | * @return $this |
||
| 339 | */ |
||
| 340 | public function setManufacturerWarranty($manufacturerWarranty) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return bool |
||
| 349 | */ |
||
| 350 | public function isPickup() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @param bool $pickup |
||
| 357 | * |
||
| 358 | * @return $this |
||
| 359 | */ |
||
| 360 | public function setPickup($pickup) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @return bool |
||
| 369 | */ |
||
| 370 | public function isDownloadable() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param bool $downloadable |
||
| 377 | * |
||
| 378 | * @return $this |
||
| 379 | */ |
||
| 380 | public function setDownloadable($downloadable) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return bool |
||
| 389 | */ |
||
| 390 | public function isDelivery() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param bool $delivery |
||
| 397 | * |
||
| 398 | * @return $this |
||
| 399 | */ |
||
| 400 | public function setDelivery($delivery) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return float |
||
| 409 | */ |
||
| 410 | public function getLocalDeliveryCost() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @param float $localDeliveryCost |
||
| 417 | * |
||
| 418 | * @return $this |
||
| 419 | */ |
||
| 420 | public function setLocalDeliveryCost($localDeliveryCost) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return string |
||
| 429 | */ |
||
| 430 | public function getDescription() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param string $description |
||
| 437 | * |
||
| 438 | * @return $this |
||
| 439 | */ |
||
| 440 | public function setDescription($description) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getCountryOfOrigin() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param string $countryOfOrigin |
||
| 457 | * |
||
| 458 | * @return $this |
||
| 459 | */ |
||
| 460 | public function setCountryOfOrigin($countryOfOrigin) |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @return int |
||
| 469 | */ |
||
| 470 | public function getCpa() |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @param int $cpa |
||
| 477 | * |
||
| 478 | * @return $this |
||
| 479 | */ |
||
| 480 | public function setCpa($cpa) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @return array |
||
| 489 | */ |
||
| 490 | public function getParams() |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @param OfferParam $param |
||
| 497 | * |
||
| 498 | * @return $this |
||
| 499 | */ |
||
| 500 | public function addParam(OfferParam $param) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Add picture |
||
| 509 | * |
||
| 510 | * @param string $url |
||
| 511 | * |
||
| 512 | * @return $this |
||
| 513 | */ |
||
| 514 | public function addPicture($url) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Set pictures |
||
| 525 | * |
||
| 526 | * @param array $pictures |
||
| 527 | * |
||
| 528 | * @return $this |
||
| 529 | */ |
||
| 530 | public function setPictures(array $pictures) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Get picture list |
||
| 539 | * |
||
| 540 | * @return array |
||
| 541 | */ |
||
| 542 | public function getPictures() |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @return array |
||
| 549 | */ |
||
| 550 | abstract protected function getOptions(); |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | private function getHeaderOptions() |
||
| 570 | |||
| 571 | /** |
||
| 572 | * @return array |
||
| 573 | */ |
||
| 574 | private function getFooterOptions() |
||
| 586 | } |
||
| 587 |