Complex classes like Cart 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 Cart, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
73 | class Cart extends ExtendCart implements |
||
74 | ChannelAwareInterface, |
||
75 | FirstNameInterface, |
||
76 | LastNameInterface, |
||
77 | OriginAwareInterface, |
||
78 | IntegrationAwareInterface |
||
79 | { |
||
80 | use IntegrationEntityTrait, OriginTrait, NamesAwareTrait, ChannelEntityTrait; |
||
81 | |||
82 | /** |
||
83 | * @var CartItem[]|Collection |
||
84 | * |
||
85 | * @ORM\OneToMany(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartItem", |
||
86 | * mappedBy="cart", cascade={"all"}, orphanRemoval=true |
||
87 | * ) |
||
88 | * @ORM\OrderBy({"originId" = "DESC"}) |
||
89 | * @ConfigField( |
||
90 | * defaultValues={ |
||
91 | * "importexport"={ |
||
92 | * "full"=true |
||
93 | * } |
||
94 | * } |
||
95 | * ) |
||
96 | */ |
||
97 | protected $cartItems; |
||
98 | |||
99 | /** |
||
100 | * @ORM\ManyToOne(targetEntity="Customer", inversedBy="carts") |
||
101 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE") |
||
102 | */ |
||
103 | protected $customer; |
||
104 | |||
105 | /** |
||
106 | * @var Store |
||
107 | * |
||
108 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\Store") |
||
109 | * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL") |
||
110 | * @ConfigField( |
||
111 | * defaultValues={ |
||
112 | * "importexport"={ |
||
113 | * "full"=false |
||
114 | * } |
||
115 | * } |
||
116 | * ) |
||
117 | */ |
||
118 | protected $store; |
||
119 | |||
120 | /** |
||
121 | * Total items qty |
||
122 | * |
||
123 | * @var float |
||
124 | * |
||
125 | * @ORM\Column(name="items_qty", type="float") |
||
126 | */ |
||
127 | protected $itemsQty; |
||
128 | |||
129 | /** |
||
130 | * Items count |
||
131 | * |
||
132 | * @var integer |
||
133 | * |
||
134 | * @ORM\Column(name="items_count", type="integer", options={"unsigned"=true}) |
||
135 | */ |
||
136 | protected $itemsCount; |
||
137 | |||
138 | /** |
||
139 | * @var string |
||
140 | * |
||
141 | * @ORM\Column(name="base_currency_code", type="string", length=32, nullable=false) |
||
142 | */ |
||
143 | protected $baseCurrencyCode; |
||
144 | |||
145 | /** |
||
146 | * @var string |
||
147 | * |
||
148 | * @ORM\Column(name="store_currency_code", type="string", length=32, nullable=false) |
||
149 | */ |
||
150 | protected $storeCurrencyCode; |
||
151 | |||
152 | /** |
||
153 | * @var string |
||
154 | * |
||
155 | * @ORM\Column(name="quote_currency_code", type="string", length=32, nullable=false) |
||
156 | */ |
||
157 | protected $quoteCurrencyCode; |
||
158 | |||
159 | /** |
||
160 | * @var float |
||
161 | * |
||
162 | * @ORM\Column(name="store_to_base_rate", type="float", nullable=false) |
||
163 | */ |
||
164 | protected $storeToBaseRate; |
||
165 | |||
166 | /** |
||
167 | * @var float |
||
168 | * |
||
169 | * @ORM\Column(name="store_to_quote_rate", type="float", nullable=true) |
||
170 | */ |
||
171 | protected $storeToQuoteRate; |
||
172 | |||
173 | /** |
||
174 | * @var string |
||
175 | * |
||
176 | * @ORM\Column(name="email", type="string", length=255, nullable=true) |
||
177 | * @ConfigField( |
||
178 | * defaultValues={ |
||
179 | * "entity"={ |
||
180 | * "contact_information"="email" |
||
181 | * } |
||
182 | * } |
||
183 | * ) |
||
184 | */ |
||
185 | protected $email; |
||
186 | |||
187 | /** |
||
188 | * @var string |
||
189 | * |
||
190 | * @ORM\Column(name="gift_message", type="string", length=255, nullable=true) |
||
191 | */ |
||
192 | protected $giftMessage; |
||
193 | |||
194 | /** |
||
195 | * @var float |
||
196 | * |
||
197 | * @ORM\Column(name="is_guest", type="boolean") |
||
198 | */ |
||
199 | protected $isGuest; |
||
200 | |||
201 | /** |
||
202 | * @var CartAddress $shippingAddress |
||
203 | * |
||
204 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"}) |
||
205 | * @ORM\JoinColumn(name="shipping_address_id", referencedColumnName="id", onDelete="SET NULL") |
||
206 | * @ConfigField( |
||
207 | * defaultValues={ |
||
208 | * "importexport"={ |
||
209 | * "full"=true |
||
210 | * } |
||
211 | * } |
||
212 | * ) |
||
213 | */ |
||
214 | protected $shippingAddress; |
||
215 | |||
216 | /** |
||
217 | * @var CartAddress $billingAddress |
||
218 | * |
||
219 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"}) |
||
220 | * @ORM\JoinColumn(name="billing_address_id", referencedColumnName="id", onDelete="SET NULL") |
||
221 | * @ConfigField( |
||
222 | * defaultValues={ |
||
223 | * "importexport"={ |
||
224 | * "full"=true |
||
225 | * } |
||
226 | * } |
||
227 | * ) |
||
228 | */ |
||
229 | protected $billingAddress; |
||
230 | |||
231 | /** |
||
232 | * @var string |
||
233 | * |
||
234 | * @ORM\Column(name="payment_details", type="string", length=255, nullable=true) |
||
235 | */ |
||
236 | protected $paymentDetails; |
||
237 | |||
238 | /** |
||
239 | * @var CartStatus |
||
240 | * |
||
241 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartStatus") |
||
242 | * @ORM\JoinColumn(name="status_name", referencedColumnName="name", onDelete="SET NULL") |
||
243 | * @ConfigField( |
||
244 | * defaultValues={ |
||
245 | * "importexport"={ |
||
246 | * "full"=false |
||
247 | * } |
||
248 | * } |
||
249 | * ) |
||
250 | */ |
||
251 | protected $status; |
||
252 | |||
253 | /** |
||
254 | * @var Opportunity |
||
255 | * |
||
256 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Opportunity") |
||
257 | * @ORM\JoinColumn(name="opportunity_id", referencedColumnName="id", onDelete="SET NULL") |
||
258 | */ |
||
259 | protected $opportunity; |
||
260 | |||
261 | /** |
||
262 | * @var string |
||
263 | * |
||
264 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
265 | */ |
||
266 | protected $notes; |
||
267 | |||
268 | /** |
||
269 | * @var WorkflowItem |
||
270 | * |
||
271 | * @ORM\OneToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowItem") |
||
272 | * @ORM\JoinColumn(name="workflow_item_id", referencedColumnName="id", onDelete="SET NULL") |
||
273 | */ |
||
274 | protected $workflowItem; |
||
275 | |||
276 | /** |
||
277 | * @var WorkflowStep |
||
278 | * |
||
279 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowStep") |
||
280 | * @ORM\JoinColumn(name="workflow_step_id", referencedColumnName="id", onDelete="SET NULL") |
||
281 | */ |
||
282 | protected $workflowStep; |
||
283 | |||
284 | /** |
||
285 | * @var string |
||
286 | * |
||
287 | * @ORM\Column(name="status_message", type="string", length=255, nullable=true) |
||
288 | */ |
||
289 | protected $statusMessage; |
||
290 | |||
291 | /** |
||
292 | * @var User |
||
293 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
294 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
295 | */ |
||
296 | protected $owner; |
||
297 | |||
298 | /** |
||
299 | * @var Organization |
||
300 | * |
||
301 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
302 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
303 | */ |
||
304 | protected $organization; |
||
305 | |||
306 | /** |
||
307 | * @var \DateTime |
||
308 | * |
||
309 | * @ORM\Column(type="datetime", name="imported_at", nullable=true) |
||
310 | */ |
||
311 | protected $importedAt; |
||
312 | |||
313 | /** |
||
314 | * @var \DateTime |
||
315 | * |
||
316 | * @ORM\Column(type="datetime", name="synced_at", nullable=true) |
||
317 | */ |
||
318 | protected $syncedAt; |
||
319 | |||
320 | /** |
||
321 | * @param WorkflowItem $workflowItem |
||
322 | * |
||
323 | * @return Cart |
||
324 | */ |
||
325 | public function setWorkflowItem($workflowItem) |
||
331 | |||
332 | /** |
||
333 | * @return WorkflowItem |
||
334 | */ |
||
335 | public function getWorkflowItem() |
||
339 | |||
340 | /** |
||
341 | * @param WorkflowStep $workflowStep |
||
342 | * |
||
343 | * @return Cart |
||
344 | */ |
||
345 | public function setWorkflowStep($workflowStep) |
||
351 | |||
352 | /** |
||
353 | * @return WorkflowStep |
||
354 | */ |
||
355 | public function getWorkflowStep() |
||
359 | |||
360 | public function __construct() |
||
367 | |||
368 | /** |
||
369 | * @return CartItem[]|Collection |
||
370 | */ |
||
371 | public function getCartItems() |
||
375 | |||
376 | /** |
||
377 | * @param CartItem[]|Collection $cartItems |
||
378 | */ |
||
379 | public function setCartItems(Collection $cartItems) |
||
383 | |||
384 | /** |
||
385 | * @param CartItem $cartItem |
||
386 | * |
||
387 | * @return $this |
||
388 | */ |
||
389 | public function addCartItem(CartItem $cartItem) |
||
398 | |||
399 | /** |
||
400 | * @param CartItem $cartItem |
||
401 | * |
||
402 | * @return $this |
||
403 | */ |
||
404 | public function removeCartItem(CartItem $cartItem) |
||
412 | |||
413 | /** |
||
414 | * @param Store $store |
||
415 | */ |
||
416 | public function setStore($store) |
||
420 | |||
421 | /** |
||
422 | * @return Store |
||
423 | */ |
||
424 | public function getStore() |
||
428 | |||
429 | /** |
||
430 | * @return Customer |
||
431 | */ |
||
432 | public function getCustomer() |
||
436 | |||
437 | /** |
||
438 | * @param Customer|null $customer |
||
439 | * |
||
440 | * @return Cart |
||
441 | */ |
||
442 | public function setCustomer(Customer $customer = null) |
||
448 | |||
449 | /** |
||
450 | * @param CartAddress $shippingAddress |
||
451 | * |
||
452 | * @return Cart |
||
453 | */ |
||
454 | public function setShippingAddress(CartAddress $shippingAddress = null) |
||
460 | |||
461 | /** |
||
462 | * @param CartAddress $billingAddress |
||
463 | * |
||
464 | * @return Cart |
||
465 | */ |
||
466 | public function setBillingAddress(CartAddress $billingAddress = null) |
||
472 | |||
473 | /** |
||
474 | * @return CartAddress |
||
475 | */ |
||
476 | public function getBillingAddress() |
||
480 | |||
481 | /** |
||
482 | * @return CartAddress |
||
483 | */ |
||
484 | public function getShippingAddress() |
||
488 | |||
489 | /** |
||
490 | * @return string |
||
491 | */ |
||
492 | public function getEmail() |
||
496 | |||
497 | /** |
||
498 | * @param string $email |
||
499 | * |
||
500 | * @return Cart |
||
501 | */ |
||
502 | public function setEmail($email) |
||
508 | |||
509 | /** |
||
510 | * @return float |
||
511 | */ |
||
512 | public function getItemsQty() |
||
516 | |||
517 | /** |
||
518 | * @param float $itemsQty |
||
519 | * |
||
520 | * @return Cart |
||
521 | */ |
||
522 | public function setItemsQty($itemsQty) |
||
528 | |||
529 | /** |
||
530 | * @return float |
||
531 | */ |
||
532 | public function getSubTotal() |
||
536 | |||
537 | /** |
||
538 | * @return string |
||
539 | */ |
||
540 | public function getQuoteCurrencyCode() |
||
544 | |||
545 | /** |
||
546 | * @param string $quoteCurrencyCode |
||
547 | * |
||
548 | * @return Cart |
||
549 | */ |
||
550 | public function setQuoteCurrencyCode($quoteCurrencyCode) |
||
556 | |||
557 | /** |
||
558 | * @param string $paymentDetails |
||
559 | */ |
||
560 | public function setPaymentDetails($paymentDetails) |
||
564 | |||
565 | /** |
||
566 | * @return string |
||
567 | */ |
||
568 | public function getPaymentDetails() |
||
572 | |||
573 | /** |
||
574 | * @param CartStatus $status |
||
575 | * |
||
576 | * @return Cart |
||
577 | */ |
||
578 | public function setStatus($status) |
||
584 | |||
585 | /** |
||
586 | * @return CartStatus |
||
587 | */ |
||
588 | public function getStatus() |
||
592 | |||
593 | /** |
||
594 | * @param string $baseCurrencyCode |
||
595 | * |
||
596 | * @return Cart |
||
597 | */ |
||
598 | public function setBaseCurrencyCode($baseCurrencyCode) |
||
604 | |||
605 | /** |
||
606 | * @return string |
||
607 | */ |
||
608 | public function getBaseCurrencyCode() |
||
612 | |||
613 | /** |
||
614 | * @param string $giftMessage |
||
615 | * |
||
616 | * @return Cart |
||
617 | */ |
||
618 | public function setGiftMessage($giftMessage) |
||
624 | |||
625 | /** |
||
626 | * @return string |
||
627 | */ |
||
628 | public function getGiftMessage() |
||
632 | |||
633 | /** |
||
634 | * @param float $isGuest |
||
635 | * |
||
636 | * @return Cart |
||
637 | */ |
||
638 | public function setIsGuest($isGuest) |
||
644 | |||
645 | /** |
||
646 | * @return float |
||
647 | */ |
||
648 | public function getIsGuest() |
||
652 | |||
653 | /** |
||
654 | * @param int $itemsCount |
||
655 | * |
||
656 | * @return Cart |
||
657 | */ |
||
658 | public function setItemsCount($itemsCount) |
||
664 | |||
665 | /** |
||
666 | * @return int |
||
667 | */ |
||
668 | public function getItemsCount() |
||
672 | |||
673 | /** |
||
674 | * @param string $storeCurrencyCode |
||
675 | * |
||
676 | * @return Cart |
||
677 | */ |
||
678 | public function setStoreCurrencyCode($storeCurrencyCode) |
||
684 | |||
685 | /** |
||
686 | * @return string |
||
687 | */ |
||
688 | public function getStoreCurrencyCode() |
||
692 | |||
693 | /** |
||
694 | * @param float $storeToBaseRate |
||
695 | * |
||
696 | * @return Cart |
||
697 | */ |
||
698 | public function setStoreToBaseRate($storeToBaseRate) |
||
704 | |||
705 | /** |
||
706 | * @return float |
||
707 | */ |
||
708 | public function getStoreToBaseRate() |
||
712 | |||
713 | /** |
||
714 | * @param float $storeToQuoteRate |
||
715 | * |
||
716 | * @return Cart |
||
717 | */ |
||
718 | public function setStoreToQuoteRate($storeToQuoteRate) |
||
724 | |||
725 | /** |
||
726 | * @return float |
||
727 | */ |
||
728 | public function getStoreToQuoteRate() |
||
732 | |||
733 | /** |
||
734 | * @param Opportunity $opportunity |
||
735 | * |
||
736 | * @return Cart |
||
737 | */ |
||
738 | public function setOpportunity($opportunity) |
||
744 | |||
745 | /** |
||
746 | * @return Opportunity |
||
747 | */ |
||
748 | public function getOpportunity() |
||
752 | |||
753 | /** |
||
754 | * @param string $notes |
||
755 | * |
||
756 | * @return Cart |
||
757 | */ |
||
758 | public function setNotes($notes) |
||
763 | |||
764 | /** |
||
765 | * @return string |
||
766 | */ |
||
767 | public function getNotes() |
||
771 | |||
772 | /** |
||
773 | * Pre persist event listener |
||
774 | * |
||
775 | * @ORM\PrePersist |
||
776 | */ |
||
777 | public function beforeSave() |
||
781 | |||
782 | /** |
||
783 | * Pre update event handler |
||
784 | * |
||
785 | * @ORM\PreUpdate |
||
786 | */ |
||
787 | public function doPreUpdate() |
||
791 | |||
792 | /** |
||
793 | * @param string $statusMessage |
||
794 | */ |
||
795 | public function setStatusMessage($statusMessage) |
||
799 | |||
800 | /** |
||
801 | * @return string |
||
802 | */ |
||
803 | public function getStatusMessage() |
||
807 | |||
808 | /** |
||
809 | * @return User |
||
810 | */ |
||
811 | public function getOwner() |
||
815 | |||
816 | /** |
||
817 | * @param User $user |
||
818 | */ |
||
819 | public function setOwner(User $user) |
||
823 | |||
824 | /** |
||
825 | * Set organization |
||
826 | * |
||
827 | * @param Organization $organization |
||
828 | * @return Cart |
||
829 | */ |
||
830 | public function setOrganization(Organization $organization = null) |
||
836 | |||
837 | /** |
||
838 | * Get organization |
||
839 | * |
||
840 | * @return Organization |
||
841 | */ |
||
842 | public function getOrganization() |
||
846 | |||
847 | /** |
||
848 | * @return \DateTime |
||
849 | */ |
||
850 | public function getSyncedAt() |
||
854 | |||
855 | /** |
||
856 | * @param \DateTime|null $syncedAt |
||
857 | * @return Cart |
||
858 | */ |
||
859 | public function setSyncedAt(\DateTime $syncedAt = null) |
||
865 | |||
866 | /** |
||
867 | * @return \DateTime |
||
868 | */ |
||
869 | public function getImportedAt() |
||
873 | |||
874 | /** |
||
875 | * @param \DateTime|null $importedAt |
||
876 | * @return Cart |
||
877 | */ |
||
878 | public function setImportedAt(\DateTime $importedAt = null) |
||
884 | |||
885 | /** |
||
886 | * @return string |
||
887 | */ |
||
888 | public function __toString() |
||
892 | } |
||
893 |