Complex classes like ArticleDetail 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 ArticleDetail, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class ArticleDetail extends Base |
||
19 | { |
||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $id; |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $number; |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $supplierNumber; |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $additionalText; |
||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $weight; |
||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $width; |
||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $len; |
||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $height; |
||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $ean; |
||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $purchaseUnit; |
||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $descriptionLong; |
||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $referenceUnit; |
||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $packUnit; |
||
72 | /** |
||
73 | * @var string |
||
74 | */ |
||
75 | protected $shippingTime; |
||
76 | /** |
||
77 | * @var Price[] |
||
78 | */ |
||
79 | protected $prices; |
||
80 | /** |
||
81 | * @var ConfiguratorOption[] |
||
82 | */ |
||
83 | protected $configuratorOptions; |
||
84 | /** |
||
85 | * @var ArticleAttribute |
||
86 | */ |
||
87 | protected $attribute; |
||
88 | /** |
||
89 | * @var int |
||
90 | */ |
||
91 | protected $articleId; |
||
92 | /** |
||
93 | * @var int |
||
94 | */ |
||
95 | protected $unitId; |
||
96 | /** |
||
97 | * @var int |
||
98 | */ |
||
99 | protected $kind; |
||
100 | /** |
||
101 | * @var int |
||
102 | */ |
||
103 | protected $inStock; |
||
104 | /** |
||
105 | * @var int |
||
106 | */ |
||
107 | protected $position; |
||
108 | /** |
||
109 | * @var int |
||
110 | */ |
||
111 | protected $minPurchase; |
||
112 | /** |
||
113 | * @var int |
||
114 | */ |
||
115 | protected $purchaseSteps; |
||
116 | /** |
||
117 | * @var int |
||
118 | */ |
||
119 | protected $maxPurchase; |
||
120 | /** |
||
121 | * @var string |
||
122 | */ |
||
123 | protected $releaseDate; |
||
124 | /** |
||
125 | * @var bool |
||
126 | */ |
||
127 | protected $active; |
||
128 | /** |
||
129 | * @var bool |
||
130 | */ |
||
131 | protected $shippingFree; |
||
132 | |||
133 | /** |
||
134 | * @return int |
||
135 | */ |
||
136 | public function getId() |
||
140 | |||
141 | /** |
||
142 | * @param int $id |
||
143 | * |
||
144 | * @return ArticleDetail |
||
145 | */ |
||
146 | 2 | public function setId($id) |
|
152 | |||
153 | /** |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getNumber() |
||
160 | |||
161 | /** |
||
162 | * @param string $number |
||
163 | * |
||
164 | * @return ArticleDetail |
||
165 | */ |
||
166 | public function setNumber($number) |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getSupplierNumber() |
||
180 | |||
181 | /** |
||
182 | * @param string $supplierNumber |
||
183 | * |
||
184 | * @return ArticleDetail |
||
185 | */ |
||
186 | public function setSupplierNumber($supplierNumber) |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getAdditionalText() |
||
200 | |||
201 | /** |
||
202 | * @param string $additionalText |
||
203 | * |
||
204 | * @return ArticleDetail |
||
205 | */ |
||
206 | public function setAdditionalText($additionalText) |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getWeight() |
||
220 | |||
221 | /** |
||
222 | * @param string $weight |
||
223 | * |
||
224 | * @return ArticleDetail |
||
225 | */ |
||
226 | public function setWeight($weight) |
||
232 | |||
233 | /** |
||
234 | * @return string |
||
235 | */ |
||
236 | public function getWidth() |
||
240 | |||
241 | /** |
||
242 | * @param string $width |
||
243 | * |
||
244 | * @return ArticleDetail |
||
245 | */ |
||
246 | public function setWidth($width) |
||
252 | |||
253 | /** |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getLen() |
||
260 | |||
261 | /** |
||
262 | * @param string $len |
||
263 | * |
||
264 | * @return ArticleDetail |
||
265 | */ |
||
266 | public function setLen($len) |
||
272 | |||
273 | /** |
||
274 | * @return string |
||
275 | */ |
||
276 | public function getHeight() |
||
280 | |||
281 | /** |
||
282 | * @param string $height |
||
283 | * |
||
284 | * @return ArticleDetail |
||
285 | */ |
||
286 | public function setHeight($height) |
||
292 | |||
293 | /** |
||
294 | * @return string |
||
295 | */ |
||
296 | public function getEan() |
||
300 | |||
301 | /** |
||
302 | * @param string $ean |
||
303 | * |
||
304 | * @return ArticleDetail |
||
305 | */ |
||
306 | public function setEan($ean) |
||
312 | |||
313 | /** |
||
314 | * @return string |
||
315 | */ |
||
316 | public function getPurchaseUnit() |
||
320 | |||
321 | /** |
||
322 | * @param string $purchaseUnit |
||
323 | * |
||
324 | * @return ArticleDetail |
||
325 | */ |
||
326 | public function setPurchaseUnit($purchaseUnit) |
||
332 | |||
333 | /** |
||
334 | * @return string |
||
335 | */ |
||
336 | public function getDescriptionLong() |
||
340 | |||
341 | /** |
||
342 | * @param string $descriptionLong |
||
343 | * |
||
344 | * @return ArticleDetail |
||
345 | */ |
||
346 | public function setDescriptionLong($descriptionLong) |
||
352 | |||
353 | /** |
||
354 | * @return string |
||
355 | */ |
||
356 | public function getReferenceUnit() |
||
360 | |||
361 | /** |
||
362 | * @param string $referenceUnit |
||
363 | * |
||
364 | * @return ArticleDetail |
||
365 | */ |
||
366 | public function setReferenceUnit($referenceUnit) |
||
372 | |||
373 | /** |
||
374 | * @return string |
||
375 | */ |
||
376 | public function getPackUnit() |
||
380 | |||
381 | /** |
||
382 | * @param string $packUnit |
||
383 | * |
||
384 | * @return ArticleDetail |
||
385 | */ |
||
386 | public function setPackUnit($packUnit) |
||
392 | |||
393 | /** |
||
394 | * @return string |
||
395 | */ |
||
396 | public function getShippingTime() |
||
400 | |||
401 | /** |
||
402 | * @param string $shippingTime |
||
403 | * |
||
404 | * @return ArticleDetail |
||
405 | */ |
||
406 | public function setShippingTime($shippingTime) |
||
412 | |||
413 | /** |
||
414 | * @return Price[] |
||
415 | */ |
||
416 | public function getPrices() |
||
420 | |||
421 | /** |
||
422 | * @param Price[] $prices |
||
423 | * |
||
424 | * @return ArticleDetail |
||
425 | */ |
||
426 | public function setPrices($prices) |
||
432 | |||
433 | /** |
||
434 | * @return ConfiguratorOption[] |
||
435 | */ |
||
436 | public function getConfiguratorOptions() |
||
440 | |||
441 | /** |
||
442 | * @param ConfiguratorOption[] $configuratorOptions |
||
443 | * |
||
444 | * @return ArticleDetail |
||
445 | */ |
||
446 | public function setConfiguratorOptions($configuratorOptions) |
||
452 | |||
453 | /** |
||
454 | * @return \Neta\Shopware\SDK\Entity\ArticleAttribute |
||
455 | */ |
||
456 | 1 | public function getAttribute(): ?ArticleAttribute |
|
460 | |||
461 | /** |
||
462 | * @param \Neta\Shopware\SDK\Entity\ArticleAttribute|array $value |
||
463 | * |
||
464 | * @return \Neta\Shopware\SDK\Entity\ArticleDetail |
||
465 | */ |
||
466 | 1 | public function setAttribute($value) |
|
480 | |||
481 | /** |
||
482 | * @return int |
||
483 | */ |
||
484 | public function getArticleId() |
||
488 | |||
489 | /** |
||
490 | * @param int $articleId |
||
491 | * |
||
492 | * @return ArticleDetail |
||
493 | */ |
||
494 | public function setArticleId($articleId) |
||
500 | |||
501 | /** |
||
502 | * @return int |
||
503 | */ |
||
504 | public function getUnitId() |
||
508 | |||
509 | /** |
||
510 | * @param int $unitId |
||
511 | * |
||
512 | * @return ArticleDetail |
||
513 | */ |
||
514 | public function setUnitId($unitId) |
||
520 | |||
521 | /** |
||
522 | * @return int |
||
523 | */ |
||
524 | public function getKind() |
||
528 | |||
529 | /** |
||
530 | * @param int $kind |
||
531 | * |
||
532 | * @return ArticleDetail |
||
533 | */ |
||
534 | public function setKind($kind) |
||
540 | |||
541 | /** |
||
542 | * @return int |
||
543 | */ |
||
544 | public function getInStock() |
||
548 | |||
549 | /** |
||
550 | * @param int $inStock |
||
551 | * |
||
552 | * @return ArticleDetail |
||
553 | */ |
||
554 | public function setInStock($inStock) |
||
560 | |||
561 | /** |
||
562 | * @return int |
||
563 | */ |
||
564 | public function getPosition() |
||
568 | |||
569 | /** |
||
570 | * @param int $position |
||
571 | * |
||
572 | * @return ArticleDetail |
||
573 | */ |
||
574 | public function setPosition($position) |
||
580 | |||
581 | /** |
||
582 | * @return int |
||
583 | */ |
||
584 | public function getMinPurchase() |
||
588 | |||
589 | /** |
||
590 | * @param int $minPurchase |
||
591 | * |
||
592 | * @return ArticleDetail |
||
593 | */ |
||
594 | public function setMinPurchase($minPurchase) |
||
600 | |||
601 | /** |
||
602 | * @return int |
||
603 | */ |
||
604 | public function getPurchaseSteps() |
||
608 | |||
609 | /** |
||
610 | * @param int $purchaseSteps |
||
611 | * |
||
612 | * @return ArticleDetail |
||
613 | */ |
||
614 | public function setPurchaseSteps($purchaseSteps) |
||
620 | |||
621 | /** |
||
622 | * @return int |
||
623 | */ |
||
624 | public function getMaxPurchase() |
||
628 | |||
629 | /** |
||
630 | * @param int $maxPurchase |
||
631 | * |
||
632 | * @return ArticleDetail |
||
633 | */ |
||
634 | public function setMaxPurchase($maxPurchase) |
||
640 | |||
641 | /** |
||
642 | * @return string |
||
643 | */ |
||
644 | public function getReleaseDate() |
||
648 | |||
649 | /** |
||
650 | * @param string $releaseDate |
||
651 | * |
||
652 | * @return ArticleDetail |
||
653 | */ |
||
654 | public function setReleaseDate($releaseDate) |
||
660 | |||
661 | /** |
||
662 | * @return bool |
||
663 | */ |
||
664 | public function isActive() |
||
668 | |||
669 | /** |
||
670 | * @param bool $active |
||
671 | * |
||
672 | * @return ArticleDetail |
||
673 | */ |
||
674 | public function setActive($active) |
||
680 | |||
681 | /** |
||
682 | * @return bool |
||
683 | */ |
||
684 | public function isShippingFree() |
||
688 | |||
689 | /** |
||
690 | * @param bool $shippingFree |
||
691 | * |
||
692 | * @return ArticleDetail |
||
693 | */ |
||
694 | public function setShippingFree($shippingFree) |
||
700 | } |
||
701 |