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 | 273 | public function getPriceIncTax() |
|
49 | |||
50 | /** |
||
51 | * @return integer |
||
52 | */ |
||
53 | 67 | public function getTotalPrice() |
|
57 | |||
58 | /** |
||
59 | * @return integer |
||
60 | */ |
||
61 | 280 | public function getOrderItemTypeId() |
|
69 | |||
70 | /** |
||
71 | * 商品明細かどうか. |
||
72 | * |
||
73 | * @return boolean 商品明細の場合 true |
||
74 | */ |
||
75 | 279 | public function isProduct() |
|
79 | |||
80 | /** |
||
81 | * 送料明細かどうか. |
||
82 | * |
||
83 | * @return boolean 送料明細の場合 true |
||
84 | */ |
||
85 | 268 | public function isDeliveryFee() |
|
89 | |||
90 | /** |
||
91 | * 手数料明細かどうか. |
||
92 | * |
||
93 | * @return boolean 手数料明細の場合 true |
||
94 | */ |
||
95 | 262 | public function isCharge() |
|
99 | |||
100 | /** |
||
101 | * 値引き明細かどうか. |
||
102 | * |
||
103 | * @return boolean 値引き明細の場合 true |
||
104 | */ |
||
105 | 262 | public function isDiscount() |
|
109 | |||
110 | /** |
||
111 | * 税額明細かどうか. |
||
112 | * |
||
113 | * @return boolean 税額明細の場合 true |
||
114 | */ |
||
115 | 20 | public function isTax() |
|
119 | |||
120 | /** |
||
121 | * ポイント明細かどうか. |
||
122 | * |
||
123 | * @return boolean ポイント明細の場合 true |
||
124 | */ |
||
125 | 263 | 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 int|null |
||
211 | * |
||
212 | * @ORM\Column(name="tax_rule_id", type="smallint", nullable=true, options={"unsigned":true}) |
||
213 | */ |
||
214 | private $tax_rule_id; |
||
215 | |||
216 | /** |
||
217 | * @var string|null |
||
218 | * |
||
219 | * @ORM\Column(name="currency_code", type="string", nullable=true) |
||
220 | */ |
||
221 | private $currency_code; |
||
222 | |||
223 | /** |
||
224 | * @var \Eccube\Entity\Order |
||
225 | * |
||
226 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems") |
||
227 | * @ORM\JoinColumns({ |
||
228 | * @ORM\JoinColumn(name="order_id", referencedColumnName="id") |
||
229 | * }) |
||
230 | */ |
||
231 | private $Order; |
||
232 | |||
233 | /** |
||
234 | * @var \Eccube\Entity\Product |
||
235 | * |
||
236 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product") |
||
237 | * @ORM\JoinColumns({ |
||
238 | * @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
||
239 | * }) |
||
240 | */ |
||
241 | private $Product; |
||
242 | |||
243 | /** |
||
244 | * @var \Eccube\Entity\ProductClass |
||
245 | * |
||
246 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass") |
||
247 | * @ORM\JoinColumns({ |
||
248 | * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id") |
||
249 | * }) |
||
250 | */ |
||
251 | private $ProductClass; |
||
252 | |||
253 | /** |
||
254 | * @var \Eccube\Entity\Shipping |
||
255 | * |
||
256 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems") |
||
257 | * @ORM\JoinColumns({ |
||
258 | * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") |
||
259 | * }) |
||
260 | */ |
||
261 | private $Shipping; |
||
262 | |||
263 | /** |
||
264 | * @var \Eccube\Entity\Master\RoundingType |
||
265 | * |
||
266 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType") |
||
267 | * @ORM\JoinColumns({ |
||
268 | * @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id") |
||
269 | * }) |
||
270 | */ |
||
271 | private $RoundingType; |
||
272 | |||
273 | /** |
||
274 | * @var \Eccube\Entity\Master\TaxType |
||
275 | * |
||
276 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType") |
||
277 | * @ORM\JoinColumns({ |
||
278 | * @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id") |
||
279 | * }) |
||
280 | */ |
||
281 | private $TaxType; |
||
282 | |||
283 | /** |
||
284 | * @var \Eccube\Entity\Master\TaxDisplayType |
||
285 | * |
||
286 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType") |
||
287 | * @ORM\JoinColumns({ |
||
288 | * @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id") |
||
289 | * }) |
||
290 | */ |
||
291 | private $TaxDisplayType; |
||
292 | |||
293 | /** |
||
294 | * @var \Eccube\Entity\Master\OrderItemType |
||
295 | * |
||
296 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType") |
||
297 | * @ORM\JoinColumns({ |
||
298 | * @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id") |
||
299 | * }) |
||
300 | */ |
||
301 | private $OrderItemType; |
||
302 | |||
303 | /** |
||
304 | * Get id. |
||
305 | * |
||
306 | * @return int |
||
307 | */ |
||
308 | 46 | public function getId() |
|
312 | |||
313 | /** |
||
314 | * Set productName. |
||
315 | * |
||
316 | * @param string $productName |
||
317 | * |
||
318 | * @return OrderItem |
||
319 | */ |
||
320 | 233 | public function setProductName($productName) |
|
326 | |||
327 | /** |
||
328 | * Get productName. |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | 79 | public function getProductName() |
|
336 | |||
337 | /** |
||
338 | * Set productCode. |
||
339 | * |
||
340 | * @param string|null $productCode |
||
341 | * |
||
342 | * @return OrderItem |
||
343 | */ |
||
344 | 215 | public function setProductCode($productCode = null) |
|
350 | |||
351 | /** |
||
352 | * Get productCode. |
||
353 | * |
||
354 | * @return string|null |
||
355 | */ |
||
356 | 37 | public function getProductCode() |
|
360 | |||
361 | /** |
||
362 | * Set className1. |
||
363 | * |
||
364 | * @param string|null $className1 |
||
365 | * |
||
366 | * @return OrderItem |
||
367 | */ |
||
368 | 215 | public function setClassName1($className1 = null) |
|
374 | |||
375 | /** |
||
376 | * Get className1. |
||
377 | * |
||
378 | * @return string|null |
||
379 | */ |
||
380 | 19 | public function getClassName1() |
|
384 | |||
385 | /** |
||
386 | * Set className2. |
||
387 | * |
||
388 | * @param string|null $className2 |
||
389 | * |
||
390 | * @return OrderItem |
||
391 | */ |
||
392 | 152 | public function setClassName2($className2 = null) |
|
398 | |||
399 | /** |
||
400 | * Get className2. |
||
401 | * |
||
402 | * @return string|null |
||
403 | */ |
||
404 | 19 | public function getClassName2() |
|
408 | |||
409 | /** |
||
410 | * Set classCategoryName1. |
||
411 | * |
||
412 | * @param string|null $classCategoryName1 |
||
413 | * |
||
414 | * @return OrderItem |
||
415 | */ |
||
416 | 215 | public function setClassCategoryName1($classCategoryName1 = null) |
|
422 | |||
423 | /** |
||
424 | * Get classCategoryName1. |
||
425 | * |
||
426 | * @return string|null |
||
427 | */ |
||
428 | 23 | public function getClassCategoryName1() |
|
432 | |||
433 | /** |
||
434 | * Set classCategoryName2. |
||
435 | * |
||
436 | * @param string|null $classCategoryName2 |
||
437 | * |
||
438 | * @return OrderItem |
||
439 | */ |
||
440 | 153 | public function setClassCategoryName2($classCategoryName2 = null) |
|
446 | |||
447 | /** |
||
448 | * Get classCategoryName2. |
||
449 | * |
||
450 | * @return string|null |
||
451 | */ |
||
452 | 23 | public function getClassCategoryName2() |
|
456 | |||
457 | /** |
||
458 | * Set price. |
||
459 | * |
||
460 | * @param string $price |
||
461 | * |
||
462 | * @return OrderItem |
||
463 | */ |
||
464 | 282 | public function setPrice($price) |
|
470 | |||
471 | /** |
||
472 | * Get price. |
||
473 | * |
||
474 | * @return string |
||
475 | */ |
||
476 | 233 | public function getPrice() |
|
480 | |||
481 | /** |
||
482 | * Set quantity. |
||
483 | * |
||
484 | * @param string $quantity |
||
485 | * |
||
486 | * @return OrderItem |
||
487 | */ |
||
488 | 292 | public function setQuantity($quantity) |
|
494 | |||
495 | /** |
||
496 | * Get quantity. |
||
497 | * |
||
498 | * @return string |
||
499 | */ |
||
500 | 289 | public function getQuantity() |
|
504 | |||
505 | /** |
||
506 | * @return string |
||
507 | */ |
||
508 | 262 | public function getTax() |
|
512 | |||
513 | /** |
||
514 | * @param string $tax |
||
515 | * |
||
516 | * @return $this |
||
517 | */ |
||
518 | 222 | public function setTax($tax) |
|
524 | |||
525 | /** |
||
526 | * Set taxRate. |
||
527 | * |
||
528 | * @param string $taxRate |
||
529 | * |
||
530 | * @return OrderItem |
||
531 | */ |
||
532 | 222 | public function setTaxRate($taxRate) |
|
538 | |||
539 | /** |
||
540 | * Get taxRate. |
||
541 | * |
||
542 | * @return string |
||
543 | */ |
||
544 | 4 | public function getTaxRate() |
|
548 | |||
549 | /** |
||
550 | * Set taxRuleId. |
||
551 | * |
||
552 | * @param int|null $taxRuleId |
||
553 | * |
||
554 | * @return OrderItem |
||
555 | */ |
||
556 | 222 | public function setTaxRuleId($taxRuleId = null) |
|
562 | |||
563 | /** |
||
564 | * Get taxRuleId. |
||
565 | * |
||
566 | * @return int|null |
||
567 | */ |
||
568 | 205 | public function getTaxRuleId() |
|
572 | |||
573 | /** |
||
574 | * Get currencyCode. |
||
575 | * |
||
576 | * @return string |
||
577 | */ |
||
578 | public function getCurrencyCode() |
||
582 | |||
583 | /** |
||
584 | * Set currencyCode. |
||
585 | * |
||
586 | * @param string|null $currencyCode |
||
587 | * |
||
588 | * @return OrderItem |
||
589 | */ |
||
590 | 205 | public function setCurrencyCode($currencyCode = null) |
|
596 | |||
597 | /** |
||
598 | * Set order. |
||
599 | * |
||
600 | * @param \Eccube\Entity\Order|null $order |
||
601 | * |
||
602 | * @return OrderItem |
||
603 | */ |
||
604 | 222 | public function setOrder(\Eccube\Entity\Order $order = null) |
|
610 | |||
611 | /** |
||
612 | * Get order. |
||
613 | * |
||
614 | * @return \Eccube\Entity\Order|null |
||
615 | */ |
||
616 | 30 | public function getOrder() |
|
620 | |||
621 | 4 | public function getOrderId() |
|
629 | |||
630 | /** |
||
631 | * Set product. |
||
632 | * |
||
633 | * @param \Eccube\Entity\Product|null $product |
||
634 | * |
||
635 | * @return OrderItem |
||
636 | */ |
||
637 | 215 | public function setProduct(\Eccube\Entity\Product $product = null) |
|
643 | |||
644 | /** |
||
645 | * Get product. |
||
646 | * |
||
647 | * @return \Eccube\Entity\Product|null |
||
648 | */ |
||
649 | 205 | public function getProduct() |
|
653 | |||
654 | /** |
||
655 | * Set productClass. |
||
656 | * |
||
657 | * @param \Eccube\Entity\ProductClass|null $productClass |
||
658 | * |
||
659 | * @return OrderItem |
||
660 | */ |
||
661 | 280 | public function setProductClass(\Eccube\Entity\ProductClass $productClass = null) |
|
667 | |||
668 | /** |
||
669 | * Get productClass. |
||
670 | * |
||
671 | * @return \Eccube\Entity\ProductClass|null |
||
672 | */ |
||
673 | 225 | public function getProductClass() |
|
677 | |||
678 | /** |
||
679 | * Set shipping. |
||
680 | * |
||
681 | * @param \Eccube\Entity\Shipping|null $shipping |
||
682 | * |
||
683 | * @return OrderItem |
||
684 | */ |
||
685 | 216 | public function setShipping(\Eccube\Entity\Shipping $shipping = null) |
|
691 | |||
692 | /** |
||
693 | * Get shipping. |
||
694 | * |
||
695 | * @return \Eccube\Entity\Shipping|null |
||
696 | */ |
||
697 | 64 | public function getShipping() |
|
701 | |||
702 | /** |
||
703 | * @return RoundingType |
||
704 | */ |
||
705 | public function getRoundingType() |
||
709 | |||
710 | /** |
||
711 | * @param RoundingType $RoundingType |
||
712 | */ |
||
713 | 222 | public function setRoundingType(RoundingType $RoundingType = null) |
|
719 | |||
720 | /** |
||
721 | * Set taxType |
||
722 | * |
||
723 | * @param \Eccube\Entity\Master\TaxType $taxType |
||
724 | * |
||
725 | * @return OrderItem |
||
726 | */ |
||
727 | 222 | public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null) |
|
733 | |||
734 | /** |
||
735 | * Get taxType |
||
736 | * |
||
737 | * @return \Eccube\Entity\Master\TaxType |
||
738 | */ |
||
739 | 205 | public function getTaxType() |
|
743 | |||
744 | /** |
||
745 | * Set taxDisplayType |
||
746 | * |
||
747 | * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType |
||
748 | * |
||
749 | * @return OrderItem |
||
750 | */ |
||
751 | 222 | public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null) |
|
757 | |||
758 | /** |
||
759 | * Get taxDisplayType |
||
760 | * |
||
761 | * @return \Eccube\Entity\Master\TaxDisplayType |
||
762 | */ |
||
763 | 205 | public function getTaxDisplayType() |
|
767 | |||
768 | /** |
||
769 | * Set orderItemType |
||
770 | * |
||
771 | * @param \Eccube\Entity\Master\OrderItemType $orderItemType |
||
772 | * |
||
773 | * @return OrderItem |
||
774 | */ |
||
775 | 253 | public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null) |
|
781 | |||
782 | /** |
||
783 | * Get orderItemType |
||
784 | * |
||
785 | * @return \Eccube\Entity\Master\OrderItemType |
||
786 | */ |
||
787 | 291 | public function getOrderItemType() |
|
791 | } |
||
792 |