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 | * @return array |
||
124 | */ |
||
125 | public function toArray() |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getId() |
||
137 | |||
138 | /** |
||
139 | * @param string $id |
||
140 | * |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setId($id) |
||
149 | |||
150 | /** |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function isAvailable() |
||
157 | |||
158 | /** |
||
159 | * @param bool $available |
||
160 | * |
||
161 | * @return $this |
||
162 | */ |
||
163 | public function setAvailable($available) |
||
169 | |||
170 | /** |
||
171 | * @return string |
||
172 | */ |
||
173 | public function getUrl() |
||
177 | |||
178 | /** |
||
179 | * @param string $url |
||
180 | * |
||
181 | * @return $this |
||
182 | */ |
||
183 | public function setUrl($url) |
||
189 | |||
190 | /** |
||
191 | * @return float |
||
192 | */ |
||
193 | public function getPrice() |
||
197 | |||
198 | /** |
||
199 | * @param float $price |
||
200 | * |
||
201 | * @return $this |
||
202 | */ |
||
203 | public function setPrice($price) |
||
209 | |||
210 | /** |
||
211 | * @return float |
||
212 | */ |
||
213 | public function getOldPrice() |
||
217 | |||
218 | /** |
||
219 | * @param float $oldPrice |
||
220 | * |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function setOldPrice($oldPrice) |
||
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getCurrencyId() |
||
237 | |||
238 | /** |
||
239 | * @param string $currencyId |
||
240 | * |
||
241 | * @return $this |
||
242 | */ |
||
243 | public function setCurrencyId($currencyId) |
||
249 | |||
250 | /** |
||
251 | * @return int |
||
252 | */ |
||
253 | public function getCategoryId() |
||
257 | |||
258 | /** |
||
259 | * @param int $categoryId |
||
260 | * |
||
261 | * @return $this |
||
262 | */ |
||
263 | public function setCategoryId($categoryId) |
||
269 | |||
270 | /** |
||
271 | * @return string |
||
272 | */ |
||
273 | public function getMarketCategory() |
||
277 | |||
278 | /** |
||
279 | * @param string $marketCategory |
||
280 | * |
||
281 | * @return $this |
||
282 | */ |
||
283 | public function setMarketCategory($marketCategory) |
||
289 | |||
290 | /** |
||
291 | * @return bool |
||
292 | */ |
||
293 | public function isAdult() |
||
297 | |||
298 | /** |
||
299 | * @param bool $adult |
||
300 | * |
||
301 | * @return $this |
||
302 | */ |
||
303 | public function setAdult($adult) |
||
309 | |||
310 | /** |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getSalesNotes() |
||
317 | |||
318 | /** |
||
319 | * @param string $salesNotes |
||
320 | * |
||
321 | * @return $this |
||
322 | */ |
||
323 | public function setSalesNotes($salesNotes) |
||
329 | |||
330 | /** |
||
331 | * @return bool |
||
332 | */ |
||
333 | public function isManufacturerWarranty() |
||
337 | |||
338 | /** |
||
339 | * @param bool $manufacturerWarranty |
||
340 | * |
||
341 | * @return $this |
||
342 | */ |
||
343 | public function setManufacturerWarranty($manufacturerWarranty) |
||
349 | |||
350 | /** |
||
351 | * @return bool |
||
352 | */ |
||
353 | public function isPickup() |
||
357 | |||
358 | /** |
||
359 | * @param bool $pickup |
||
360 | * |
||
361 | * @return $this |
||
362 | */ |
||
363 | public function setPickup($pickup) |
||
369 | |||
370 | /** |
||
371 | * @return bool |
||
372 | */ |
||
373 | public function isDownloadable() |
||
377 | |||
378 | /** |
||
379 | * @param bool $downloadable |
||
380 | * |
||
381 | * @return $this |
||
382 | */ |
||
383 | public function setDownloadable($downloadable) |
||
389 | |||
390 | /** |
||
391 | * @return bool |
||
392 | */ |
||
393 | public function isDelivery() |
||
397 | |||
398 | /** |
||
399 | * @param bool $delivery |
||
400 | * |
||
401 | * @return $this |
||
402 | */ |
||
403 | public function setDelivery($delivery) |
||
409 | |||
410 | /** |
||
411 | * @return float |
||
412 | */ |
||
413 | public function getLocalDeliveryCost() |
||
417 | |||
418 | /** |
||
419 | * @param float $localDeliveryCost |
||
420 | * |
||
421 | * @return $this |
||
422 | */ |
||
423 | public function setLocalDeliveryCost($localDeliveryCost) |
||
429 | |||
430 | /** |
||
431 | * @return string |
||
432 | */ |
||
433 | public function getDescription() |
||
437 | |||
438 | /** |
||
439 | * @param string $description |
||
440 | * |
||
441 | * @return $this |
||
442 | */ |
||
443 | public function setDescription($description) |
||
449 | |||
450 | /** |
||
451 | * @return string |
||
452 | */ |
||
453 | public function getCountryOfOrigin() |
||
457 | |||
458 | /** |
||
459 | * @param string $countryOfOrigin |
||
460 | * |
||
461 | * @return $this |
||
462 | */ |
||
463 | public function setCountryOfOrigin($countryOfOrigin) |
||
469 | |||
470 | /** |
||
471 | * @return int |
||
472 | */ |
||
473 | public function getCpa() |
||
477 | |||
478 | /** |
||
479 | * @param int $cpa |
||
480 | * |
||
481 | * @return $this |
||
482 | */ |
||
483 | public function setCpa($cpa) |
||
489 | |||
490 | /** |
||
491 | * @return array |
||
492 | */ |
||
493 | public function getParams() |
||
497 | |||
498 | /** |
||
499 | * @param OfferParam $param |
||
500 | * |
||
501 | * @return $this |
||
502 | */ |
||
503 | public function addParam(OfferParam $param) |
||
509 | |||
510 | /** |
||
511 | * Add picture |
||
512 | * |
||
513 | * @param string $url |
||
514 | * |
||
515 | * @return $this |
||
516 | */ |
||
517 | public function addPicture($url) |
||
525 | |||
526 | /** |
||
527 | * Set pictures |
||
528 | * |
||
529 | * @param array $pictures |
||
530 | * |
||
531 | * @return $this |
||
532 | */ |
||
533 | public function setPictures(array $pictures) |
||
539 | |||
540 | /** |
||
541 | * Get picture list |
||
542 | * |
||
543 | * @return array |
||
544 | */ |
||
545 | public function getPictures() |
||
549 | |||
550 | /** |
||
551 | * Get list of barcodes of the offer |
||
552 | * |
||
553 | * @return string[] |
||
554 | */ |
||
555 | public function getBarcodes() |
||
559 | |||
560 | /** |
||
561 | * Set list of barcodes for that offer |
||
562 | * |
||
563 | * @param string[] $barcodes |
||
564 | * |
||
565 | * @return $this |
||
566 | */ |
||
567 | public function setBarcodes(array $barcodes = []) |
||
573 | |||
574 | /** |
||
575 | * Add one barcode to the collection of barcodes of this offer |
||
576 | * |
||
577 | * @param string $barcode |
||
578 | * |
||
579 | * @return AbstractOffer |
||
580 | */ |
||
581 | public function addBarcode($barcode) |
||
587 | |||
588 | /** |
||
589 | * @return array |
||
590 | */ |
||
591 | abstract protected function getOptions(); |
||
592 | |||
593 | /** |
||
594 | * @return array |
||
595 | */ |
||
596 | private function getHeaderOptions() |
||
611 | |||
612 | /** |
||
613 | * @return array |
||
614 | */ |
||
615 | private function getFooterOptions() |
||
628 | } |
||
629 |