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 string |
||
106 | */ |
||
107 | private $weight; |
||
108 | |||
109 | /** |
||
110 | * @var int |
||
111 | */ |
||
112 | private $cpa; |
||
113 | |||
114 | /** @var string[] */ |
||
115 | private $barcodes; |
||
116 | |||
117 | /** |
||
118 | * @var array |
||
119 | */ |
||
120 | private $pictures = []; |
||
121 | |||
122 | /** |
||
123 | * @var array |
||
124 | */ |
||
125 | private $params = []; |
||
126 | |||
127 | /** |
||
128 | * @var bool |
||
129 | */ |
||
130 | private $store; |
||
131 | |||
132 | /** |
||
133 | * @return array |
||
134 | */ |
||
135 | public function toArray() |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getId() |
||
147 | |||
148 | /** |
||
149 | * @param string $id |
||
150 | * |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function setId($id) |
||
159 | |||
160 | /** |
||
161 | * @return bool |
||
162 | */ |
||
163 | public function isAvailable() |
||
167 | |||
168 | /** |
||
169 | * @param bool $available |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setAvailable($available) |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getUrl() |
||
187 | |||
188 | /** |
||
189 | * @param string $url |
||
190 | * |
||
191 | * @return $this |
||
192 | */ |
||
193 | public function setUrl($url) |
||
199 | |||
200 | /** |
||
201 | * @return float |
||
202 | */ |
||
203 | public function getPrice() |
||
207 | |||
208 | /** |
||
209 | * @param float $price |
||
210 | * |
||
211 | * @return $this |
||
212 | */ |
||
213 | public function setPrice($price) |
||
219 | |||
220 | /** |
||
221 | * @return float |
||
222 | */ |
||
223 | public function getOldPrice() |
||
227 | |||
228 | /** |
||
229 | * @param float $oldPrice |
||
230 | * |
||
231 | * @return $this |
||
232 | */ |
||
233 | public function setOldPrice($oldPrice) |
||
239 | |||
240 | /** |
||
241 | * @return string |
||
242 | */ |
||
243 | public function getCurrencyId() |
||
247 | |||
248 | /** |
||
249 | * @param string $currencyId |
||
250 | * |
||
251 | * @return $this |
||
252 | */ |
||
253 | public function setCurrencyId($currencyId) |
||
259 | |||
260 | /** |
||
261 | * @return int |
||
262 | */ |
||
263 | public function getCategoryId() |
||
267 | |||
268 | /** |
||
269 | * @param int $categoryId |
||
270 | * |
||
271 | * @return $this |
||
272 | */ |
||
273 | public function setCategoryId($categoryId) |
||
279 | |||
280 | /** |
||
281 | * @return string |
||
282 | */ |
||
283 | public function getMarketCategory() |
||
287 | |||
288 | /** |
||
289 | * @param string $marketCategory |
||
290 | * |
||
291 | * @return $this |
||
292 | */ |
||
293 | public function setMarketCategory($marketCategory) |
||
299 | |||
300 | /** |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function isAdult() |
||
307 | |||
308 | /** |
||
309 | * @param bool $adult |
||
310 | * |
||
311 | * @return $this |
||
312 | */ |
||
313 | public function setAdult($adult) |
||
319 | |||
320 | /** |
||
321 | * @return string |
||
322 | */ |
||
323 | public function getSalesNotes() |
||
327 | |||
328 | /** |
||
329 | * @param string $salesNotes |
||
330 | * |
||
331 | * @return $this |
||
332 | */ |
||
333 | public function setSalesNotes($salesNotes) |
||
339 | |||
340 | /** |
||
341 | * @return bool |
||
342 | */ |
||
343 | public function isManufacturerWarranty() |
||
347 | |||
348 | /** |
||
349 | * @param bool $manufacturerWarranty |
||
350 | * |
||
351 | * @return $this |
||
352 | */ |
||
353 | public function setManufacturerWarranty($manufacturerWarranty) |
||
359 | |||
360 | /** |
||
361 | * @return bool |
||
362 | */ |
||
363 | public function isPickup() |
||
367 | |||
368 | /** |
||
369 | * @param bool $pickup |
||
370 | * |
||
371 | * @return $this |
||
372 | */ |
||
373 | public function setPickup($pickup) |
||
379 | |||
380 | /** |
||
381 | * @return bool |
||
382 | */ |
||
383 | public function isDownloadable() |
||
387 | |||
388 | /** |
||
389 | * @param bool $downloadable |
||
390 | * |
||
391 | * @return $this |
||
392 | */ |
||
393 | public function setDownloadable($downloadable) |
||
399 | |||
400 | /** |
||
401 | * @return bool |
||
402 | */ |
||
403 | public function isDelivery() |
||
407 | |||
408 | /** |
||
409 | * @param bool $delivery |
||
410 | * |
||
411 | * @return $this |
||
412 | */ |
||
413 | public function setDelivery($delivery) |
||
419 | |||
420 | /** |
||
421 | * @param bool $store |
||
422 | * |
||
423 | * @return $this |
||
424 | */ |
||
425 | public function setStore($store) |
||
431 | |||
432 | /** |
||
433 | * @return bool |
||
434 | */ |
||
435 | public function isStore() |
||
439 | |||
440 | /** |
||
441 | * @return float |
||
442 | */ |
||
443 | public function getLocalDeliveryCost() |
||
447 | |||
448 | /** |
||
449 | * @param float $localDeliveryCost |
||
450 | * |
||
451 | * @return $this |
||
452 | */ |
||
453 | public function setLocalDeliveryCost($localDeliveryCost) |
||
459 | |||
460 | /** |
||
461 | * @return string |
||
462 | */ |
||
463 | public function getDescription() |
||
467 | |||
468 | /** |
||
469 | * @param string $description |
||
470 | * |
||
471 | * @return $this |
||
472 | */ |
||
473 | public function setDescription($description) |
||
479 | |||
480 | /** |
||
481 | * @return string |
||
482 | */ |
||
483 | public function getCountryOfOrigin() |
||
487 | |||
488 | /** |
||
489 | * @param string $countryOfOrigin |
||
490 | * |
||
491 | * @return $this |
||
492 | */ |
||
493 | public function setCountryOfOrigin($countryOfOrigin) |
||
499 | |||
500 | /** |
||
501 | * @return string |
||
502 | */ |
||
503 | public function getWeight() |
||
507 | |||
508 | /** |
||
509 | * @param string $weight |
||
510 | * |
||
511 | * @return $this |
||
512 | */ |
||
513 | public function setWeight($weight) |
||
519 | |||
520 | /** |
||
521 | * @return int |
||
522 | */ |
||
523 | public function getCpa() |
||
527 | |||
528 | /** |
||
529 | * @param int $cpa |
||
530 | * |
||
531 | * @return $this |
||
532 | */ |
||
533 | public function setCpa($cpa) |
||
539 | |||
540 | /** |
||
541 | * @return array |
||
542 | */ |
||
543 | public function getParams() |
||
547 | |||
548 | /** |
||
549 | * @param OfferParam $param |
||
550 | * |
||
551 | * @return $this |
||
552 | */ |
||
553 | public function addParam(OfferParam $param) |
||
559 | |||
560 | /** |
||
561 | * Add picture |
||
562 | * |
||
563 | * @param string $url |
||
564 | * |
||
565 | * @return $this |
||
566 | */ |
||
567 | public function addPicture($url) |
||
575 | |||
576 | /** |
||
577 | * Set pictures |
||
578 | * |
||
579 | * @param array $pictures |
||
580 | * |
||
581 | * @return $this |
||
582 | */ |
||
583 | public function setPictures(array $pictures) |
||
589 | |||
590 | /** |
||
591 | * Get picture list |
||
592 | * |
||
593 | * @return array |
||
594 | */ |
||
595 | public function getPictures() |
||
599 | |||
600 | /** |
||
601 | * Get list of barcodes of the offer |
||
602 | * |
||
603 | * @return string[] |
||
604 | */ |
||
605 | public function getBarcodes() |
||
609 | |||
610 | /** |
||
611 | * Set list of barcodes for that offer |
||
612 | * |
||
613 | * @param string[] $barcodes |
||
614 | * |
||
615 | * @return $this |
||
616 | */ |
||
617 | public function setBarcodes(array $barcodes = []) |
||
623 | |||
624 | /** |
||
625 | * Add one barcode to the collection of barcodes of this offer |
||
626 | * |
||
627 | * @param string $barcode |
||
628 | * |
||
629 | * @return AbstractOffer |
||
630 | */ |
||
631 | public function addBarcode($barcode) |
||
637 | |||
638 | /** |
||
639 | * @return array |
||
640 | */ |
||
641 | abstract protected function getOptions(); |
||
642 | |||
643 | /** |
||
644 | * @return array |
||
645 | */ |
||
646 | private function getHeaderOptions() |
||
663 | |||
664 | /** |
||
665 | * @return array |
||
666 | */ |
||
667 | private function getFooterOptions() |
||
680 | } |
||
681 |