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 |
||
| 29 | class OrderItem extends \Eccube\Entity\AbstractEntity implements ItemInterface |
||
| 30 | { |
||
| 31 | use PointRateTrait; |
||
| 32 | |||
| 33 | private $price_inc_tax = null; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Set price IncTax |
||
| 37 | * |
||
| 38 | * @param string $price_inc_tax |
||
| 39 | * |
||
| 40 | * @return OrderItem |
||
| 41 | */ |
||
| 42 | 231 | public function setPriceIncTax($price_inc_tax) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Get price IncTax |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | 232 | public function getPriceIncTax() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * @return integer |
||
| 61 | */ |
||
| 62 | 61 | public function getTotalPrice() |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @return integer |
||
| 84 | */ |
||
| 85 | 238 | public function getOrderItemTypeId() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * 商品明細かどうか. |
||
| 96 | * |
||
| 97 | * @return boolean 商品明細の場合 true |
||
| 98 | */ |
||
| 99 | 238 | public function isProduct() |
|
| 103 | |||
| 104 | /** |
||
| 105 | * 送料明細かどうか. |
||
| 106 | * |
||
| 107 | * @return boolean 送料明細の場合 true |
||
| 108 | */ |
||
| 109 | 227 | public function isDeliveryFee() |
|
| 113 | |||
| 114 | /** |
||
| 115 | * 手数料明細かどうか. |
||
| 116 | * |
||
| 117 | * @return boolean 手数料明細の場合 true |
||
| 118 | */ |
||
| 119 | 221 | public function isCharge() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * 値引き明細かどうか. |
||
| 126 | * |
||
| 127 | * @return boolean 値引き明細の場合 true |
||
| 128 | */ |
||
| 129 | 221 | public function isDiscount() |
|
| 133 | |||
| 134 | /** |
||
| 135 | * 税額明細かどうか. |
||
| 136 | * |
||
| 137 | * @return boolean 税額明細の場合 true |
||
| 138 | */ |
||
| 139 | 3 | public function isTax() |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @var integer |
||
| 146 | * |
||
| 147 | * @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
||
| 148 | * @ORM\Id |
||
| 149 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 150 | */ |
||
| 151 | private $id; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var string |
||
| 155 | * |
||
| 156 | * @ORM\Column(name="product_name", type="string", length=255) |
||
| 157 | */ |
||
| 158 | private $product_name; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @var string|null |
||
| 162 | * |
||
| 163 | * @ORM\Column(name="product_code", type="string", length=255, nullable=true) |
||
| 164 | */ |
||
| 165 | private $product_code; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var string|null |
||
| 169 | * |
||
| 170 | * @ORM\Column(name="class_name1", type="string", length=255, nullable=true) |
||
| 171 | */ |
||
| 172 | private $class_name1; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var string|null |
||
| 176 | * |
||
| 177 | * @ORM\Column(name="class_name2", type="string", length=255, nullable=true) |
||
| 178 | */ |
||
| 179 | private $class_name2; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var string|null |
||
| 183 | * |
||
| 184 | * @ORM\Column(name="class_category_name1", type="string", length=255, nullable=true) |
||
| 185 | */ |
||
| 186 | private $class_category_name1; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var string|null |
||
| 190 | * |
||
| 191 | * @ORM\Column(name="class_category_name2", type="string", length=255, nullable=true) |
||
| 192 | */ |
||
| 193 | private $class_category_name2; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @var string |
||
| 197 | * |
||
| 198 | * @ORM\Column(name="price", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0}) |
||
| 199 | */ |
||
| 200 | private $price = 0; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @var string |
||
| 204 | * |
||
| 205 | * @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) |
||
| 206 | */ |
||
| 207 | private $quantity = 0; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @var string |
||
| 211 | * |
||
| 212 | * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0}) |
||
| 213 | */ |
||
| 214 | private $tax_rate = 0; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @var int|null |
||
| 218 | * |
||
| 219 | * @ORM\Column(name="tax_rule", type="smallint", nullable=true, options={"unsigned":true}) |
||
| 220 | */ |
||
| 221 | private $tax_rule; |
||
| 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 \Eccube\Entity\Order |
||
| 232 | * |
||
| 233 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderItems") |
||
| 234 | * @ORM\JoinColumns({ |
||
| 235 | * @ORM\JoinColumn(name="order_id", referencedColumnName="id") |
||
| 236 | * }) |
||
| 237 | */ |
||
| 238 | private $Order; |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @var \Eccube\Entity\Product |
||
| 242 | * |
||
| 243 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product") |
||
| 244 | * @ORM\JoinColumns({ |
||
| 245 | * @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
||
| 246 | * }) |
||
| 247 | */ |
||
| 248 | private $Product; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @var \Eccube\Entity\ProductClass |
||
| 252 | * |
||
| 253 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\ProductClass") |
||
| 254 | * @ORM\JoinColumns({ |
||
| 255 | * @ORM\JoinColumn(name="product_class_id", referencedColumnName="id") |
||
| 256 | * }) |
||
| 257 | */ |
||
| 258 | private $ProductClass; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @var \Eccube\Entity\Shipping |
||
| 262 | * |
||
| 263 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Shipping", inversedBy="OrderItems") |
||
| 264 | * @ORM\JoinColumns({ |
||
| 265 | * @ORM\JoinColumn(name="shipping_id", referencedColumnName="id") |
||
| 266 | * }) |
||
| 267 | */ |
||
| 268 | private $Shipping; |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @var \Eccube\Entity\Master\TaxType |
||
| 272 | * |
||
| 273 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxType") |
||
| 274 | * @ORM\JoinColumns({ |
||
| 275 | * @ORM\JoinColumn(name="tax_type_id", referencedColumnName="id") |
||
| 276 | * }) |
||
| 277 | */ |
||
| 278 | private $TaxType; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @var \Eccube\Entity\Master\TaxDisplayType |
||
| 282 | * |
||
| 283 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\TaxDisplayType") |
||
| 284 | * @ORM\JoinColumns({ |
||
| 285 | * @ORM\JoinColumn(name="tax_display_type_id", referencedColumnName="id") |
||
| 286 | * }) |
||
| 287 | */ |
||
| 288 | private $TaxDisplayType; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @var \Eccube\Entity\Master\OrderItemType |
||
| 292 | * |
||
| 293 | * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderItemType") |
||
| 294 | * @ORM\JoinColumns({ |
||
| 295 | * @ORM\JoinColumn(name="order_item_type_id", referencedColumnName="id") |
||
| 296 | * }) |
||
| 297 | */ |
||
| 298 | private $OrderItemType; |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Get id. |
||
| 302 | * |
||
| 303 | * @return int |
||
| 304 | */ |
||
| 305 | 45 | public function getId() |
|
| 309 | |||
| 310 | /** |
||
| 311 | * Set productName. |
||
| 312 | * |
||
| 313 | * @param string $productName |
||
| 314 | * |
||
| 315 | * @return OrderItem |
||
| 316 | */ |
||
| 317 | 220 | public function setProductName($productName) |
|
| 323 | |||
| 324 | /** |
||
| 325 | * Get productName. |
||
| 326 | * |
||
| 327 | * @return string |
||
| 328 | */ |
||
| 329 | 76 | public function getProductName() |
|
| 333 | |||
| 334 | /** |
||
| 335 | * Set productCode. |
||
| 336 | * |
||
| 337 | * @param string|null $productCode |
||
| 338 | * |
||
| 339 | * @return OrderItem |
||
| 340 | */ |
||
| 341 | 208 | public function setProductCode($productCode = null) |
|
| 347 | |||
| 348 | /** |
||
| 349 | * Get productCode. |
||
| 350 | * |
||
| 351 | * @return string|null |
||
| 352 | */ |
||
| 353 | 37 | public function getProductCode() |
|
| 357 | |||
| 358 | /** |
||
| 359 | * Set className1. |
||
| 360 | * |
||
| 361 | * @param string|null $className1 |
||
| 362 | * |
||
| 363 | * @return OrderItem |
||
| 364 | */ |
||
| 365 | 206 | public function setClassName1($className1 = null) |
|
| 371 | |||
| 372 | /** |
||
| 373 | * Get className1. |
||
| 374 | * |
||
| 375 | * @return string|null |
||
| 376 | */ |
||
| 377 | 22 | public function getClassName1() |
|
| 381 | |||
| 382 | /** |
||
| 383 | * Set className2. |
||
| 384 | * |
||
| 385 | * @param string|null $className2 |
||
| 386 | * |
||
| 387 | * @return OrderItem |
||
| 388 | */ |
||
| 389 | 149 | public function setClassName2($className2 = null) |
|
| 395 | |||
| 396 | /** |
||
| 397 | * Get className2. |
||
| 398 | * |
||
| 399 | * @return string|null |
||
| 400 | */ |
||
| 401 | 22 | public function getClassName2() |
|
| 405 | |||
| 406 | /** |
||
| 407 | * Set classCategoryName1. |
||
| 408 | * |
||
| 409 | * @param string|null $classCategoryName1 |
||
| 410 | * |
||
| 411 | * @return OrderItem |
||
| 412 | */ |
||
| 413 | 206 | public function setClassCategoryName1($classCategoryName1 = null) |
|
| 419 | |||
| 420 | /** |
||
| 421 | * Get classCategoryName1. |
||
| 422 | * |
||
| 423 | * @return string|null |
||
| 424 | */ |
||
| 425 | 38 | public function getClassCategoryName1() |
|
| 429 | |||
| 430 | /** |
||
| 431 | * Set classCategoryName2. |
||
| 432 | * |
||
| 433 | * @param string|null $classCategoryName2 |
||
| 434 | * |
||
| 435 | * @return OrderItem |
||
| 436 | */ |
||
| 437 | 149 | public function setClassCategoryName2($classCategoryName2 = null) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * Get classCategoryName2. |
||
| 446 | * |
||
| 447 | * @return string|null |
||
| 448 | */ |
||
| 449 | 36 | public function getClassCategoryName2() |
|
| 453 | |||
| 454 | /** |
||
| 455 | * Set price. |
||
| 456 | * |
||
| 457 | * @param string $price |
||
| 458 | * |
||
| 459 | * @return OrderItem |
||
| 460 | */ |
||
| 461 | 230 | public function setPrice($price) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Get price. |
||
| 470 | * |
||
| 471 | * @return string |
||
| 472 | */ |
||
| 473 | 232 | public function getPrice() |
|
| 477 | |||
| 478 | /** |
||
| 479 | * Set quantity. |
||
| 480 | * |
||
| 481 | * @param string $quantity |
||
| 482 | * |
||
| 483 | * @return OrderItem |
||
| 484 | */ |
||
| 485 | 251 | public function setQuantity($quantity) |
|
| 491 | |||
| 492 | /** |
||
| 493 | * Get quantity. |
||
| 494 | * |
||
| 495 | * @return string |
||
| 496 | */ |
||
| 497 | 247 | public function getQuantity() |
|
| 501 | |||
| 502 | /** |
||
| 503 | * Set taxRate. |
||
| 504 | * |
||
| 505 | * @param string $taxRate |
||
| 506 | * |
||
| 507 | * @return OrderItem |
||
| 508 | */ |
||
| 509 | 220 | public function setTaxRate($taxRate) |
|
| 515 | |||
| 516 | /** |
||
| 517 | * Get taxRate. |
||
| 518 | * |
||
| 519 | * @return string |
||
| 520 | */ |
||
| 521 | 72 | public function getTaxRate() |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Set taxRule. |
||
| 528 | * |
||
| 529 | * @param int|null $taxRule |
||
| 530 | * |
||
| 531 | * @return OrderItem |
||
| 532 | */ |
||
| 533 | 208 | public function setTaxRule($taxRule = null) |
|
| 539 | |||
| 540 | /** |
||
| 541 | * Get taxRule. |
||
| 542 | * |
||
| 543 | * @return int|null |
||
| 544 | */ |
||
| 545 | 33 | public function getTaxRule() |
|
| 549 | |||
| 550 | /** |
||
| 551 | * Get currencyCode. |
||
| 552 | * |
||
| 553 | * @return string |
||
| 554 | */ |
||
| 555 | public function getCurrencyCode() |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Set currencyCode. |
||
| 562 | * |
||
| 563 | * @param string|null $currencyCode |
||
| 564 | * |
||
| 565 | * @return OrderItem |
||
| 566 | */ |
||
| 567 | 208 | public function setCurrencyCode($currencyCode = null) |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Set order. |
||
| 576 | * |
||
| 577 | * @param \Eccube\Entity\Order|null $order |
||
| 578 | * |
||
| 579 | * @return OrderItem |
||
| 580 | */ |
||
| 581 | 209 | public function setOrder(\Eccube\Entity\Order $order = null) |
|
| 587 | |||
| 588 | /** |
||
| 589 | * Get order. |
||
| 590 | * |
||
| 591 | * @return \Eccube\Entity\Order|null |
||
| 592 | */ |
||
| 593 | 51 | public function getOrder() |
|
| 597 | |||
| 598 | 8 | public function getOrderId() |
|
| 606 | |||
| 607 | /** |
||
| 608 | * Set product. |
||
| 609 | * |
||
| 610 | * @param \Eccube\Entity\Product|null $product |
||
| 611 | * |
||
| 612 | * @return OrderItem |
||
| 613 | */ |
||
| 614 | 208 | public function setProduct(\Eccube\Entity\Product $product = null) |
|
| 620 | |||
| 621 | /** |
||
| 622 | * Get product. |
||
| 623 | * |
||
| 624 | * @return \Eccube\Entity\Product|null |
||
| 625 | */ |
||
| 626 | 219 | public function getProduct() |
|
| 630 | |||
| 631 | /** |
||
| 632 | * Set productClass. |
||
| 633 | * |
||
| 634 | * @param \Eccube\Entity\ProductClass|null $productClass |
||
| 635 | * |
||
| 636 | * @return OrderItem |
||
| 637 | */ |
||
| 638 | 228 | public function setProductClass(\Eccube\Entity\ProductClass $productClass = null) |
|
| 644 | |||
| 645 | /** |
||
| 646 | * Get productClass. |
||
| 647 | * |
||
| 648 | * @return \Eccube\Entity\ProductClass|null |
||
| 649 | */ |
||
| 650 | 228 | public function getProductClass() |
|
| 654 | |||
| 655 | /** |
||
| 656 | * Set shipping. |
||
| 657 | * |
||
| 658 | * @param \Eccube\Entity\Shipping|null $shipping |
||
| 659 | * |
||
| 660 | * @return OrderItem |
||
| 661 | */ |
||
| 662 | 217 | public function setShipping(\Eccube\Entity\Shipping $shipping = null) |
|
| 668 | |||
| 669 | /** |
||
| 670 | * Get shipping. |
||
| 671 | * |
||
| 672 | * @return \Eccube\Entity\Shipping|null |
||
| 673 | */ |
||
| 674 | 75 | public function getShipping() |
|
| 678 | |||
| 679 | /** |
||
| 680 | * Set taxType |
||
| 681 | * |
||
| 682 | * @param \Eccube\Entity\Master\TaxType $taxType |
||
| 683 | * |
||
| 684 | * @return OrderItem |
||
| 685 | */ |
||
| 686 | 207 | public function setTaxType(\Eccube\Entity\Master\TaxType $taxType = null) |
|
| 692 | |||
| 693 | /** |
||
| 694 | * Get taxType |
||
| 695 | * |
||
| 696 | * @return \Eccube\Entity\Master\TaxType |
||
| 697 | */ |
||
| 698 | 17 | public function getTaxType() |
|
| 702 | |||
| 703 | /** |
||
| 704 | * Set taxDisplayType |
||
| 705 | * |
||
| 706 | * @param \Eccube\Entity\Master\TaxDisplayType $taxDisplayType |
||
| 707 | * |
||
| 708 | * @return OrderItem |
||
| 709 | */ |
||
| 710 | 207 | public function setTaxDisplayType(\Eccube\Entity\Master\TaxDisplayType $taxDisplayType = null) |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Get taxDisplayType |
||
| 719 | * |
||
| 720 | * @return \Eccube\Entity\Master\TaxDisplayType |
||
| 721 | */ |
||
| 722 | 77 | public function getTaxDisplayType() |
|
| 726 | |||
| 727 | /** |
||
| 728 | * Set orderItemType |
||
| 729 | * |
||
| 730 | * @param \Eccube\Entity\Master\OrderItemType $orderItemType |
||
| 731 | * |
||
| 732 | * @return OrderItem |
||
| 733 | */ |
||
| 734 | 229 | public function setOrderItemType(\Eccube\Entity\Master\OrderItemType $orderItemType = null) |
|
| 740 | |||
| 741 | /** |
||
| 742 | * Get orderItemType |
||
| 743 | * |
||
| 744 | * @return \Eccube\Entity\Master\OrderItemType |
||
| 745 | */ |
||
| 746 | 249 | public function getOrderItemType() |
|
| 750 | } |
||
| 751 |