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 |
||
| 69 | class Order extends ExtendOrder implements |
||
| 70 | ChannelAwareInterface, |
||
| 71 | FirstNameInterface, |
||
| 72 | LastNameInterface, |
||
| 73 | IntegrationAwareInterface |
||
| 74 | { |
||
| 75 | const STATUS_CANCELED = 'canceled'; |
||
| 76 | const STATUS_COMPLETED = 'completed'; |
||
| 77 | |||
| 78 | use IntegrationEntityTrait, NamesAwareTrait, ChannelEntityTrait; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var string |
||
| 82 | * |
||
| 83 | * @ORM\Column(name="increment_id", type="string", length=60, nullable=false) |
||
| 84 | * @ConfigField( |
||
| 85 | * defaultValues={ |
||
| 86 | * "importexport"={ |
||
| 87 | * "identity"=true |
||
| 88 | * } |
||
| 89 | * } |
||
| 90 | * ) |
||
| 91 | */ |
||
| 92 | protected $incrementId; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var Customer |
||
| 96 | * |
||
| 97 | * @ORM\ManyToOne(targetEntity="Customer", inversedBy="orders") |
||
| 98 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL", nullable=true) |
||
| 99 | */ |
||
| 100 | protected $customer; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var ArrayCollection |
||
| 104 | * |
||
| 105 | * @ORM\OneToMany(targetEntity="OrderAddress", |
||
| 106 | * mappedBy="owner", cascade={"all"}, orphanRemoval=true |
||
| 107 | * ) |
||
| 108 | * @ConfigField( |
||
| 109 | * defaultValues={ |
||
| 110 | * "importexport"={ |
||
| 111 | * "full"=true |
||
| 112 | * } |
||
| 113 | * } |
||
| 114 | * ) |
||
| 115 | */ |
||
| 116 | protected $addresses; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var Store |
||
| 120 | * |
||
| 121 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\Store") |
||
| 122 | * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 123 | * @ConfigField( |
||
| 124 | * defaultValues={ |
||
| 125 | * "importexport"={ |
||
| 126 | * "full"=false |
||
| 127 | * } |
||
| 128 | * } |
||
| 129 | * ) |
||
| 130 | */ |
||
| 131 | protected $store; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var boolean |
||
| 135 | * |
||
| 136 | * @ORM\Column(name="is_virtual", type="boolean", nullable=true) |
||
| 137 | */ |
||
| 138 | protected $isVirtual = false; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var boolean |
||
| 142 | * |
||
| 143 | * @ORM\Column(name="is_guest", type="boolean", nullable=true) |
||
| 144 | */ |
||
| 145 | protected $isGuest = false; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var string |
||
| 149 | * |
||
| 150 | * @ORM\Column(name="gift_message", type="string", length=255, nullable=true) |
||
| 151 | */ |
||
| 152 | protected $giftMessage; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var string |
||
| 156 | * |
||
| 157 | * @ORM\Column(name="remote_ip", type="string", length=255, nullable=true) |
||
| 158 | */ |
||
| 159 | protected $remoteIp; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var string |
||
| 163 | * |
||
| 164 | * @ORM\Column(name="store_name", type="string", length=255, nullable=true) |
||
| 165 | */ |
||
| 166 | protected $storeName; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var float |
||
| 170 | * |
||
| 171 | * @ORM\Column(name="total_paid_amount", type="float", nullable=true) |
||
| 172 | */ |
||
| 173 | protected $totalPaidAmount = 0; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @var double |
||
| 177 | * |
||
| 178 | * @ORM\Column(name="total_invoiced_amount", type="money", nullable=true) |
||
| 179 | */ |
||
| 180 | protected $totalInvoicedAmount = 0; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @var double |
||
| 184 | * |
||
| 185 | * @ORM\Column(name="total_refunded_amount", type="money", nullable=true) |
||
| 186 | */ |
||
| 187 | protected $totalRefundedAmount = 0; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @var double |
||
| 191 | * |
||
| 192 | * @ORM\Column(name="total_canceled_amount", type="money", nullable=true) |
||
| 193 | */ |
||
| 194 | protected $totalCanceledAmount = 0; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @ORM\ManyToOne(targetEntity="Cart") |
||
| 198 | */ |
||
| 199 | protected $cart; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @var OrderItem[]|Collection |
||
| 203 | * |
||
| 204 | * @ORM\OneToMany(targetEntity="OrderItem", mappedBy="order",cascade={"all"}) |
||
| 205 | * @ConfigField( |
||
| 206 | * defaultValues={ |
||
| 207 | * "importexport"={ |
||
| 208 | * "full"=true |
||
| 209 | * } |
||
| 210 | * } |
||
| 211 | * ) |
||
| 212 | */ |
||
| 213 | protected $items; |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @var string |
||
| 217 | * |
||
| 218 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
| 219 | */ |
||
| 220 | protected $notes; |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @var string |
||
| 224 | * |
||
| 225 | * @ORM\Column(name="feedback", type="text", nullable=true) |
||
| 226 | */ |
||
| 227 | protected $feedback; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @var WorkflowItem |
||
| 231 | * |
||
| 232 | * @ORM\OneToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowItem") |
||
| 233 | * @ORM\JoinColumn(name="workflow_item_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 234 | */ |
||
| 235 | protected $workflowItem; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @var WorkflowStep |
||
| 239 | * |
||
| 240 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowStep") |
||
| 241 | * @ORM\JoinColumn(name="workflow_step_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 242 | */ |
||
| 243 | protected $workflowStep; |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @var string |
||
| 247 | * |
||
| 248 | * @ORM\Column(name="customer_email", type="string", length=255, nullable=true) |
||
| 249 | */ |
||
| 250 | protected $customerEmail; |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @var User |
||
| 254 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
| 255 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 256 | */ |
||
| 257 | protected $owner; |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @var Organization |
||
| 261 | * |
||
| 262 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
| 263 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 264 | */ |
||
| 265 | protected $organization; |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @var string |
||
| 269 | * |
||
| 270 | * @ORM\Column(name="coupon_code", type="string", length=255, nullable=true) |
||
| 271 | */ |
||
| 272 | protected $couponCode; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @var \DateTime |
||
| 276 | * |
||
| 277 | * @ORM\Column(type="datetime", name="imported_at", nullable=true) |
||
| 278 | */ |
||
| 279 | protected $importedAt; |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @var \DateTime |
||
| 283 | * |
||
| 284 | * @ORM\Column(type="datetime", name="synced_at", nullable=true) |
||
| 285 | */ |
||
| 286 | protected $syncedAt; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param WorkflowItem $workflowItem |
||
| 290 | * |
||
| 291 | * @return Order |
||
| 292 | */ |
||
| 293 | public function setWorkflowItem($workflowItem) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return WorkflowItem |
||
| 302 | */ |
||
| 303 | public function getWorkflowItem() |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param WorkflowItem $workflowStep |
||
| 310 | * |
||
| 311 | * @return Order |
||
| 312 | */ |
||
| 313 | public function setWorkflowStep($workflowStep) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return WorkflowStep |
||
| 322 | */ |
||
| 323 | public function getWorkflowStep() |
||
| 327 | |||
| 328 | public function __construct() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @param string $incrementId |
||
| 337 | * |
||
| 338 | * @return Order |
||
| 339 | */ |
||
| 340 | public function setIncrementId($incrementId) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return string |
||
| 349 | */ |
||
| 350 | public function getIncrementId() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @param string $giftMessage |
||
| 357 | * |
||
| 358 | * @return Order |
||
| 359 | */ |
||
| 360 | public function setGiftMessage($giftMessage) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @return string |
||
| 369 | */ |
||
| 370 | public function getGiftMessage() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param boolean $isGuest |
||
| 377 | * |
||
| 378 | * @return Order |
||
| 379 | */ |
||
| 380 | public function setIsGuest($isGuest) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return boolean |
||
| 389 | */ |
||
| 390 | public function getIsGuest() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param boolean $isVirtual |
||
| 397 | * |
||
| 398 | * @return Order |
||
| 399 | */ |
||
| 400 | public function setIsVirtual($isVirtual) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return boolean |
||
| 409 | */ |
||
| 410 | public function getIsVirtual() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @param Store $store |
||
| 417 | * |
||
| 418 | * @return Order |
||
| 419 | */ |
||
| 420 | public function setStore(Store $store) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return Store |
||
| 429 | */ |
||
| 430 | public function getStore() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param string $storeName |
||
| 437 | * |
||
| 438 | * @return Order |
||
| 439 | */ |
||
| 440 | public function setStoreName($storeName) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getStoreName() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param float $totalCanceledAmount |
||
| 457 | * |
||
| 458 | * @return Order |
||
| 459 | */ |
||
| 460 | public function setTotalCanceledAmount($totalCanceledAmount) |
||
| 466 | |||
| 467 | /** |
||
| 468 | * @return float |
||
| 469 | */ |
||
| 470 | public function getTotalCanceledAmount() |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @param float $totalInvoicedAmount |
||
| 477 | * |
||
| 478 | * @return Order |
||
| 479 | */ |
||
| 480 | public function setTotalInvoicedAmount($totalInvoicedAmount) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @return float |
||
| 489 | */ |
||
| 490 | public function getTotalInvoicedAmount() |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @param float $totalPaidAmount |
||
| 497 | * |
||
| 498 | * @return Order |
||
| 499 | */ |
||
| 500 | public function setTotalPaidAmount($totalPaidAmount) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @return float |
||
| 509 | */ |
||
| 510 | public function getTotalPaidAmount() |
||
| 514 | |||
| 515 | /** |
||
| 516 | * @param float $totalRefundedAmount |
||
| 517 | * |
||
| 518 | * @return Order |
||
| 519 | */ |
||
| 520 | public function setTotalRefundedAmount($totalRefundedAmount) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @return float |
||
| 529 | */ |
||
| 530 | public function getTotalRefundedAmount() |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @param string $remoteIp |
||
| 537 | * |
||
| 538 | * @return Order |
||
| 539 | */ |
||
| 540 | public function setRemoteIp($remoteIp) |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @return string |
||
| 549 | */ |
||
| 550 | public function getRemoteIp() |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @param Cart $cart |
||
| 557 | * |
||
| 558 | * @return Order |
||
| 559 | */ |
||
| 560 | public function setCart($cart = null) |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @return Cart |
||
| 569 | */ |
||
| 570 | public function getCart() |
||
| 574 | |||
| 575 | /** |
||
| 576 | * @param string $notes |
||
| 577 | * |
||
| 578 | * @return Order |
||
| 579 | */ |
||
| 580 | public function setNotes($notes) |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @return string |
||
| 589 | */ |
||
| 590 | public function getNotes() |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @param string $feedback |
||
| 597 | * |
||
| 598 | * @return Order |
||
| 599 | */ |
||
| 600 | public function setFeedback($feedback) |
||
| 606 | |||
| 607 | /** |
||
| 608 | * @return string |
||
| 609 | */ |
||
| 610 | public function getFeedback() |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Pre persist event listener |
||
| 617 | * |
||
| 618 | * @ORM\PrePersist |
||
| 619 | */ |
||
| 620 | public function beforeSave() |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Pre update event handler |
||
| 627 | * |
||
| 628 | * @ORM\PreUpdate |
||
| 629 | */ |
||
| 630 | public function doPreUpdate() |
||
| 634 | |||
| 635 | /** |
||
| 636 | * {@inheritdoc} |
||
| 637 | */ |
||
| 638 | public function getBillingAddress() |
||
| 648 | |||
| 649 | /** |
||
| 650 | * @param string $customerEmail |
||
| 651 | * |
||
| 652 | * @return Order |
||
| 653 | */ |
||
| 654 | public function setCustomerEmail($customerEmail) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * @return string |
||
| 663 | */ |
||
| 664 | public function getCustomerEmail() |
||
| 668 | |||
| 669 | /** |
||
| 670 | * @return User |
||
| 671 | */ |
||
| 672 | public function getOwner() |
||
| 676 | |||
| 677 | /** |
||
| 678 | * @param User $user |
||
| 679 | */ |
||
| 680 | public function setOwner(User $user) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Set organization |
||
| 687 | * |
||
| 688 | * @param Organization $organization |
||
| 689 | * @return Order |
||
| 690 | */ |
||
| 691 | public function setOrganization(Organization $organization = null) |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Get organization |
||
| 700 | * |
||
| 701 | * @return Organization |
||
| 702 | */ |
||
| 703 | public function getOrganization() |
||
| 707 | |||
| 708 | /** |
||
| 709 | * @return string |
||
| 710 | */ |
||
| 711 | public function getCouponCode() |
||
| 715 | |||
| 716 | /** |
||
| 717 | * @param string $couponCode |
||
| 718 | * @return Order |
||
| 719 | */ |
||
| 720 | public function setCouponCode($couponCode) |
||
| 726 | |||
| 727 | /** |
||
| 728 | * @return bool |
||
| 729 | */ |
||
| 730 | public function isCanceled() |
||
| 734 | |||
| 735 | /** |
||
| 736 | * @return bool |
||
| 737 | */ |
||
| 738 | public function isCompleted() |
||
| 742 | |||
| 743 | /** |
||
| 744 | * @return \DateTime |
||
| 745 | */ |
||
| 746 | public function getSyncedAt() |
||
| 750 | |||
| 751 | /** |
||
| 752 | * @param \DateTime $syncedAt |
||
| 753 | * @return Customer |
||
| 754 | */ |
||
| 755 | public function setSyncedAt(\DateTime $syncedAt) |
||
| 761 | |||
| 762 | /** |
||
| 763 | * @return \DateTime |
||
| 764 | */ |
||
| 765 | public function getImportedAt() |
||
| 769 | |||
| 770 | /** |
||
| 771 | * @param \DateTime $importedAt |
||
| 772 | * @return Customer |
||
| 773 | */ |
||
| 774 | public function setImportedAt(\DateTime $importedAt) |
||
| 780 | |||
| 781 | /** |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | public function __toString() |
||
| 788 | } |
||
| 789 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..