Complex classes like OrderItem 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 OrderItem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class OrderItem extends \Eccube\Entity\AbstractEntity implements ItemInterface |
||
33 | { |
||
34 | use PointRateTrait; |
||
35 | |||
36 | /** |
||
37 | * Get price IncTax |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getPriceIncTax() |
||
50 | |||
51 | /** |
||
52 | * @return integer |
||
53 | */ |
||
54 | public function getTotalPrice() |
||
58 | |||
59 | /** |
||
60 | * @return integer |
||
61 | */ |
||
62 | public function getOrderItemTypeId() |
||
70 | |||
71 | /** |
||
72 | * 商品明細かどうか. |
||
73 | * |
||
74 | * @return boolean 商品明細の場合 true |
||
75 | */ |
||
76 | public function isProduct() |
||
80 | |||
81 | /** |
||
82 | * 送料明細かどうか. |
||
83 | * |
||
84 | * @return boolean 送料明細の場合 true |
||
85 | */ |
||
86 | public function isDeliveryFee() |
||
90 | |||
91 | /** |
||
92 | * 手数料明細かどうか. |
||
93 | * |
||
94 | * @return boolean 手数料明細の場合 true |
||
95 | */ |
||
96 | public function isCharge() |
||
100 | |||
101 | /** |
||
102 | * 値引き明細かどうか. |
||
103 | * |
||
104 | * @return boolean 値引き明細の場合 true |
||
105 | */ |
||
106 | public function isDiscount() |
||
110 | |||
111 | /** |
||
112 | * 税額明細かどうか. |
||
113 | * |
||
114 | * @return boolean 税額明細の場合 true |
||
115 | */ |
||
116 | public function isTax() |
||
120 | |||
121 | /** |
||
122 | * ポイント明細かどうか. |
||
123 | * |
||
124 | * @return boolean ポイント明細の場合 true |
||
125 | */ |
||
126 | public function isPoint() |
||
130 | |||
131 | /** |
||
132 | * @var integer |
||
133 | * |
||
134 | * @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
||
135 | * @ORM\Id |
||
136 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
137 | */ |
||
138 | private $id; |
||
139 | |||
140 | /** |
||
141 | * @var string |
||
142 | * |
||
143 | * @ORM\Column(name="product_name", type="string", length=255) |
||
144 | */ |
||
145 | private $product_name; |
||
146 | |||
147 | /** |
||
148 | * @var string|null |
||
149 | * |
||
150 | * @ORM\Column(name="product_code", type="string", length=255, nullable=true) |
||
151 | */ |
||
152 | private $product_code; |
||
153 | |||
154 | /** |
||
155 | * @var string|null |
||
156 | * |
||
157 | * @ORM\Column(name="class_name1", type="string", length=255, nullable=true) |
||
158 | */ |
||
159 | private $class_name1; |
||
160 | |||
161 | /** |
||
162 | * @var string|null |
||
163 | * |
||
164 | * @ORM\Column(name="class_name2", type="string", length=255, nullable=true) |
||
165 | */ |
||
166 | private $class_name2; |
||
167 | |||
168 | /** |
||
169 | * @var string|null |
||
170 | * |
||
171 | * @ORM\Column(name="class_category_name1", type="string", length=255, nullable=true) |
||
172 | */ |
||
173 | private $class_category_name1; |
||
174 | |||
175 | /** |
||
176 | * @var string|null |
||
177 | * |
||
178 | * @ORM\Column(name="class_category_name2", type="string", length=255, nullable=true) |
||
179 | */ |
||
180 | private $class_category_name2; |
||
181 | |||
182 | /** |
||
183 | * @var string |
||
184 | * |
||
185 | * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"default":0}) |
||
186 | */ |
||
187 | private $price = 0; |
||
188 | |||
189 | /** |
||
190 | * @var string |
||
191 | * |
||
192 | * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0}) |
||
193 | */ |
||
194 | private $quantity = 0; |
||
195 | |||
196 | /** |
||
197 | * @var string |
||
198 | * |
||
199 | * @ORM\Column(name="tax", type="decimal", precision=10, scale=0, options={"default":0}) |
||
200 | */ |
||
201 | private $tax = 0; |
||
202 | |||
203 | /** |
||
204 | * @var string |
||
205 | * |
||
206 | * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) |
||
207 | */ |
||
208 | private $tax_rate = 0; |
||
209 | |||
210 | /** |
||
211 | * @var int|null |
||
212 | * |
||
213 | * @ORM\Column(name="tax_rule_id", type="smallint", nullable=true, options={"unsigned":true}) |
||
214 | */ |
||
215 | private $tax_rule_id; |
||
216 | |||
217 | /** |
||
218 | * @var string|null |
||
219 | * |
||
220 | * @ORM\Column(name="currency_code", type="string", nullable=true) |
||
221 | */ |
||
222 | private $currency_code; |
||
223 | |||
224 | /** |
||
225 | * @var string|null |
||
226 | * |
||
227 | * @ORM\Column(name="processor_name", type="string", nullable=true) |
||
228 | */ |
||
229 | private $processor_name; |
||
230 | |||
231 | /** |
||
232 | * @var \Eccube\Entity\Order |
||
233 | * |
||
234 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems") |
||
235 | * @ORM\JoinColumns({ |
||
236 | * @ORM\JoinColumn(name="order_id", referencedColumnName="id") |
||
237 | * }) |
||
238 | */ |
||
239 | private $Order; |
||
240 | |||
241 | /** |
||
242 | * @var \Eccube\Entity\Product |
||
243 | * |
||
244 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product") |
||
245 | * @ORM\JoinColumns({ |
||
246 | * @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
||
247 | * }) |
||
248 | */ |
||
249 | private $Product; |
||
250 | |||
251 | /** |
||
252 | * @var \Eccube\Entity\ProductClass |
||
253 | * |
||
254 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass") |
||
255 | * @ORM\JoinColumns({ |
||
256 | * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id") |
||
257 | * }) |
||
258 | */ |
||
259 | private $ProductClass; |
||
260 | |||
261 | /** |
||
262 | * @var \Eccube\Entity\Shipping |
||
263 | * |
||
264 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems") |
||
265 | * @ORM\JoinColumns({ |
||
266 | * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") |
||
267 | * }) |
||
268 | */ |
||
269 | private $Shipping; |
||
270 | |||
271 | /** |
||
272 | * @var \Eccube\Entity\Master\RoundingType |
||
273 | * |
||
274 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType") |
||
275 | * @ORM\JoinColumns({ |
||
276 | * @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id") |
||
277 | * }) |
||
278 | */ |
||
279 | private $RoundingType; |
||
280 | |||
281 | /** |
||
282 | * @var \Eccube\Entity\Master\TaxType |
||
283 | * |
||
284 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType") |
||
285 | * @ORM\JoinColumns({ |
||
286 | * @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id") |
||
287 | * }) |
||
288 | */ |
||
289 | private $TaxType; |
||
290 | |||
291 | /** |
||
292 | * @var \Eccube\Entity\Master\TaxDisplayType |
||
293 | * |
||
294 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType") |
||
295 | * @ORM\JoinColumns({ |
||
296 | * @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id") |
||
297 | * }) |
||
298 | */ |
||
299 | private $TaxDisplayType; |
||
300 | |||
301 | /** |
||
302 | * @var \Eccube\Entity\Master\OrderItemType |
||
303 | * |
||
304 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType") |
||
305 | * @ORM\JoinColumns({ |
||
306 | * @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id") |
||
307 | * }) |
||
308 | */ |
||
309 | private $OrderItemType; |
||
310 | |||
311 | /** |
||
312 | * Get id. |
||
313 | * |
||
314 | * @return int |
||
315 | */ |
||
316 | public function getId() |
||
320 | |||
321 | /** |
||
322 | * Set productName. |
||
323 | * |
||
324 | * @param string $productName |
||
325 | * |
||
326 | * @return OrderItem |
||
327 | */ |
||
328 | public function setProductName($productName) |
||
334 | |||
335 | /** |
||
336 | * Get productName. |
||
337 | * |
||
338 | * @return string |
||
339 | */ |
||
340 | public function getProductName() |
||
344 | |||
345 | /** |
||
346 | * Set productCode. |
||
347 | * |
||
348 | * @param string|null $productCode |
||
349 | * |
||
350 | * @return OrderItem |
||
351 | */ |
||
352 | public function setProductCode($productCode = null) |
||
358 | |||
359 | /** |
||
360 | * Get productCode. |
||
361 | * |
||
362 | * @return string|null |
||
363 | */ |
||
364 | public function getProductCode() |
||
368 | |||
369 | /** |
||
370 | * Set className1. |
||
371 | * |
||
372 | * @param string|null $className1 |
||
373 | * |
||
374 | * @return OrderItem |
||
375 | */ |
||
376 | public function setClassName1($className1 = null) |
||
382 | |||
383 | /** |
||
384 | * Get className1. |
||
385 | * |
||
386 | * @return string|null |
||
387 | */ |
||
388 | public function getClassName1() |
||
392 | |||
393 | /** |
||
394 | * Set className2. |
||
395 | * |
||
396 | * @param string|null $className2 |
||
397 | * |
||
398 | * @return OrderItem |
||
399 | */ |
||
400 | public function setClassName2($className2 = null) |
||
406 | |||
407 | /** |
||
408 | * Get className2. |
||
409 | * |
||
410 | * @return string|null |
||
411 | */ |
||
412 | public function getClassName2() |
||
416 | |||
417 | /** |
||
418 | * Set classCategoryName1. |
||
419 | * |
||
420 | * @param string|null $classCategoryName1 |
||
421 | * |
||
422 | * @return OrderItem |
||
423 | */ |
||
424 | public function setClassCategoryName1($classCategoryName1 = null) |
||
430 | |||
431 | /** |
||
432 | * Get classCategoryName1. |
||
433 | * |
||
434 | * @return string|null |
||
435 | */ |
||
436 | public function getClassCategoryName1() |
||
440 | |||
441 | /** |
||
442 | * Set classCategoryName2. |
||
443 | * |
||
444 | * @param string|null $classCategoryName2 |
||
445 | * |
||
446 | * @return OrderItem |
||
447 | */ |
||
448 | public function setClassCategoryName2($classCategoryName2 = null) |
||
454 | |||
455 | /** |
||
456 | * Get classCategoryName2. |
||
457 | * |
||
458 | * @return string|null |
||
459 | */ |
||
460 | public function getClassCategoryName2() |
||
464 | |||
465 | /** |
||
466 | * Set price. |
||
467 | * |
||
468 | * @param string $price |
||
469 | * |
||
470 | * @return OrderItem |
||
471 | */ |
||
472 | public function setPrice($price) |
||
478 | |||
479 | /** |
||
480 | * Get price. |
||
481 | * |
||
482 | * @return string |
||
483 | */ |
||
484 | public function getPrice() |
||
488 | |||
489 | /** |
||
490 | * Set quantity. |
||
491 | * |
||
492 | * @param string $quantity |
||
493 | * |
||
494 | * @return OrderItem |
||
495 | */ |
||
496 | public function setQuantity($quantity) |
||
502 | |||
503 | /** |
||
504 | * Get quantity. |
||
505 | * |
||
506 | * @return string |
||
507 | */ |
||
508 | public function getQuantity() |
||
512 | |||
513 | /** |
||
514 | * @return string |
||
515 | */ |
||
516 | public function getTax() |
||
520 | |||
521 | /** |
||
522 | * @param string $tax |
||
523 | * |
||
524 | * @return $this |
||
525 | */ |
||
526 | public function setTax($tax) |
||
532 | |||
533 | /** |
||
534 | * Set taxRate. |
||
535 | * |
||
536 | * @param string $taxRate |
||
537 | * |
||
538 | * @return OrderItem |
||
539 | */ |
||
540 | public function setTaxRate($taxRate) |
||
546 | |||
547 | /** |
||
548 | * Get taxRate. |
||
549 | * |
||
550 | * @return string |
||
551 | */ |
||
552 | public function getTaxRate() |
||
556 | |||
557 | /** |
||
558 | * Set taxRuleId. |
||
559 | * |
||
560 | * @param int|null $taxRuleId |
||
561 | * |
||
562 | * @return OrderItem |
||
563 | */ |
||
564 | public function setTaxRuleId($taxRuleId = null) |
||
570 | |||
571 | /** |
||
572 | * Get taxRuleId. |
||
573 | * |
||
574 | * @return int|null |
||
575 | */ |
||
576 | public function getTaxRuleId() |
||
580 | |||
581 | /** |
||
582 | * Get currencyCode. |
||
583 | * |
||
584 | * @return string |
||
585 | */ |
||
586 | public function getCurrencyCode() |
||
590 | |||
591 | /** |
||
592 | * Set currencyCode. |
||
593 | * |
||
594 | * @param string|null $currencyCode |
||
595 | * |
||
596 | * @return OrderItem |
||
597 | */ |
||
598 | public function setCurrencyCode($currencyCode = null) |
||
604 | |||
605 | /** |
||
606 | * Get processorName. |
||
607 | * |
||
608 | * @return string |
||
609 | */ |
||
610 | public function getProcessorName() |
||
614 | |||
615 | /** |
||
616 | * Set processorName. |
||
617 | * |
||
618 | * @param string|null $processorName |
||
619 | * |
||
620 | * @return $this |
||
621 | */ |
||
622 | public function setProcessorName($processorName = null) |
||
628 | |||
629 | /** |
||
630 | * Set order. |
||
631 | * |
||
632 | * @param \Eccube\Entity\Order|null $order |
||
633 | * |
||
634 | * @return OrderItem |
||
635 | */ |
||
636 | public function setOrder(\Eccube\Entity\Order $order = null) |
||
642 | |||
643 | /** |
||
644 | * Get order. |
||
645 | * |
||
646 | * @return \Eccube\Entity\Order|null |
||
647 | */ |
||
648 | public function getOrder() |
||
652 | |||
653 | public function getOrderId() |
||
661 | |||
662 | /** |
||
663 | * Set product. |
||
664 | * |
||
665 | * @param \Eccube\Entity\Product|null $product |
||
666 | * |
||
667 | * @return OrderItem |
||
668 | */ |
||
669 | public function setProduct(\Eccube\Entity\Product $product = null) |
||
675 | |||
676 | /** |
||
677 | * Get product. |
||
678 | * |
||
679 | * @return \Eccube\Entity\Product|null |
||
680 | */ |
||
681 | public function getProduct() |
||
685 | |||
686 | /** |
||
687 | * Set productClass. |
||
688 | * |
||
689 | * @param \Eccube\Entity\ProductClass|null $productClass |
||
690 | * |
||
691 | * @return OrderItem |
||
692 | */ |
||
693 | public function setProductClass(\Eccube\Entity\ProductClass $productClass = null) |
||
699 | |||
700 | /** |
||
701 | * Get productClass. |
||
702 | * |
||
703 | * @return \Eccube\Entity\ProductClass|null |
||
704 | */ |
||
705 | public function getProductClass() |
||
709 | |||
710 | /** |
||
711 | * Set shipping. |
||
712 | * |
||
713 | * @param \Eccube\Entity\Shipping|null $shipping |
||
714 | * |
||
715 | * @return OrderItem |
||
716 | */ |
||
717 | public function setShipping(\Eccube\Entity\Shipping $shipping = null) |
||
723 | |||
724 | /** |
||
725 | * Get shipping. |
||
726 | * |
||
727 | * @return \Eccube\Entity\Shipping|null |
||
728 | */ |
||
729 | public function getShipping() |
||
733 | |||
734 | /** |
||
735 | * @return RoundingType |
||
736 | */ |
||
737 | public function getRoundingType() |
||
741 | |||
742 | /** |
||
743 | * @param RoundingType $RoundingType |
||
744 | */ |
||
745 | public function setRoundingType(RoundingType $RoundingType = null) |
||
751 | |||
752 | /** |
||
753 | * Set taxType |
||
754 | * |
||
755 | * @param \Eccube\Entity\Master\TaxType $taxType |
||
756 | * |
||
757 | * @return OrderItem |
||
758 | */ |
||
759 | public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null) |
||
765 | |||
766 | /** |
||
767 | * Get taxType |
||
768 | * |
||
769 | * @return \Eccube\Entity\Master\TaxType |
||
770 | */ |
||
771 | public function getTaxType() |
||
775 | |||
776 | /** |
||
777 | * Set taxDisplayType |
||
778 | * |
||
779 | * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType |
||
780 | * |
||
781 | * @return OrderItem |
||
782 | */ |
||
783 | public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null) |
||
789 | |||
790 | /** |
||
791 | * Get taxDisplayType |
||
792 | * |
||
793 | * @return \Eccube\Entity\Master\TaxDisplayType |
||
794 | */ |
||
795 | public function getTaxDisplayType() |
||
799 | |||
800 | /** |
||
801 | * Set orderItemType |
||
802 | * |
||
803 | * @param \Eccube\Entity\Master\OrderItemType $orderItemType |
||
804 | * |
||
805 | * @return OrderItem |
||
806 | */ |
||
807 | public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null) |
||
813 | |||
814 | /** |
||
815 | * Get orderItemType |
||
816 | * |
||
817 | * @return \Eccube\Entity\Master\OrderItemType |
||
818 | */ |
||
819 | public function getOrderItemType() |
||
823 | } |
||
824 | } |
||
825 |