Complex classes like CombinedStockbaseStockItem 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 CombinedStockbaseStockItem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class CombinedStockbaseStockItem implements StockItemInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var StockItemInterface |
||
15 | */ |
||
16 | private $magentoStockItem; |
||
17 | |||
18 | /** |
||
19 | * @var float |
||
20 | */ |
||
21 | private $stockbaseQty; |
||
22 | |||
23 | /** |
||
24 | * CombinedStockbaseStockItem constructor. |
||
25 | * @param StockItemInterface $magentoStockItem |
||
26 | * @param float $stockbaseQty |
||
27 | */ |
||
28 | 60 | public function __construct(StockItemInterface $magentoStockItem, $stockbaseQty) |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 1 | public function __call($name, $arguments) |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 5 | public function getQty() |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 1 | public function setQty($qty) |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 1 | public function getItemId() |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 1 | public function setItemId($itemId) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 1 | public function getProductId() |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 1 | public function setProductId($productId) |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | 1 | public function getStockId() |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | 1 | public function setStockId($stockId) |
|
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | 1 | public function getIsInStock() |
|
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 1 | public function setIsInStock($isInStock) |
|
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | 2 | public function getIsQtyDecimal() |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | 2 | public function setIsQtyDecimal($isQtyDecimal) |
|
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | 1 | public function getShowDefaultNotificationMessage() |
|
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | 1 | public function getUseConfigMinQty() |
|
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | 1 | public function setUseConfigMinQty($useConfigMinQty) |
|
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | 1 | public function getMinQty() |
|
183 | |||
184 | /** |
||
185 | * {@inheritdoc} |
||
186 | */ |
||
187 | 1 | public function setMinQty($minQty) |
|
193 | |||
194 | /** |
||
195 | * {@inheritdoc} |
||
196 | */ |
||
197 | 1 | public function getUseConfigMinSaleQty() |
|
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | 1 | public function setUseConfigMinSaleQty($useConfigMinSaleQty) |
|
211 | |||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | 1 | public function getMinSaleQty() |
|
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | 1 | public function setMinSaleQty($minSaleQty) |
|
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | 1 | public function getUseConfigMaxSaleQty() |
|
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | 1 | public function setUseConfigMaxSaleQty($useConfigMaxSaleQty) |
|
247 | |||
248 | /** |
||
249 | * {@inheritdoc} |
||
250 | */ |
||
251 | 1 | public function getMaxSaleQty() |
|
255 | |||
256 | /** |
||
257 | * {@inheritdoc} |
||
258 | */ |
||
259 | 1 | public function setMaxSaleQty($maxSaleQty) |
|
265 | |||
266 | /** |
||
267 | * {@inheritdoc} |
||
268 | */ |
||
269 | 1 | public function getUseConfigBackorders() |
|
273 | |||
274 | /** |
||
275 | * {@inheritdoc} |
||
276 | */ |
||
277 | 1 | public function setUseConfigBackorders($useConfigBackorders) |
|
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | */ |
||
287 | 1 | public function getBackorders() |
|
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | */ |
||
295 | 1 | public function setBackorders($backOrders) |
|
301 | |||
302 | /** |
||
303 | * {@inheritdoc} |
||
304 | */ |
||
305 | 1 | public function getUseConfigNotifyStockQty() |
|
309 | |||
310 | /** |
||
311 | * {@inheritdoc} |
||
312 | */ |
||
313 | 1 | public function setUseConfigNotifyStockQty($useConfigNotifyStockQty) |
|
319 | |||
320 | /** |
||
321 | * {@inheritdoc} |
||
322 | */ |
||
323 | 1 | public function getNotifyStockQty() |
|
327 | |||
328 | /** |
||
329 | * {@inheritdoc} |
||
330 | */ |
||
331 | 1 | public function setNotifyStockQty($notifyStockQty) |
|
337 | |||
338 | /** |
||
339 | * {@inheritdoc} |
||
340 | */ |
||
341 | 1 | public function getUseConfigQtyIncrements() |
|
345 | |||
346 | /** |
||
347 | * {@inheritdoc} |
||
348 | */ |
||
349 | 1 | public function setUseConfigQtyIncrements($useConfigQtyIncrements) |
|
355 | |||
356 | /** |
||
357 | * {@inheritdoc} |
||
358 | */ |
||
359 | 1 | public function getQtyIncrements() |
|
363 | |||
364 | /** |
||
365 | * {@inheritdoc} |
||
366 | */ |
||
367 | 1 | public function setQtyIncrements($qtyIncrements) |
|
373 | |||
374 | /** |
||
375 | * {@inheritdoc} |
||
376 | */ |
||
377 | 1 | public function getUseConfigEnableQtyInc() |
|
381 | |||
382 | /** |
||
383 | * {@inheritdoc} |
||
384 | */ |
||
385 | 1 | public function setUseConfigEnableQtyInc($useConfigEnableQtyInc) |
|
391 | |||
392 | /** |
||
393 | * {@inheritdoc} |
||
394 | */ |
||
395 | 1 | public function getEnableQtyIncrements() |
|
399 | |||
400 | /** |
||
401 | * {@inheritdoc} |
||
402 | */ |
||
403 | 1 | public function setEnableQtyIncrements($enableQtyIncrements) |
|
409 | |||
410 | /** |
||
411 | * {@inheritdoc} |
||
412 | */ |
||
413 | 1 | public function getUseConfigManageStock() |
|
417 | |||
418 | /** |
||
419 | * {@inheritdoc} |
||
420 | */ |
||
421 | 1 | public function setUseConfigManageStock($useConfigManageStock) |
|
427 | |||
428 | /** |
||
429 | * {@inheritdoc} |
||
430 | */ |
||
431 | 1 | public function getManageStock() |
|
435 | |||
436 | /** |
||
437 | * {@inheritdoc} |
||
438 | */ |
||
439 | 1 | public function setManageStock($manageStock) |
|
445 | |||
446 | /** |
||
447 | * {@inheritdoc} |
||
448 | */ |
||
449 | 1 | public function getLowStockDate() |
|
453 | |||
454 | /** |
||
455 | * {@inheritdoc} |
||
456 | */ |
||
457 | 1 | public function setLowStockDate($lowStockDate) |
|
463 | |||
464 | /** |
||
465 | * {@inheritdoc} |
||
466 | */ |
||
467 | 1 | public function getIsDecimalDivided() |
|
471 | |||
472 | /** |
||
473 | * {@inheritdoc} |
||
474 | */ |
||
475 | 1 | public function setIsDecimalDivided($isDecimalDivided) |
|
481 | |||
482 | /** |
||
483 | * {@inheritdoc} |
||
484 | */ |
||
485 | 1 | public function getStockStatusChangedAuto() |
|
489 | |||
490 | /** |
||
491 | * {@inheritdoc} |
||
492 | */ |
||
493 | 1 | public function setStockStatusChangedAuto($stockStatusChangedAuto) |
|
499 | |||
500 | /** |
||
501 | * {@inheritdoc} |
||
502 | */ |
||
503 | 1 | public function getExtensionAttributes() |
|
507 | |||
508 | /** |
||
509 | * {@inheritdoc} |
||
510 | */ |
||
511 | 1 | public function setExtensionAttributes( |
|
518 | } |
||
519 |