Complex classes like Order 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 Order, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 67 | class Order extends ExtendOrder implements |
||
| 68 | ChannelAwareInterface, |
||
| 69 | FirstNameInterface, |
||
| 70 | LastNameInterface, |
||
| 71 | IntegrationAwareInterface |
||
| 72 | { |
||
| 73 | const STATUS_CANCELED = 'canceled'; |
||
| 74 | const STATUS_COMPLETED = 'completed'; |
||
| 75 | |||
| 76 | use IntegrationEntityTrait, NamesAwareTrait, ChannelEntityTrait; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="increment_id", type="string", length=60, nullable=false) |
||
| 82 | * @ConfigField( |
||
| 83 | * defaultValues={ |
||
| 84 | * "importexport"={ |
||
| 85 | * "identity"=true |
||
| 86 | * } |
||
| 87 | * } |
||
| 88 | * ) |
||
| 89 | */ |
||
| 90 | protected $incrementId; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var Customer |
||
| 94 | * |
||
| 95 | * @ORM\ManyToOne(targetEntity="Customer", inversedBy="orders") |
||
| 96 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL", nullable=true) |
||
| 97 | */ |
||
| 98 | protected $customer; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var ArrayCollection |
||
| 102 | * |
||
| 103 | * @ORM\OneToMany(targetEntity="OrderAddress", |
||
| 104 | * mappedBy="owner", cascade={"all"}, orphanRemoval=true |
||
| 105 | * ) |
||
| 106 | * @ConfigField( |
||
| 107 | * defaultValues={ |
||
| 108 | * "importexport"={ |
||
| 109 | * "full"=true |
||
| 110 | * } |
||
| 111 | * } |
||
| 112 | * ) |
||
| 113 | */ |
||
| 114 | protected $addresses; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var Store |
||
| 118 | * |
||
| 119 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\Store") |
||
| 120 | * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 121 | * @ConfigField( |
||
| 122 | * defaultValues={ |
||
| 123 | * "importexport"={ |
||
| 124 | * "full"=false |
||
| 125 | * } |
||
| 126 | * } |
||
| 127 | * ) |
||
| 128 | */ |
||
| 129 | protected $store; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var boolean |
||
| 133 | * |
||
| 134 | * @ORM\Column(name="is_virtual", type="boolean", nullable=true) |
||
| 135 | */ |
||
| 136 | protected $isVirtual = false; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var boolean |
||
| 140 | * |
||
| 141 | * @ORM\Column(name="is_guest", type="boolean", nullable=true) |
||
| 142 | */ |
||
| 143 | protected $isGuest = false; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @var string |
||
| 147 | * |
||
| 148 | * @ORM\Column(name="gift_message", type="string", length=255, nullable=true) |
||
| 149 | */ |
||
| 150 | protected $giftMessage; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var string |
||
| 154 | * |
||
| 155 | * @ORM\Column(name="remote_ip", type="string", length=255, nullable=true) |
||
| 156 | */ |
||
| 157 | protected $remoteIp; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var string |
||
| 161 | * |
||
| 162 | * @ORM\Column(name="store_name", type="string", length=255, nullable=true) |
||
| 163 | */ |
||
| 164 | protected $storeName; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @var float |
||
| 168 | * |
||
| 169 | * @ORM\Column(name="total_paid_amount", type="float", nullable=true) |
||
| 170 | */ |
||
| 171 | protected $totalPaidAmount = 0; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var double |
||
| 175 | * |
||
| 176 | * @ORM\Column(name="total_invoiced_amount", type="money", nullable=true) |
||
| 177 | */ |
||
| 178 | protected $totalInvoicedAmount = 0; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @var double |
||
| 182 | * |
||
| 183 | * @ORM\Column(name="total_refunded_amount", type="money", nullable=true) |
||
| 184 | */ |
||
| 185 | protected $totalRefundedAmount = 0; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @var double |
||
| 189 | * |
||
| 190 | * @ORM\Column(name="total_canceled_amount", type="money", nullable=true) |
||
| 191 | */ |
||
| 192 | protected $totalCanceledAmount = 0; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @ORM\ManyToOne(targetEntity="Cart") |
||
| 196 | */ |
||
| 197 | protected $cart; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @var OrderItem[]|Collection |
||
| 201 | * |
||
| 202 | * @ORM\OneToMany(targetEntity="OrderItem", mappedBy="order",cascade={"all"}) |
||
| 203 | * @ConfigField( |
||
| 204 | * defaultValues={ |
||
| 205 | * "importexport"={ |
||
| 206 | * "full"=true |
||
| 207 | * } |
||
| 208 | * } |
||
| 209 | * ) |
||
| 210 | */ |
||
| 211 | protected $items; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var string |
||
| 215 | * |
||
| 216 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
| 217 | */ |
||
| 218 | protected $notes; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @var string |
||
| 222 | * |
||
| 223 | * @ORM\Column(name="feedback", type="text", nullable=true) |
||
| 224 | */ |
||
| 225 | protected $feedback; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @var string |
||
| 229 | * |
||
| 230 | * @ORM\Column(name="customer_email", type="string", length=255, nullable=true) |
||
| 231 | */ |
||
| 232 | protected $customerEmail; |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @var User |
||
| 236 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
| 237 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 238 | */ |
||
| 239 | protected $owner; |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @var Organization |
||
| 243 | * |
||
| 244 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
| 245 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 246 | */ |
||
| 247 | protected $organization; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @var string |
||
| 251 | * |
||
| 252 | * @ORM\Column(name="coupon_code", type="string", length=255, nullable=true) |
||
| 253 | */ |
||
| 254 | protected $couponCode; |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @var \DateTime |
||
| 258 | * |
||
| 259 | * @ORM\Column(type="datetime", name="imported_at", nullable=true) |
||
| 260 | */ |
||
| 261 | protected $importedAt; |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @var \DateTime |
||
| 265 | * |
||
| 266 | * @ORM\Column(type="datetime", name="synced_at", nullable=true) |
||
| 267 | */ |
||
| 268 | protected $syncedAt; |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param string $incrementId |
||
| 272 | * |
||
| 273 | * @return Order |
||
| 274 | */ |
||
| 275 | public function setIncrementId($incrementId) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | public function getIncrementId() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @param string $giftMessage |
||
| 292 | * |
||
| 293 | * @return Order |
||
| 294 | */ |
||
| 295 | public function setGiftMessage($giftMessage) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | public function getGiftMessage() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @param boolean $isGuest |
||
| 312 | * |
||
| 313 | * @return Order |
||
| 314 | */ |
||
| 315 | public function setIsGuest($isGuest) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return boolean |
||
| 324 | */ |
||
| 325 | public function getIsGuest() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param boolean $isVirtual |
||
| 332 | * |
||
| 333 | * @return Order |
||
| 334 | */ |
||
| 335 | public function setIsVirtual($isVirtual) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return boolean |
||
| 344 | */ |
||
| 345 | public function getIsVirtual() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param Store $store |
||
| 352 | * |
||
| 353 | * @return Order |
||
| 354 | */ |
||
| 355 | public function setStore(Store $store) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return Store |
||
| 364 | */ |
||
| 365 | public function getStore() |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $storeName |
||
| 372 | * |
||
| 373 | * @return Order |
||
| 374 | */ |
||
| 375 | public function setStoreName($storeName) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | public function getStoreName() |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @param float $totalCanceledAmount |
||
| 392 | * |
||
| 393 | * @return Order |
||
| 394 | */ |
||
| 395 | public function setTotalCanceledAmount($totalCanceledAmount) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return float |
||
| 404 | */ |
||
| 405 | public function getTotalCanceledAmount() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param float $totalInvoicedAmount |
||
| 412 | * |
||
| 413 | * @return Order |
||
| 414 | */ |
||
| 415 | public function setTotalInvoicedAmount($totalInvoicedAmount) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @return float |
||
| 424 | */ |
||
| 425 | public function getTotalInvoicedAmount() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @param float $totalPaidAmount |
||
| 432 | * |
||
| 433 | * @return Order |
||
| 434 | */ |
||
| 435 | public function setTotalPaidAmount($totalPaidAmount) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return float |
||
| 444 | */ |
||
| 445 | public function getTotalPaidAmount() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param float $totalRefundedAmount |
||
| 452 | * |
||
| 453 | * @return Order |
||
| 454 | */ |
||
| 455 | public function setTotalRefundedAmount($totalRefundedAmount) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @return float |
||
| 464 | */ |
||
| 465 | public function getTotalRefundedAmount() |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @param string $remoteIp |
||
| 472 | * |
||
| 473 | * @return Order |
||
| 474 | */ |
||
| 475 | public function setRemoteIp($remoteIp) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @return string |
||
| 484 | */ |
||
| 485 | public function getRemoteIp() |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @param Cart $cart |
||
| 492 | * |
||
| 493 | * @return Order |
||
| 494 | */ |
||
| 495 | public function setCart($cart = null) |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return Cart |
||
| 504 | */ |
||
| 505 | public function getCart() |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @param string $notes |
||
| 512 | * |
||
| 513 | * @return Order |
||
| 514 | */ |
||
| 515 | public function setNotes($notes) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @return string |
||
| 524 | */ |
||
| 525 | public function getNotes() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @param string $feedback |
||
| 532 | * |
||
| 533 | * @return Order |
||
| 534 | */ |
||
| 535 | public function setFeedback($feedback) |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @return string |
||
| 544 | */ |
||
| 545 | public function getFeedback() |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Pre persist event listener |
||
| 552 | * |
||
| 553 | * @ORM\PrePersist |
||
| 554 | */ |
||
| 555 | public function beforeSave() |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Pre update event handler |
||
| 562 | * |
||
| 563 | * @ORM\PreUpdate |
||
| 564 | */ |
||
| 565 | public function doPreUpdate() |
||
| 569 | |||
| 570 | /** |
||
| 571 | * {@inheritdoc} |
||
| 572 | */ |
||
| 573 | public function getBillingAddress() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @param string $customerEmail |
||
| 586 | * |
||
| 587 | * @return Order |
||
| 588 | */ |
||
| 589 | public function setCustomerEmail($customerEmail) |
||
| 595 | |||
| 596 | /** |
||
| 597 | * @return string |
||
| 598 | */ |
||
| 599 | public function getCustomerEmail() |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @return User |
||
| 606 | */ |
||
| 607 | public function getOwner() |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @param User $user |
||
| 614 | */ |
||
| 615 | public function setOwner(User $user) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Set organization |
||
| 622 | * |
||
| 623 | * @param Organization $organization |
||
| 624 | * @return Order |
||
| 625 | */ |
||
| 626 | public function setOrganization(Organization $organization = null) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Get organization |
||
| 635 | * |
||
| 636 | * @return Organization |
||
| 637 | */ |
||
| 638 | public function getOrganization() |
||
| 642 | |||
| 643 | /** |
||
| 644 | * @return string |
||
| 645 | */ |
||
| 646 | public function getCouponCode() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * @param string $couponCode |
||
| 653 | * @return Order |
||
| 654 | */ |
||
| 655 | public function setCouponCode($couponCode) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @return bool |
||
| 664 | */ |
||
| 665 | public function isCanceled() |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @return bool |
||
| 672 | */ |
||
| 673 | public function isCompleted() |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @return \DateTime |
||
| 680 | */ |
||
| 681 | public function getSyncedAt() |
||
| 685 | |||
| 686 | /** |
||
| 687 | * @param \DateTime|null $syncedAt |
||
| 688 | * @return Order |
||
| 689 | */ |
||
| 690 | public function setSyncedAt(\DateTime $syncedAt = null) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * @return \DateTime |
||
| 699 | */ |
||
| 700 | public function getImportedAt() |
||
| 704 | |||
| 705 | /** |
||
| 706 | * @param \DateTime|null $importedAt |
||
| 707 | * @return Order |
||
| 708 | */ |
||
| 709 | public function setImportedAt(\DateTime $importedAt = null) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @return string |
||
| 718 | */ |
||
| 719 | public function __toString() |
||
| 723 | } |
||
| 724 |