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 \Eccube\Entity\Order |
||
226 | * |
||
227 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems") |
||
228 | * @ORM\JoinColumns({ |
||
229 | * @ORM\JoinColumn(name="order_id", referencedColumnName="id") |
||
230 | * }) |
||
231 | */ |
||
232 | private $Order; |
||
233 | |||
234 | /** |
||
235 | * @var \Eccube\Entity\Product |
||
236 | * |
||
237 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product") |
||
238 | * @ORM\JoinColumns({ |
||
239 | * @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
||
240 | * }) |
||
241 | */ |
||
242 | private $Product; |
||
243 | |||
244 | /** |
||
245 | * @var \Eccube\Entity\ProductClass |
||
246 | * |
||
247 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass") |
||
248 | * @ORM\JoinColumns({ |
||
249 | * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id") |
||
250 | * }) |
||
251 | */ |
||
252 | private $ProductClass; |
||
253 | |||
254 | /** |
||
255 | * @var \Eccube\Entity\Shipping |
||
256 | * |
||
257 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems") |
||
258 | * @ORM\JoinColumns({ |
||
259 | * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") |
||
260 | * }) |
||
261 | */ |
||
262 | private $Shipping; |
||
263 | |||
264 | /** |
||
265 | * @var \Eccube\Entity\Master\RoundingType |
||
266 | * |
||
267 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType") |
||
268 | * @ORM\JoinColumns({ |
||
269 | * @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id") |
||
270 | * }) |
||
271 | */ |
||
272 | private $RoundingType; |
||
273 | |||
274 | /** |
||
275 | * @var \Eccube\Entity\Master\TaxType |
||
276 | * |
||
277 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType") |
||
278 | * @ORM\JoinColumns({ |
||
279 | * @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id") |
||
280 | * }) |
||
281 | */ |
||
282 | private $TaxType; |
||
283 | |||
284 | /** |
||
285 | * @var \Eccube\Entity\Master\TaxDisplayType |
||
286 | * |
||
287 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType") |
||
288 | * @ORM\JoinColumns({ |
||
289 | * @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id") |
||
290 | * }) |
||
291 | */ |
||
292 | private $TaxDisplayType; |
||
293 | |||
294 | /** |
||
295 | * @var \Eccube\Entity\Master\OrderItemType |
||
296 | * |
||
297 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType") |
||
298 | * @ORM\JoinColumns({ |
||
299 | * @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id") |
||
300 | * }) |
||
301 | */ |
||
302 | private $OrderItemType; |
||
303 | |||
304 | /** |
||
305 | * Get id. |
||
306 | * |
||
307 | * @return int |
||
308 | */ |
||
309 | public function getId() |
||
313 | |||
314 | /** |
||
315 | * Set productName. |
||
316 | * |
||
317 | * @param string $productName |
||
318 | * |
||
319 | * @return OrderItem |
||
320 | */ |
||
321 | public function setProductName($productName) |
||
327 | |||
328 | /** |
||
329 | * Get productName. |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | public function getProductName() |
||
337 | |||
338 | /** |
||
339 | * Set productCode. |
||
340 | * |
||
341 | * @param string|null $productCode |
||
342 | * |
||
343 | * @return OrderItem |
||
344 | */ |
||
345 | public function setProductCode($productCode = null) |
||
351 | |||
352 | /** |
||
353 | * Get productCode. |
||
354 | * |
||
355 | * @return string|null |
||
356 | */ |
||
357 | public function getProductCode() |
||
361 | |||
362 | /** |
||
363 | * Set className1. |
||
364 | * |
||
365 | * @param string|null $className1 |
||
366 | * |
||
367 | * @return OrderItem |
||
368 | */ |
||
369 | public function setClassName1($className1 = null) |
||
375 | |||
376 | /** |
||
377 | * Get className1. |
||
378 | * |
||
379 | * @return string|null |
||
380 | */ |
||
381 | public function getClassName1() |
||
385 | |||
386 | /** |
||
387 | * Set className2. |
||
388 | * |
||
389 | * @param string|null $className2 |
||
390 | * |
||
391 | * @return OrderItem |
||
392 | */ |
||
393 | public function setClassName2($className2 = null) |
||
399 | |||
400 | /** |
||
401 | * Get className2. |
||
402 | * |
||
403 | * @return string|null |
||
404 | */ |
||
405 | public function getClassName2() |
||
409 | |||
410 | /** |
||
411 | * Set classCategoryName1. |
||
412 | * |
||
413 | * @param string|null $classCategoryName1 |
||
414 | * |
||
415 | * @return OrderItem |
||
416 | */ |
||
417 | public function setClassCategoryName1($classCategoryName1 = null) |
||
423 | |||
424 | /** |
||
425 | * Get classCategoryName1. |
||
426 | * |
||
427 | * @return string|null |
||
428 | */ |
||
429 | public function getClassCategoryName1() |
||
433 | |||
434 | /** |
||
435 | * Set classCategoryName2. |
||
436 | * |
||
437 | * @param string|null $classCategoryName2 |
||
438 | * |
||
439 | * @return OrderItem |
||
440 | */ |
||
441 | public function setClassCategoryName2($classCategoryName2 = null) |
||
447 | |||
448 | /** |
||
449 | * Get classCategoryName2. |
||
450 | * |
||
451 | * @return string|null |
||
452 | */ |
||
453 | public function getClassCategoryName2() |
||
457 | |||
458 | /** |
||
459 | * Set price. |
||
460 | * |
||
461 | * @param string $price |
||
462 | * |
||
463 | * @return OrderItem |
||
464 | */ |
||
465 | public function setPrice($price) |
||
471 | |||
472 | /** |
||
473 | * Get price. |
||
474 | * |
||
475 | * @return string |
||
476 | */ |
||
477 | public function getPrice() |
||
481 | |||
482 | /** |
||
483 | * Set quantity. |
||
484 | * |
||
485 | * @param string $quantity |
||
486 | * |
||
487 | * @return OrderItem |
||
488 | */ |
||
489 | public function setQuantity($quantity) |
||
495 | |||
496 | /** |
||
497 | * Get quantity. |
||
498 | * |
||
499 | * @return string |
||
500 | */ |
||
501 | public function getQuantity() |
||
505 | |||
506 | /** |
||
507 | * @return string |
||
508 | */ |
||
509 | public function getTax() |
||
513 | |||
514 | /** |
||
515 | * @param string $tax |
||
516 | * |
||
517 | * @return $this |
||
518 | */ |
||
519 | public function setTax($tax) |
||
525 | |||
526 | /** |
||
527 | * Set taxRate. |
||
528 | * |
||
529 | * @param string $taxRate |
||
530 | * |
||
531 | * @return OrderItem |
||
532 | */ |
||
533 | public function setTaxRate($taxRate) |
||
539 | |||
540 | /** |
||
541 | * Get taxRate. |
||
542 | * |
||
543 | * @return string |
||
544 | */ |
||
545 | public function getTaxRate() |
||
549 | |||
550 | /** |
||
551 | * Set taxRuleId. |
||
552 | * |
||
553 | * @param int|null $taxRuleId |
||
554 | * |
||
555 | * @return OrderItem |
||
556 | */ |
||
557 | public function setTaxRuleId($taxRuleId = null) |
||
563 | |||
564 | /** |
||
565 | * Get taxRuleId. |
||
566 | * |
||
567 | * @return int|null |
||
568 | */ |
||
569 | public function getTaxRuleId() |
||
573 | |||
574 | /** |
||
575 | * Get currencyCode. |
||
576 | * |
||
577 | * @return string |
||
578 | */ |
||
579 | public function getCurrencyCode() |
||
583 | |||
584 | /** |
||
585 | * Set currencyCode. |
||
586 | * |
||
587 | * @param string|null $currencyCode |
||
588 | * |
||
589 | * @return OrderItem |
||
590 | */ |
||
591 | public function setCurrencyCode($currencyCode = null) |
||
597 | |||
598 | /** |
||
599 | * Set order. |
||
600 | * |
||
601 | * @param \Eccube\Entity\Order|null $order |
||
602 | * |
||
603 | * @return OrderItem |
||
604 | */ |
||
605 | public function setOrder(\Eccube\Entity\Order $order = null) |
||
611 | |||
612 | /** |
||
613 | * Get order. |
||
614 | * |
||
615 | * @return \Eccube\Entity\Order|null |
||
616 | */ |
||
617 | public function getOrder() |
||
621 | |||
622 | public function getOrderId() |
||
630 | |||
631 | /** |
||
632 | * Set product. |
||
633 | * |
||
634 | * @param \Eccube\Entity\Product|null $product |
||
635 | * |
||
636 | * @return OrderItem |
||
637 | */ |
||
638 | public function setProduct(\Eccube\Entity\Product $product = null) |
||
644 | |||
645 | /** |
||
646 | * Get product. |
||
647 | * |
||
648 | * @return \Eccube\Entity\Product|null |
||
649 | */ |
||
650 | public function getProduct() |
||
654 | |||
655 | /** |
||
656 | * Set productClass. |
||
657 | * |
||
658 | * @param \Eccube\Entity\ProductClass|null $productClass |
||
659 | * |
||
660 | * @return OrderItem |
||
661 | */ |
||
662 | public function setProductClass(\Eccube\Entity\ProductClass $productClass = null) |
||
668 | |||
669 | /** |
||
670 | * Get productClass. |
||
671 | * |
||
672 | * @return \Eccube\Entity\ProductClass|null |
||
673 | */ |
||
674 | public function getProductClass() |
||
678 | |||
679 | /** |
||
680 | * Set shipping. |
||
681 | * |
||
682 | * @param \Eccube\Entity\Shipping|null $shipping |
||
683 | * |
||
684 | * @return OrderItem |
||
685 | */ |
||
686 | public function setShipping(\Eccube\Entity\Shipping $shipping = null) |
||
692 | |||
693 | /** |
||
694 | * Get shipping. |
||
695 | * |
||
696 | * @return \Eccube\Entity\Shipping|null |
||
697 | */ |
||
698 | public function getShipping() |
||
702 | |||
703 | /** |
||
704 | * @return RoundingType |
||
705 | */ |
||
706 | public function getRoundingType() |
||
710 | |||
711 | /** |
||
712 | * @param RoundingType $RoundingType |
||
713 | */ |
||
714 | public function setRoundingType(RoundingType $RoundingType = null) |
||
720 | |||
721 | /** |
||
722 | * Set taxType |
||
723 | * |
||
724 | * @param \Eccube\Entity\Master\TaxType $taxType |
||
725 | * |
||
726 | * @return OrderItem |
||
727 | */ |
||
728 | public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null) |
||
734 | |||
735 | /** |
||
736 | * Get taxType |
||
737 | * |
||
738 | * @return \Eccube\Entity\Master\TaxType |
||
739 | */ |
||
740 | public function getTaxType() |
||
744 | |||
745 | /** |
||
746 | * Set taxDisplayType |
||
747 | * |
||
748 | * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType |
||
749 | * |
||
750 | * @return OrderItem |
||
751 | */ |
||
752 | public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null) |
||
758 | |||
759 | /** |
||
760 | * Get taxDisplayType |
||
761 | * |
||
762 | * @return \Eccube\Entity\Master\TaxDisplayType |
||
763 | */ |
||
764 | public function getTaxDisplayType() |
||
768 | |||
769 | /** |
||
770 | * Set orderItemType |
||
771 | * |
||
772 | * @param \Eccube\Entity\Master\OrderItemType $orderItemType |
||
773 | * |
||
774 | * @return OrderItem |
||
775 | */ |
||
776 | public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null) |
||
782 | |||
783 | /** |
||
784 | * Get orderItemType |
||
785 | * |
||
786 | * @return \Eccube\Entity\Master\OrderItemType |
||
787 | */ |
||
788 | public function getOrderItemType() |
||
792 | } |
||
793 | } |
||
794 |