Complex classes like LineItemType 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 LineItemType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class LineItemType implements \JsonSerializable |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @property string $itemId |
||
16 | */ |
||
17 | private $itemId = null; |
||
18 | |||
19 | /** |
||
20 | * @property string $name |
||
21 | */ |
||
22 | private $name = null; |
||
23 | |||
24 | /** |
||
25 | * @property string $description |
||
26 | */ |
||
27 | private $description = null; |
||
28 | |||
29 | /** |
||
30 | * @property float $quantity |
||
31 | */ |
||
32 | private $quantity = null; |
||
33 | |||
34 | /** |
||
35 | * @property float $unitPrice |
||
36 | */ |
||
37 | private $unitPrice = null; |
||
38 | |||
39 | /** |
||
40 | * @property boolean $taxable |
||
41 | */ |
||
42 | private $taxable = null; |
||
43 | |||
44 | /** |
||
45 | * @property string $unitOfMeasure |
||
46 | */ |
||
47 | private $unitOfMeasure = null; |
||
48 | |||
49 | /** |
||
50 | * @property string $typeOfSupply |
||
51 | */ |
||
52 | private $typeOfSupply = null; |
||
53 | |||
54 | /** |
||
55 | * @property float $taxRate |
||
56 | */ |
||
57 | private $taxRate = null; |
||
58 | |||
59 | /** |
||
60 | * @property float $taxAmount |
||
61 | */ |
||
62 | private $taxAmount = null; |
||
63 | |||
64 | /** |
||
65 | * @property float $nationalTax |
||
66 | */ |
||
67 | private $nationalTax = null; |
||
68 | |||
69 | /** |
||
70 | * @property float $localTax |
||
71 | */ |
||
72 | private $localTax = null; |
||
73 | |||
74 | /** |
||
75 | * @property float $vatRate |
||
76 | */ |
||
77 | private $vatRate = null; |
||
78 | |||
79 | /** |
||
80 | * @property string $alternateTaxId |
||
81 | */ |
||
82 | private $alternateTaxId = null; |
||
83 | |||
84 | /** |
||
85 | * @property string $alternateTaxType |
||
86 | */ |
||
87 | private $alternateTaxType = null; |
||
88 | |||
89 | /** |
||
90 | * @property string $alternateTaxTypeApplied |
||
91 | */ |
||
92 | private $alternateTaxTypeApplied = null; |
||
93 | |||
94 | /** |
||
95 | * @property float $alternateTaxRate |
||
96 | */ |
||
97 | private $alternateTaxRate = null; |
||
98 | |||
99 | /** |
||
100 | * @property float $alternateTaxAmount |
||
101 | */ |
||
102 | private $alternateTaxAmount = null; |
||
103 | |||
104 | /** |
||
105 | * @property float $totalAmount |
||
106 | */ |
||
107 | private $totalAmount = null; |
||
108 | |||
109 | /** |
||
110 | * @property string $commodityCode |
||
111 | */ |
||
112 | private $commodityCode = null; |
||
113 | |||
114 | /** |
||
115 | * @property string $productCode |
||
116 | */ |
||
117 | private $productCode = null; |
||
118 | |||
119 | /** |
||
120 | * @property string $productSKU |
||
121 | */ |
||
122 | private $productSKU = null; |
||
123 | |||
124 | /** |
||
125 | * @property float $discountRate |
||
126 | */ |
||
127 | private $discountRate = null; |
||
128 | |||
129 | /** |
||
130 | * @property float $discountAmount |
||
131 | */ |
||
132 | private $discountAmount = null; |
||
133 | |||
134 | /** |
||
135 | * @property boolean $taxIncludedInTotal |
||
136 | */ |
||
137 | private $taxIncludedInTotal = null; |
||
138 | |||
139 | /** |
||
140 | * @property boolean $taxIsAfterDiscount |
||
141 | */ |
||
142 | private $taxIsAfterDiscount = null; |
||
143 | |||
144 | /** |
||
145 | * Gets as itemId |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | public function getItemId() |
||
153 | |||
154 | /** |
||
155 | * Sets a new itemId |
||
156 | * |
||
157 | * @param string $itemId |
||
158 | * @return self |
||
159 | */ |
||
160 | public function setItemId($itemId) |
||
165 | |||
166 | /** |
||
167 | * Gets as name |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getName() |
||
175 | |||
176 | /** |
||
177 | * Sets a new name |
||
178 | * |
||
179 | * @param string $name |
||
180 | * @return self |
||
181 | */ |
||
182 | public function setName($name) |
||
187 | |||
188 | /** |
||
189 | * Gets as description |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getDescription() |
||
197 | |||
198 | /** |
||
199 | * Sets a new description |
||
200 | * |
||
201 | * @param string $description |
||
202 | * @return self |
||
203 | */ |
||
204 | public function setDescription($description) |
||
209 | |||
210 | /** |
||
211 | * Gets as quantity |
||
212 | * |
||
213 | * @return float |
||
214 | */ |
||
215 | public function getQuantity() |
||
219 | |||
220 | /** |
||
221 | * Sets a new quantity |
||
222 | * |
||
223 | * @param float $quantity |
||
224 | * @return self |
||
225 | */ |
||
226 | public function setQuantity($quantity) |
||
231 | |||
232 | /** |
||
233 | * Gets as unitPrice |
||
234 | * |
||
235 | * @return float |
||
236 | */ |
||
237 | public function getUnitPrice() |
||
241 | |||
242 | /** |
||
243 | * Sets a new unitPrice |
||
244 | * |
||
245 | * @param float $unitPrice |
||
246 | * @return self |
||
247 | */ |
||
248 | public function setUnitPrice($unitPrice) |
||
253 | |||
254 | /** |
||
255 | * Gets as taxable |
||
256 | * |
||
257 | * @return boolean |
||
258 | */ |
||
259 | public function getTaxable() |
||
263 | |||
264 | /** |
||
265 | * Sets a new taxable |
||
266 | * |
||
267 | * @param boolean $taxable |
||
268 | * @return self |
||
269 | */ |
||
270 | public function setTaxable($taxable) |
||
275 | |||
276 | /** |
||
277 | * Gets as unitOfMeasure |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | public function getUnitOfMeasure() |
||
285 | |||
286 | /** |
||
287 | * Sets a new unitOfMeasure |
||
288 | * |
||
289 | * @param string $unitOfMeasure |
||
290 | * @return self |
||
291 | */ |
||
292 | public function setUnitOfMeasure($unitOfMeasure) |
||
297 | |||
298 | /** |
||
299 | * Gets as typeOfSupply |
||
300 | * |
||
301 | * @return string |
||
302 | */ |
||
303 | public function getTypeOfSupply() |
||
307 | |||
308 | /** |
||
309 | * Sets a new typeOfSupply |
||
310 | * |
||
311 | * @param string $typeOfSupply |
||
312 | * @return self |
||
313 | */ |
||
314 | public function setTypeOfSupply($typeOfSupply) |
||
319 | |||
320 | /** |
||
321 | * Gets as taxRate |
||
322 | * |
||
323 | * @return float |
||
324 | */ |
||
325 | public function getTaxRate() |
||
329 | |||
330 | /** |
||
331 | * Sets a new taxRate |
||
332 | * |
||
333 | * @param float $taxRate |
||
334 | * @return self |
||
335 | */ |
||
336 | public function setTaxRate($taxRate) |
||
341 | |||
342 | /** |
||
343 | * Gets as taxAmount |
||
344 | * |
||
345 | * @return float |
||
346 | */ |
||
347 | public function getTaxAmount() |
||
351 | |||
352 | /** |
||
353 | * Sets a new taxAmount |
||
354 | * |
||
355 | * @param float $taxAmount |
||
356 | * @return self |
||
357 | */ |
||
358 | public function setTaxAmount($taxAmount) |
||
363 | |||
364 | /** |
||
365 | * Gets as nationalTax |
||
366 | * |
||
367 | * @return float |
||
368 | */ |
||
369 | public function getNationalTax() |
||
373 | |||
374 | /** |
||
375 | * Sets a new nationalTax |
||
376 | * |
||
377 | * @param float $nationalTax |
||
378 | * @return self |
||
379 | */ |
||
380 | public function setNationalTax($nationalTax) |
||
385 | |||
386 | /** |
||
387 | * Gets as localTax |
||
388 | * |
||
389 | * @return float |
||
390 | */ |
||
391 | public function getLocalTax() |
||
395 | |||
396 | /** |
||
397 | * Sets a new localTax |
||
398 | * |
||
399 | * @param float $localTax |
||
400 | * @return self |
||
401 | */ |
||
402 | public function setLocalTax($localTax) |
||
407 | |||
408 | /** |
||
409 | * Gets as vatRate |
||
410 | * |
||
411 | * @return float |
||
412 | */ |
||
413 | public function getVatRate() |
||
417 | |||
418 | /** |
||
419 | * Sets a new vatRate |
||
420 | * |
||
421 | * @param float $vatRate |
||
422 | * @return self |
||
423 | */ |
||
424 | public function setVatRate($vatRate) |
||
429 | |||
430 | /** |
||
431 | * Gets as alternateTaxId |
||
432 | * |
||
433 | * @return string |
||
434 | */ |
||
435 | public function getAlternateTaxId() |
||
439 | |||
440 | /** |
||
441 | * Sets a new alternateTaxId |
||
442 | * |
||
443 | * @param string $alternateTaxId |
||
444 | * @return self |
||
445 | */ |
||
446 | public function setAlternateTaxId($alternateTaxId) |
||
451 | |||
452 | /** |
||
453 | * Gets as alternateTaxType |
||
454 | * |
||
455 | * @return string |
||
456 | */ |
||
457 | public function getAlternateTaxType() |
||
461 | |||
462 | /** |
||
463 | * Sets a new alternateTaxType |
||
464 | * |
||
465 | * @param string $alternateTaxType |
||
466 | * @return self |
||
467 | */ |
||
468 | public function setAlternateTaxType($alternateTaxType) |
||
473 | |||
474 | /** |
||
475 | * Gets as alternateTaxTypeApplied |
||
476 | * |
||
477 | * @return string |
||
478 | */ |
||
479 | public function getAlternateTaxTypeApplied() |
||
483 | |||
484 | /** |
||
485 | * Sets a new alternateTaxTypeApplied |
||
486 | * |
||
487 | * @param string $alternateTaxTypeApplied |
||
488 | * @return self |
||
489 | */ |
||
490 | public function setAlternateTaxTypeApplied($alternateTaxTypeApplied) |
||
495 | |||
496 | /** |
||
497 | * Gets as alternateTaxRate |
||
498 | * |
||
499 | * @return float |
||
500 | */ |
||
501 | public function getAlternateTaxRate() |
||
505 | |||
506 | /** |
||
507 | * Sets a new alternateTaxRate |
||
508 | * |
||
509 | * @param float $alternateTaxRate |
||
510 | * @return self |
||
511 | */ |
||
512 | public function setAlternateTaxRate($alternateTaxRate) |
||
517 | |||
518 | /** |
||
519 | * Gets as alternateTaxAmount |
||
520 | * |
||
521 | * @return float |
||
522 | */ |
||
523 | public function getAlternateTaxAmount() |
||
527 | |||
528 | /** |
||
529 | * Sets a new alternateTaxAmount |
||
530 | * |
||
531 | * @param float $alternateTaxAmount |
||
532 | * @return self |
||
533 | */ |
||
534 | public function setAlternateTaxAmount($alternateTaxAmount) |
||
539 | |||
540 | /** |
||
541 | * Gets as totalAmount |
||
542 | * |
||
543 | * @return float |
||
544 | */ |
||
545 | public function getTotalAmount() |
||
549 | |||
550 | /** |
||
551 | * Sets a new totalAmount |
||
552 | * |
||
553 | * @param float $totalAmount |
||
554 | * @return self |
||
555 | */ |
||
556 | public function setTotalAmount($totalAmount) |
||
561 | |||
562 | /** |
||
563 | * Gets as commodityCode |
||
564 | * |
||
565 | * @return string |
||
566 | */ |
||
567 | public function getCommodityCode() |
||
571 | |||
572 | /** |
||
573 | * Sets a new commodityCode |
||
574 | * |
||
575 | * @param string $commodityCode |
||
576 | * @return self |
||
577 | */ |
||
578 | public function setCommodityCode($commodityCode) |
||
583 | |||
584 | /** |
||
585 | * Gets as productCode |
||
586 | * |
||
587 | * @return string |
||
588 | */ |
||
589 | public function getProductCode() |
||
593 | |||
594 | /** |
||
595 | * Sets a new productCode |
||
596 | * |
||
597 | * @param string $productCode |
||
598 | * @return self |
||
599 | */ |
||
600 | public function setProductCode($productCode) |
||
605 | |||
606 | /** |
||
607 | * Gets as productSKU |
||
608 | * |
||
609 | * @return string |
||
610 | */ |
||
611 | public function getProductSKU() |
||
615 | |||
616 | /** |
||
617 | * Sets a new productSKU |
||
618 | * |
||
619 | * @param string $productSKU |
||
620 | * @return self |
||
621 | */ |
||
622 | public function setProductSKU($productSKU) |
||
627 | |||
628 | /** |
||
629 | * Gets as discountRate |
||
630 | * |
||
631 | * @return float |
||
632 | */ |
||
633 | public function getDiscountRate() |
||
637 | |||
638 | /** |
||
639 | * Sets a new discountRate |
||
640 | * |
||
641 | * @param float $discountRate |
||
642 | * @return self |
||
643 | */ |
||
644 | public function setDiscountRate($discountRate) |
||
649 | |||
650 | /** |
||
651 | * Gets as discountAmount |
||
652 | * |
||
653 | * @return float |
||
654 | */ |
||
655 | public function getDiscountAmount() |
||
659 | |||
660 | /** |
||
661 | * Sets a new discountAmount |
||
662 | * |
||
663 | * @param float $discountAmount |
||
664 | * @return self |
||
665 | */ |
||
666 | public function setDiscountAmount($discountAmount) |
||
671 | |||
672 | /** |
||
673 | * Gets as taxIncludedInTotal |
||
674 | * |
||
675 | * @return boolean |
||
676 | */ |
||
677 | public function getTaxIncludedInTotal() |
||
681 | |||
682 | /** |
||
683 | * Sets a new taxIncludedInTotal |
||
684 | * |
||
685 | * @param boolean $taxIncludedInTotal |
||
686 | * @return self |
||
687 | */ |
||
688 | public function setTaxIncludedInTotal($taxIncludedInTotal) |
||
693 | |||
694 | /** |
||
695 | * Gets as taxIsAfterDiscount |
||
696 | * |
||
697 | * @return boolean |
||
698 | */ |
||
699 | public function getTaxIsAfterDiscount() |
||
703 | |||
704 | /** |
||
705 | * Sets a new taxIsAfterDiscount |
||
706 | * |
||
707 | * @param boolean $taxIsAfterDiscount |
||
708 | * @return self |
||
709 | */ |
||
710 | public function setTaxIsAfterDiscount($taxIsAfterDiscount) |
||
715 | |||
716 | |||
717 | // Json Serialize Code |
||
718 | public function jsonSerialize(){ |
||
746 | |||
747 | // Json Set Code |
||
748 | public function set($data) |
||
794 | |||
795 | } |
||
796 | |||
797 |