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 |
||
31 | class OrderItem extends \Eccube\Entity\AbstractEntity implements ItemInterface |
||
32 | { |
||
33 | use PointRateTrait; |
||
34 | |||
35 | /** |
||
36 | * Get price IncTax |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getPriceIncTax() |
||
49 | |||
50 | /** |
||
51 | * @return integer |
||
52 | */ |
||
53 | public function getTotalPrice() |
||
57 | |||
58 | /** |
||
59 | * @return integer |
||
60 | */ |
||
61 | public function getOrderItemTypeId() |
||
69 | |||
70 | /** |
||
71 | * 商品明細かどうか. |
||
72 | * |
||
73 | * @return boolean 商品明細の場合 true |
||
74 | */ |
||
75 | public function isProduct() |
||
79 | |||
80 | /** |
||
81 | * 送料明細かどうか. |
||
82 | * |
||
83 | * @return boolean 送料明細の場合 true |
||
84 | */ |
||
85 | public function isDeliveryFee() |
||
89 | |||
90 | /** |
||
91 | * 手数料明細かどうか. |
||
92 | * |
||
93 | * @return boolean 手数料明細の場合 true |
||
94 | */ |
||
95 | public function isCharge() |
||
99 | |||
100 | /** |
||
101 | * 値引き明細かどうか. |
||
102 | * |
||
103 | * @return boolean 値引き明細の場合 true |
||
104 | */ |
||
105 | public function isDiscount() |
||
109 | |||
110 | /** |
||
111 | * 税額明細かどうか. |
||
112 | * |
||
113 | * @return boolean 税額明細の場合 true |
||
114 | */ |
||
115 | public function isTax() |
||
119 | |||
120 | /** |
||
121 | * ポイント明細かどうか. |
||
122 | * |
||
123 | * @return boolean ポイント明細の場合 true |
||
124 | */ |
||
125 | public function isPoint() |
||
129 | |||
130 | /** |
||
131 | * @var integer |
||
132 | * |
||
133 | * @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
||
134 | * @ORM\Id |
||
135 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
136 | */ |
||
137 | private $id; |
||
138 | |||
139 | /** |
||
140 | * @var string |
||
141 | * |
||
142 | * @ORM\Column(name="product_name", type="string", length=255) |
||
143 | */ |
||
144 | private $product_name; |
||
145 | |||
146 | /** |
||
147 | * @var string|null |
||
148 | * |
||
149 | * @ORM\Column(name="product_code", type="string", length=255, nullable=true) |
||
150 | */ |
||
151 | private $product_code; |
||
152 | |||
153 | /** |
||
154 | * @var string|null |
||
155 | * |
||
156 | * @ORM\Column(name="class_name1", type="string", length=255, nullable=true) |
||
157 | */ |
||
158 | private $class_name1; |
||
159 | |||
160 | /** |
||
161 | * @var string|null |
||
162 | * |
||
163 | * @ORM\Column(name="class_name2", type="string", length=255, nullable=true) |
||
164 | */ |
||
165 | private $class_name2; |
||
166 | |||
167 | /** |
||
168 | * @var string|null |
||
169 | * |
||
170 | * @ORM\Column(name="class_category_name1", type="string", length=255, nullable=true) |
||
171 | */ |
||
172 | private $class_category_name1; |
||
173 | |||
174 | /** |
||
175 | * @var string|null |
||
176 | * |
||
177 | * @ORM\Column(name="class_category_name2", type="string", length=255, nullable=true) |
||
178 | */ |
||
179 | private $class_category_name2; |
||
180 | |||
181 | /** |
||
182 | * @var string |
||
183 | * |
||
184 | * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"default":0}) |
||
185 | */ |
||
186 | private $price = 0; |
||
187 | |||
188 | /** |
||
189 | * @var string |
||
190 | * |
||
191 | * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0}) |
||
192 | */ |
||
193 | private $quantity = 0; |
||
194 | |||
195 | /** |
||
196 | * @var string |
||
197 | * |
||
198 | * @ORM\Column(name="tax", type="decimal", precision=10, scale=0, options={"default":0}) |
||
199 | */ |
||
200 | private $tax = 0; |
||
201 | |||
202 | /** |
||
203 | * @var string |
||
204 | * |
||
205 | * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) |
||
206 | */ |
||
207 | private $tax_rate = 0; |
||
208 | |||
209 | /** |
||
210 | * @var string |
||
211 | * |
||
212 | * @ORM\Column(name="tax_adjust", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) |
||
213 | */ |
||
214 | private $tax_adjust = 0; |
||
215 | |||
216 | /** |
||
217 | * @var int|null |
||
218 | * |
||
219 | * @ORM\Column(name="tax_rule_id", type="smallint", nullable=true, options={"unsigned":true}) |
||
220 | */ |
||
221 | private $tax_rule_id; |
||
222 | |||
223 | /** |
||
224 | * @var string|null |
||
225 | * |
||
226 | * @ORM\Column(name="currency_code", type="string", nullable=true) |
||
227 | */ |
||
228 | private $currency_code; |
||
229 | |||
230 | /** |
||
231 | * @var string|null |
||
232 | * |
||
233 | * @ORM\Column(name="processor_name", type="string", nullable=true) |
||
234 | */ |
||
235 | private $processor_name; |
||
236 | |||
237 | /** |
||
238 | * @var \Eccube\Entity\Order |
||
239 | * |
||
240 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems") |
||
241 | * @ORM\JoinColumns({ |
||
242 | * @ORM\JoinColumn(name="order_id", referencedColumnName="id") |
||
243 | * }) |
||
244 | */ |
||
245 | private $Order; |
||
246 | |||
247 | /** |
||
248 | * @var \Eccube\Entity\Product |
||
249 | * |
||
250 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product") |
||
251 | * @ORM\JoinColumns({ |
||
252 | * @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
||
253 | * }) |
||
254 | */ |
||
255 | private $Product; |
||
256 | |||
257 | /** |
||
258 | * @var \Eccube\Entity\ProductClass |
||
259 | * |
||
260 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass") |
||
261 | * @ORM\JoinColumns({ |
||
262 | * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id") |
||
263 | * }) |
||
264 | */ |
||
265 | private $ProductClass; |
||
266 | |||
267 | /** |
||
268 | * @var \Eccube\Entity\Shipping |
||
269 | * |
||
270 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems") |
||
271 | * @ORM\JoinColumns({ |
||
272 | * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") |
||
273 | * }) |
||
274 | */ |
||
275 | private $Shipping; |
||
276 | |||
277 | /** |
||
278 | * @var \Eccube\Entity\Master\RoundingType |
||
279 | * |
||
280 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType") |
||
281 | * @ORM\JoinColumns({ |
||
282 | * @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id") |
||
283 | * }) |
||
284 | */ |
||
285 | private $RoundingType; |
||
286 | |||
287 | /** |
||
288 | * @var \Eccube\Entity\Master\TaxType |
||
289 | * |
||
290 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType") |
||
291 | * @ORM\JoinColumns({ |
||
292 | * @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id") |
||
293 | * }) |
||
294 | */ |
||
295 | private $TaxType; |
||
296 | |||
297 | /** |
||
298 | * @var \Eccube\Entity\Master\TaxDisplayType |
||
299 | * |
||
300 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType") |
||
301 | * @ORM\JoinColumns({ |
||
302 | * @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id") |
||
303 | * }) |
||
304 | */ |
||
305 | private $TaxDisplayType; |
||
306 | |||
307 | /** |
||
308 | * @var \Eccube\Entity\Master\OrderItemType |
||
309 | 46 | * |
|
310 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType") |
||
311 | 46 | * @ORM\JoinColumns({ |
|
312 | * @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id") |
||
313 | * }) |
||
314 | */ |
||
315 | private $OrderItemType; |
||
316 | |||
317 | /** |
||
318 | * Get id. |
||
319 | * |
||
320 | * @return int |
||
321 | 235 | */ |
|
322 | public function getId() |
||
326 | |||
327 | /** |
||
328 | * Set productName. |
||
329 | * |
||
330 | * @param string $productName |
||
331 | * |
||
332 | * @return OrderItem |
||
333 | 80 | */ |
|
334 | public function setProductName($productName) |
||
340 | |||
341 | /** |
||
342 | * Get productName. |
||
343 | * |
||
344 | * @return string |
||
345 | 217 | */ |
|
346 | public function getProductName() |
||
350 | |||
351 | /** |
||
352 | * Set productCode. |
||
353 | * |
||
354 | * @param string|null $productCode |
||
355 | * |
||
356 | * @return OrderItem |
||
357 | 38 | */ |
|
358 | public function setProductCode($productCode = null) |
||
364 | |||
365 | /** |
||
366 | * Get productCode. |
||
367 | * |
||
368 | * @return string|null |
||
369 | 217 | */ |
|
370 | public function getProductCode() |
||
374 | |||
375 | /** |
||
376 | * Set className1. |
||
377 | * |
||
378 | * @param string|null $className1 |
||
379 | * |
||
380 | * @return OrderItem |
||
381 | 20 | */ |
|
382 | public function setClassName1($className1 = null) |
||
388 | |||
389 | /** |
||
390 | * Get className1. |
||
391 | * |
||
392 | * @return string|null |
||
393 | 164 | */ |
|
394 | public function getClassName1() |
||
398 | |||
399 | /** |
||
400 | * Set className2. |
||
401 | * |
||
402 | * @param string|null $className2 |
||
403 | * |
||
404 | * @return OrderItem |
||
405 | 20 | */ |
|
406 | public function setClassName2($className2 = null) |
||
412 | |||
413 | /** |
||
414 | * Get className2. |
||
415 | * |
||
416 | * @return string|null |
||
417 | 217 | */ |
|
418 | public function getClassName2() |
||
422 | |||
423 | /** |
||
424 | * Set classCategoryName1. |
||
425 | * |
||
426 | * @param string|null $classCategoryName1 |
||
427 | * |
||
428 | * @return OrderItem |
||
429 | 24 | */ |
|
430 | public function setClassCategoryName1($classCategoryName1 = null) |
||
436 | |||
437 | /** |
||
438 | * Get classCategoryName1. |
||
439 | * |
||
440 | * @return string|null |
||
441 | 164 | */ |
|
442 | public function getClassCategoryName1() |
||
446 | |||
447 | /** |
||
448 | * Set classCategoryName2. |
||
449 | * |
||
450 | * @param string|null $classCategoryName2 |
||
451 | * |
||
452 | * @return OrderItem |
||
453 | 24 | */ |
|
454 | public function setClassCategoryName2($classCategoryName2 = null) |
||
460 | |||
461 | /** |
||
462 | * Get classCategoryName2. |
||
463 | * |
||
464 | * @return string|null |
||
465 | 284 | */ |
|
466 | public function getClassCategoryName2() |
||
470 | |||
471 | /** |
||
472 | * Set price. |
||
473 | * |
||
474 | * @param string $price |
||
475 | * |
||
476 | * @return OrderItem |
||
477 | 235 | */ |
|
478 | public function setPrice($price) |
||
484 | |||
485 | /** |
||
486 | * Get price. |
||
487 | * |
||
488 | * @return string |
||
489 | 294 | */ |
|
490 | public function getPrice() |
||
494 | |||
495 | /** |
||
496 | * Set quantity. |
||
497 | * |
||
498 | * @param string $quantity |
||
499 | * |
||
500 | * @return OrderItem |
||
501 | 291 | */ |
|
502 | public function setQuantity($quantity) |
||
508 | |||
509 | 264 | /** |
|
510 | * Get quantity. |
||
511 | 264 | * |
|
512 | * @return string |
||
513 | */ |
||
514 | public function getQuantity() |
||
518 | |||
519 | 224 | /** |
|
520 | * @return string |
||
521 | 224 | */ |
|
522 | public function getTax() |
||
526 | |||
527 | /** |
||
528 | * @param string $tax |
||
529 | * |
||
530 | * @return $this |
||
531 | */ |
||
532 | public function setTax($tax) |
||
538 | |||
539 | /** |
||
540 | * Set taxRate. |
||
541 | * |
||
542 | * @param string $taxRate |
||
543 | * |
||
544 | * @return OrderItem |
||
545 | 5 | */ |
|
546 | public function setTaxRate($taxRate) |
||
552 | |||
553 | /** |
||
554 | * Get taxRate. |
||
555 | * |
||
556 | * @return string |
||
557 | 224 | */ |
|
558 | public function getTaxRate() |
||
562 | |||
563 | /** |
||
564 | * Set taxAdjust. |
||
565 | * |
||
566 | * @param string $tax_adjust |
||
567 | * |
||
568 | * @return OrderItem |
||
569 | 207 | */ |
|
570 | public function setTaxAdjust($tax_adjust) |
||
576 | |||
577 | /** |
||
578 | * Get taxAdjust. |
||
579 | * |
||
580 | * @return string |
||
581 | */ |
||
582 | public function getTaxAdjust() |
||
586 | |||
587 | /** |
||
588 | * Set taxRuleId. |
||
589 | * @deprecated 税率設定は受注作成時に決定するため廃止予定 |
||
590 | * |
||
591 | 207 | * @param int|null $taxRuleId |
|
592 | * |
||
593 | 207 | * @return OrderItem |
|
594 | */ |
||
595 | 207 | public function setTaxRuleId($taxRuleId = null) |
|
601 | |||
602 | /** |
||
603 | * Get taxRuleId. |
||
604 | * @deprecated 税率設定は受注作成時に決定するため廃止予定 |
||
605 | 224 | * |
|
606 | * @return int|null |
||
607 | 224 | */ |
|
608 | public function getTaxRuleId() |
||
612 | |||
613 | /** |
||
614 | * Get currencyCode. |
||
615 | * |
||
616 | * @return string |
||
617 | 30 | */ |
|
618 | public function getCurrencyCode() |
||
622 | 4 | ||
623 | /** |
||
624 | 4 | * Set currencyCode. |
|
625 | 4 | * |
|
626 | * @param string|null $currencyCode |
||
627 | * |
||
628 | * @return OrderItem |
||
629 | */ |
||
630 | public function setCurrencyCode($currencyCode = null) |
||
636 | |||
637 | /** |
||
638 | 217 | * Get processorName. |
|
639 | * |
||
640 | 217 | * @return string |
|
641 | */ |
||
642 | 217 | public function getProcessorName() |
|
646 | |||
647 | /** |
||
648 | * Set processorName. |
||
649 | * |
||
650 | 207 | * @param string|null $processorName |
|
651 | * |
||
652 | 207 | * @return $this |
|
653 | */ |
||
654 | public function setProcessorName($processorName = null) |
||
660 | |||
661 | /** |
||
662 | 282 | * Set order. |
|
663 | * |
||
664 | 282 | * @param \Eccube\Entity\Order|null $order |
|
665 | * |
||
666 | 282 | * @return OrderItem |
|
667 | */ |
||
668 | public function setOrder(\Eccube\Entity\Order $order = null) |
||
674 | 227 | ||
675 | /** |
||
676 | 227 | * Get order. |
|
677 | * |
||
678 | * @return \Eccube\Entity\Order|null |
||
679 | */ |
||
680 | public function getOrder() |
||
684 | |||
685 | public function getOrderId() |
||
693 | |||
694 | /** |
||
695 | * Set product. |
||
696 | * |
||
697 | * @param \Eccube\Entity\Product|null $product |
||
698 | 64 | * |
|
699 | * @return OrderItem |
||
700 | 64 | */ |
|
701 | public function setProduct(\Eccube\Entity\Product $product = null) |
||
707 | |||
708 | /** |
||
709 | * Get product. |
||
710 | * |
||
711 | * @return \Eccube\Entity\Product|null |
||
712 | */ |
||
713 | public function getProduct() |
||
717 | |||
718 | 224 | /** |
|
719 | * Set productClass. |
||
720 | * |
||
721 | * @param \Eccube\Entity\ProductClass|null $productClass |
||
722 | * |
||
723 | * @return OrderItem |
||
724 | */ |
||
725 | public function setProductClass(\Eccube\Entity\ProductClass $productClass = null) |
||
731 | |||
732 | 224 | /** |
|
733 | * Get productClass. |
||
734 | * |
||
735 | * @return \Eccube\Entity\ProductClass|null |
||
736 | */ |
||
737 | public function getProductClass() |
||
741 | |||
742 | 207 | /** |
|
743 | * Set shipping. |
||
744 | * |
||
745 | * @param \Eccube\Entity\Shipping|null $shipping |
||
746 | * |
||
747 | * @return OrderItem |
||
748 | */ |
||
749 | public function setShipping(\Eccube\Entity\Shipping $shipping = null) |
||
755 | |||
756 | 224 | /** |
|
757 | * Get shipping. |
||
758 | * |
||
759 | * @return \Eccube\Entity\Shipping|null |
||
760 | */ |
||
761 | public function getShipping() |
||
765 | |||
766 | 207 | /** |
|
767 | * @return RoundingType |
||
768 | */ |
||
769 | public function getRoundingType() |
||
773 | |||
774 | /** |
||
775 | * @param RoundingType $RoundingType |
||
776 | 255 | */ |
|
777 | public function setRoundingType(RoundingType $RoundingType = null) |
||
783 | |||
784 | /** |
||
785 | * Set taxType |
||
786 | * |
||
787 | * @param \Eccube\Entity\Master\TaxType $taxType |
||
788 | 293 | * |
|
789 | * @return OrderItem |
||
790 | 293 | */ |
|
791 | public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null) |
||
797 | |||
798 | /** |
||
799 | * Get taxType |
||
800 | * |
||
801 | * @return \Eccube\Entity\Master\TaxType |
||
802 | */ |
||
803 | public function getTaxType() |
||
807 | |||
808 | /** |
||
809 | * Set taxDisplayType |
||
810 | * |
||
811 | * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType |
||
812 | * |
||
813 | * @return OrderItem |
||
814 | */ |
||
815 | public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null) |
||
821 | |||
822 | /** |
||
823 | * Get taxDisplayType |
||
824 | * |
||
825 | * @return \Eccube\Entity\Master\TaxDisplayType |
||
826 | */ |
||
827 | public function getTaxDisplayType() |
||
831 | |||
832 | /** |
||
833 | * Set orderItemType |
||
834 | * |
||
835 | * @param \Eccube\Entity\Master\OrderItemType $orderItemType |
||
836 | * |
||
837 | * @return OrderItem |
||
838 | */ |
||
839 | public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null) |
||
845 | |||
846 | /** |
||
847 | * Get orderItemType |
||
848 | * |
||
849 | * @return \Eccube\Entity\Master\OrderItemType |
||
850 | */ |
||
851 | public function getOrderItemType() |
||
855 | } |
||
856 | } |
||
857 |