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 |
||
72 | class Cart extends ExtendCart implements |
||
73 | ChannelAwareInterface, |
||
74 | FirstNameInterface, |
||
75 | LastNameInterface, |
||
76 | OriginAwareInterface, |
||
77 | IntegrationAwareInterface |
||
78 | { |
||
79 | use IntegrationEntityTrait, OriginTrait, NamesAwareTrait, ChannelEntityTrait; |
||
80 | |||
81 | /** |
||
82 | * @var CartItem[]|Collection |
||
83 | * |
||
84 | * @ORM\OneToMany(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartItem", |
||
85 | * mappedBy="cart", cascade={"all"}, orphanRemoval=true |
||
86 | * ) |
||
87 | * @ORM\OrderBy({"originId" = "DESC"}) |
||
88 | * @ConfigField( |
||
89 | * defaultValues={ |
||
90 | * "importexport"={ |
||
91 | * "full"=true |
||
92 | * } |
||
93 | * } |
||
94 | * ) |
||
95 | */ |
||
96 | protected $cartItems; |
||
97 | |||
98 | /** |
||
99 | * @ORM\ManyToOne(targetEntity="Customer", inversedBy="carts") |
||
100 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE") |
||
101 | */ |
||
102 | protected $customer; |
||
103 | |||
104 | /** |
||
105 | * @var Store |
||
106 | * |
||
107 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\Store") |
||
108 | * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL") |
||
109 | * @ConfigField( |
||
110 | * defaultValues={ |
||
111 | * "importexport"={ |
||
112 | * "full"=false |
||
113 | * } |
||
114 | * } |
||
115 | * ) |
||
116 | */ |
||
117 | protected $store; |
||
118 | |||
119 | /** |
||
120 | * Total items qty |
||
121 | * |
||
122 | * @var float |
||
123 | * |
||
124 | * @ORM\Column(name="items_qty", type="float") |
||
125 | */ |
||
126 | protected $itemsQty; |
||
127 | |||
128 | /** |
||
129 | * Items count |
||
130 | * |
||
131 | * @var integer |
||
132 | * |
||
133 | * @ORM\Column(name="items_count", type="integer", options={"unsigned"=true}) |
||
134 | */ |
||
135 | protected $itemsCount; |
||
136 | |||
137 | /** |
||
138 | * @var string |
||
139 | * |
||
140 | * @ORM\Column(name="base_currency_code", type="string", length=32, nullable=false) |
||
141 | */ |
||
142 | protected $baseCurrencyCode; |
||
143 | |||
144 | /** |
||
145 | * @var string |
||
146 | * |
||
147 | * @ORM\Column(name="store_currency_code", type="string", length=32, nullable=false) |
||
148 | */ |
||
149 | protected $storeCurrencyCode; |
||
150 | |||
151 | /** |
||
152 | * @var string |
||
153 | * |
||
154 | * @ORM\Column(name="quote_currency_code", type="string", length=32, nullable=false) |
||
155 | */ |
||
156 | protected $quoteCurrencyCode; |
||
157 | |||
158 | /** |
||
159 | * @var float |
||
160 | * |
||
161 | * @ORM\Column(name="store_to_base_rate", type="float", nullable=false) |
||
162 | */ |
||
163 | protected $storeToBaseRate; |
||
164 | |||
165 | /** |
||
166 | * @var float |
||
167 | * |
||
168 | * @ORM\Column(name="store_to_quote_rate", type="float", nullable=true) |
||
169 | */ |
||
170 | protected $storeToQuoteRate; |
||
171 | |||
172 | /** |
||
173 | * @var string |
||
174 | * |
||
175 | * @ORM\Column(name="email", type="string", length=255, nullable=true) |
||
176 | * @ConfigField( |
||
177 | * defaultValues={ |
||
178 | * "entity"={ |
||
179 | * "contact_information"="email" |
||
180 | * } |
||
181 | * } |
||
182 | * ) |
||
183 | */ |
||
184 | protected $email; |
||
185 | |||
186 | /** |
||
187 | * @var string |
||
188 | * |
||
189 | * @ORM\Column(name="gift_message", type="string", length=255, nullable=true) |
||
190 | */ |
||
191 | protected $giftMessage; |
||
192 | |||
193 | /** |
||
194 | * @var float |
||
195 | * |
||
196 | * @ORM\Column(name="is_guest", type="boolean") |
||
197 | */ |
||
198 | protected $isGuest; |
||
199 | |||
200 | /** |
||
201 | * @var CartAddress $shippingAddress |
||
202 | * |
||
203 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"}) |
||
204 | * @ORM\JoinColumn(name="shipping_address_id", referencedColumnName="id", onDelete="SET NULL") |
||
205 | * @ConfigField( |
||
206 | * defaultValues={ |
||
207 | * "importexport"={ |
||
208 | * "full"=true |
||
209 | * } |
||
210 | * } |
||
211 | * ) |
||
212 | */ |
||
213 | protected $shippingAddress; |
||
214 | |||
215 | /** |
||
216 | * @var CartAddress $billingAddress |
||
217 | * |
||
218 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"}) |
||
219 | * @ORM\JoinColumn(name="billing_address_id", referencedColumnName="id", onDelete="SET NULL") |
||
220 | * @ConfigField( |
||
221 | * defaultValues={ |
||
222 | * "importexport"={ |
||
223 | * "full"=true |
||
224 | * } |
||
225 | * } |
||
226 | * ) |
||
227 | */ |
||
228 | protected $billingAddress; |
||
229 | |||
230 | /** |
||
231 | * @var string |
||
232 | * |
||
233 | * @ORM\Column(name="payment_details", type="string", length=255, nullable=true) |
||
234 | */ |
||
235 | protected $paymentDetails; |
||
236 | |||
237 | /** |
||
238 | * @var CartStatus |
||
239 | * |
||
240 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartStatus") |
||
241 | * @ORM\JoinColumn(name="status_name", referencedColumnName="name", onDelete="SET NULL") |
||
242 | * @ConfigField( |
||
243 | * defaultValues={ |
||
244 | * "importexport"={ |
||
245 | * "full"=false |
||
246 | * } |
||
247 | * } |
||
248 | * ) |
||
249 | */ |
||
250 | protected $status; |
||
251 | |||
252 | /** |
||
253 | * @var Opportunity |
||
254 | * |
||
255 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Opportunity") |
||
256 | * @ORM\JoinColumn(name="opportunity_id", referencedColumnName="id", onDelete="SET NULL") |
||
257 | */ |
||
258 | protected $opportunity; |
||
259 | |||
260 | /** |
||
261 | * @var string |
||
262 | * |
||
263 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
264 | */ |
||
265 | protected $notes; |
||
266 | |||
267 | /** |
||
268 | * @var WorkflowItem |
||
269 | * |
||
270 | * @ORM\OneToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowItem") |
||
271 | * @ORM\JoinColumn(name="workflow_item_id", referencedColumnName="id", onDelete="SET NULL") |
||
272 | */ |
||
273 | protected $workflowItem; |
||
274 | |||
275 | /** |
||
276 | * @var WorkflowStep |
||
277 | * |
||
278 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowStep") |
||
279 | * @ORM\JoinColumn(name="workflow_step_id", referencedColumnName="id", onDelete="SET NULL") |
||
280 | */ |
||
281 | protected $workflowStep; |
||
282 | |||
283 | /** |
||
284 | * @var string |
||
285 | * |
||
286 | * @ORM\Column(name="status_message", type="string", length=255, nullable=true) |
||
287 | */ |
||
288 | protected $statusMessage; |
||
289 | |||
290 | /** |
||
291 | * @var User |
||
292 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
293 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
294 | */ |
||
295 | protected $owner; |
||
296 | |||
297 | /** |
||
298 | * @var Organization |
||
299 | * |
||
300 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
301 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
302 | */ |
||
303 | protected $organization; |
||
304 | |||
305 | /** |
||
306 | * @var \DateTime |
||
307 | * |
||
308 | * @ORM\Column(type="datetime", name="imported_at", nullable=true) |
||
309 | */ |
||
310 | protected $importedAt; |
||
311 | |||
312 | /** |
||
313 | * @var \DateTime |
||
314 | * |
||
315 | * @ORM\Column(type="datetime", name="synced_at", nullable=true) |
||
316 | */ |
||
317 | protected $syncedAt; |
||
318 | |||
319 | /** |
||
320 | * @param WorkflowItem $workflowItem |
||
321 | * |
||
322 | * @return Cart |
||
323 | */ |
||
324 | public function setWorkflowItem($workflowItem) |
||
330 | |||
331 | /** |
||
332 | * @return WorkflowItem |
||
333 | */ |
||
334 | public function getWorkflowItem() |
||
338 | |||
339 | /** |
||
340 | * @param WorkflowStep $workflowStep |
||
341 | * |
||
342 | * @return Cart |
||
343 | */ |
||
344 | public function setWorkflowStep($workflowStep) |
||
350 | |||
351 | /** |
||
352 | * @return WorkflowStep |
||
353 | */ |
||
354 | public function getWorkflowStep() |
||
358 | |||
359 | public function __construct() |
||
366 | |||
367 | /** |
||
368 | * @return CartItem[]|Collection |
||
369 | */ |
||
370 | public function getCartItems() |
||
374 | |||
375 | /** |
||
376 | * @param CartItem[]|Collection $cartItems |
||
377 | */ |
||
378 | public function setCartItems(Collection $cartItems) |
||
382 | |||
383 | /** |
||
384 | * @param Store $store |
||
385 | */ |
||
386 | public function setStore($store) |
||
390 | |||
391 | /** |
||
392 | * @return Store |
||
393 | */ |
||
394 | public function getStore() |
||
398 | |||
399 | /** |
||
400 | * @return Customer |
||
401 | */ |
||
402 | public function getCustomer() |
||
406 | |||
407 | /** |
||
408 | * @param Customer|null $customer |
||
409 | * |
||
410 | * @return Cart |
||
411 | */ |
||
412 | public function setCustomer(Customer $customer = null) |
||
418 | |||
419 | /** |
||
420 | * @param CartAddress $shippingAddress |
||
421 | * |
||
422 | * @return Cart |
||
423 | */ |
||
424 | public function setShippingAddress(CartAddress $shippingAddress = null) |
||
430 | |||
431 | /** |
||
432 | * @param CartAddress $billingAddress |
||
433 | * |
||
434 | * @return Cart |
||
435 | */ |
||
436 | public function setBillingAddress(CartAddress $billingAddress = null) |
||
442 | |||
443 | /** |
||
444 | * @return CartAddress |
||
445 | */ |
||
446 | public function getBillingAddress() |
||
450 | |||
451 | /** |
||
452 | * @return CartAddress |
||
453 | */ |
||
454 | public function getShippingAddress() |
||
458 | |||
459 | /** |
||
460 | * @return string |
||
461 | */ |
||
462 | public function getEmail() |
||
466 | |||
467 | /** |
||
468 | * @param string $email |
||
469 | * |
||
470 | * @return Cart |
||
471 | */ |
||
472 | public function setEmail($email) |
||
478 | |||
479 | /** |
||
480 | * @return float |
||
481 | */ |
||
482 | public function getItemsQty() |
||
486 | |||
487 | /** |
||
488 | * @param float $itemsQty |
||
489 | * |
||
490 | * @return Cart |
||
491 | */ |
||
492 | public function setItemsQty($itemsQty) |
||
498 | |||
499 | /** |
||
500 | * @return float |
||
501 | */ |
||
502 | public function getSubTotal() |
||
506 | |||
507 | /** |
||
508 | * @return string |
||
509 | */ |
||
510 | public function getQuoteCurrencyCode() |
||
514 | |||
515 | /** |
||
516 | * @param string $quoteCurrencyCode |
||
517 | * |
||
518 | * @return Cart |
||
519 | */ |
||
520 | public function setQuoteCurrencyCode($quoteCurrencyCode) |
||
526 | |||
527 | /** |
||
528 | * @param string $paymentDetails |
||
529 | */ |
||
530 | public function setPaymentDetails($paymentDetails) |
||
534 | |||
535 | /** |
||
536 | * @return string |
||
537 | */ |
||
538 | public function getPaymentDetails() |
||
542 | |||
543 | /** |
||
544 | * @param CartStatus $status |
||
545 | * |
||
546 | * @return Cart |
||
547 | */ |
||
548 | public function setStatus($status) |
||
554 | |||
555 | /** |
||
556 | * @return CartStatus |
||
557 | */ |
||
558 | public function getStatus() |
||
562 | |||
563 | /** |
||
564 | * @param string $baseCurrencyCode |
||
565 | * |
||
566 | * @return Cart |
||
567 | */ |
||
568 | public function setBaseCurrencyCode($baseCurrencyCode) |
||
574 | |||
575 | /** |
||
576 | * @return string |
||
577 | */ |
||
578 | public function getBaseCurrencyCode() |
||
582 | |||
583 | /** |
||
584 | * @param string $giftMessage |
||
585 | * |
||
586 | * @return Cart |
||
587 | */ |
||
588 | public function setGiftMessage($giftMessage) |
||
594 | |||
595 | /** |
||
596 | * @return string |
||
597 | */ |
||
598 | public function getGiftMessage() |
||
602 | |||
603 | /** |
||
604 | * @param float $isGuest |
||
605 | * |
||
606 | * @return Cart |
||
607 | */ |
||
608 | public function setIsGuest($isGuest) |
||
614 | |||
615 | /** |
||
616 | * @return float |
||
617 | */ |
||
618 | public function getIsGuest() |
||
622 | |||
623 | /** |
||
624 | * @param int $itemsCount |
||
625 | * |
||
626 | * @return Cart |
||
627 | */ |
||
628 | public function setItemsCount($itemsCount) |
||
634 | |||
635 | /** |
||
636 | * @return int |
||
637 | */ |
||
638 | public function getItemsCount() |
||
642 | |||
643 | /** |
||
644 | * @param string $storeCurrencyCode |
||
645 | * |
||
646 | * @return Cart |
||
647 | */ |
||
648 | public function setStoreCurrencyCode($storeCurrencyCode) |
||
654 | |||
655 | /** |
||
656 | * @return string |
||
657 | */ |
||
658 | public function getStoreCurrencyCode() |
||
662 | |||
663 | /** |
||
664 | * @param float $storeToBaseRate |
||
665 | * |
||
666 | * @return Cart |
||
667 | */ |
||
668 | public function setStoreToBaseRate($storeToBaseRate) |
||
674 | |||
675 | /** |
||
676 | * @return float |
||
677 | */ |
||
678 | public function getStoreToBaseRate() |
||
682 | |||
683 | /** |
||
684 | * @param float $storeToQuoteRate |
||
685 | * |
||
686 | * @return Cart |
||
687 | */ |
||
688 | public function setStoreToQuoteRate($storeToQuoteRate) |
||
694 | |||
695 | /** |
||
696 | * @return float |
||
697 | */ |
||
698 | public function getStoreToQuoteRate() |
||
702 | |||
703 | /** |
||
704 | * @param Opportunity $opportunity |
||
705 | * |
||
706 | * @return Cart |
||
707 | */ |
||
708 | public function setOpportunity($opportunity) |
||
714 | |||
715 | /** |
||
716 | * @return Opportunity |
||
717 | */ |
||
718 | public function getOpportunity() |
||
722 | |||
723 | /** |
||
724 | * @param string $notes |
||
725 | * |
||
726 | * @return Cart |
||
727 | */ |
||
728 | public function setNotes($notes) |
||
733 | |||
734 | /** |
||
735 | * @return string |
||
736 | */ |
||
737 | public function getNotes() |
||
741 | |||
742 | /** |
||
743 | * Pre persist event listener |
||
744 | * |
||
745 | * @ORM\PrePersist |
||
746 | */ |
||
747 | public function beforeSave() |
||
751 | |||
752 | /** |
||
753 | * Pre update event handler |
||
754 | * |
||
755 | * @ORM\PreUpdate |
||
756 | */ |
||
757 | public function doPreUpdate() |
||
761 | |||
762 | /** |
||
763 | * @param string $statusMessage |
||
764 | */ |
||
765 | public function setStatusMessage($statusMessage) |
||
769 | |||
770 | /** |
||
771 | * @return string |
||
772 | */ |
||
773 | public function getStatusMessage() |
||
777 | |||
778 | /** |
||
779 | * @return User |
||
780 | */ |
||
781 | public function getOwner() |
||
785 | |||
786 | /** |
||
787 | * @param User $user |
||
788 | */ |
||
789 | public function setOwner(User $user) |
||
793 | |||
794 | /** |
||
795 | * Set organization |
||
796 | * |
||
797 | * @param Organization $organization |
||
798 | * @return Cart |
||
799 | */ |
||
800 | public function setOrganization(Organization $organization = null) |
||
806 | |||
807 | /** |
||
808 | * Get organization |
||
809 | * |
||
810 | * @return Organization |
||
811 | */ |
||
812 | public function getOrganization() |
||
816 | |||
817 | /** |
||
818 | * @return \DateTime |
||
819 | */ |
||
820 | public function getSyncedAt() |
||
824 | |||
825 | /** |
||
826 | * @param \DateTime $syncedAt |
||
827 | * @return Customer |
||
828 | */ |
||
829 | public function setSyncedAt(\DateTime $syncedAt) |
||
835 | |||
836 | /** |
||
837 | * @return \DateTime |
||
838 | */ |
||
839 | public function getImportedAt() |
||
843 | |||
844 | /** |
||
845 | * @param \DateTime $importedAt |
||
846 | * @return Customer |
||
847 | */ |
||
848 | public function setImportedAt(\DateTime $importedAt) |
||
854 | |||
855 | /** |
||
856 | * @return string |
||
857 | */ |
||
858 | public function __toString() |
||
862 | } |
||
863 |