Complex classes like Opportunity 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 Opportunity, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
70 | class Opportunity extends ExtendOpportunity implements |
||
71 | EmailHolderInterface, |
||
72 | ChannelAwareInterface, |
||
73 | MultiCurrencyHolderInterface |
||
74 | { |
||
75 | use ChannelEntityTrait; |
||
76 | |||
77 | const INTERNAL_STATUS_CODE = 'opportunity_status'; |
||
78 | |||
79 | const STATUS_LOST = 'lost'; |
||
80 | const STATUS_WON = 'won'; |
||
81 | |||
82 | /** |
||
83 | * The key in system config for probability - status map |
||
84 | */ |
||
85 | const PROBABILITIES_CONFIG_KEY = 'oro_crm_sales.default_opportunity_probabilities'; |
||
86 | |||
87 | /** |
||
88 | * @var int |
||
89 | * |
||
90 | * @ORM\Id |
||
91 | * @ORM\Column(type="integer", name="id") |
||
92 | * @ORM\GeneratedValue(strategy="AUTO") |
||
93 | * @ConfigField( |
||
94 | * defaultValues={ |
||
95 | * "importexport"={ |
||
96 | * "order"=0 |
||
97 | * } |
||
98 | * } |
||
99 | * ) |
||
100 | */ |
||
101 | protected $id; |
||
102 | |||
103 | /** |
||
104 | * @var OpportunityCloseReason |
||
105 | * |
||
106 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\OpportunityCloseReason") |
||
107 | * @ORM\JoinColumn(name="close_reason_name", referencedColumnName="name") |
||
108 | * @Oro\Versioned |
||
109 | * @ConfigField( |
||
110 | * defaultValues={ |
||
111 | * "dataaudit"={"auditable"=true}, |
||
112 | * "importexport"={ |
||
113 | * "order"=100, |
||
114 | * "short"=true |
||
115 | * } |
||
116 | * } |
||
117 | * ) |
||
118 | **/ |
||
119 | protected $closeReason; |
||
120 | |||
121 | /** |
||
122 | * @var Contact |
||
123 | * |
||
124 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", cascade={"persist"}) |
||
125 | * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL") |
||
126 | * @Oro\Versioned |
||
127 | * @ConfigField( |
||
128 | * defaultValues={ |
||
129 | * "dataaudit"={"auditable"=true}, |
||
130 | * "importexport"={ |
||
131 | * "order"=120, |
||
132 | * "short"=true |
||
133 | * }, |
||
134 | * "form"={ |
||
135 | * "form_type"="orocrm_contact_select" |
||
136 | * } |
||
137 | * } |
||
138 | * ) |
||
139 | **/ |
||
140 | protected $contact; |
||
141 | |||
142 | /** |
||
143 | * @var Lead |
||
144 | * |
||
145 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Lead", inversedBy="opportunities") |
||
146 | * @ORM\JoinColumn(name="lead_id", referencedColumnName="id", onDelete="SET NULL") |
||
147 | * @Oro\Versioned |
||
148 | * @ConfigField( |
||
149 | * defaultValues={ |
||
150 | * "dataaudit"={"auditable"=true}, |
||
151 | * "importexport"={ |
||
152 | * "order"=130, |
||
153 | * "short"=true |
||
154 | * } |
||
155 | * } |
||
156 | * ) |
||
157 | **/ |
||
158 | protected $lead; |
||
159 | |||
160 | /** |
||
161 | * @var User |
||
162 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
163 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
164 | * @Oro\Versioned |
||
165 | * @ConfigField( |
||
166 | * defaultValues={ |
||
167 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
168 | * "importexport"={ |
||
169 | * "order"=140, |
||
170 | * "short"=true |
||
171 | * } |
||
172 | * } |
||
173 | * ) |
||
174 | */ |
||
175 | protected $owner; |
||
176 | |||
177 | /** |
||
178 | * @var string |
||
179 | * |
||
180 | * @ORM\Column(name="name", type="string", length=255, nullable=false) |
||
181 | * @Oro\Versioned |
||
182 | * @ConfigField( |
||
183 | * defaultValues={ |
||
184 | * "dataaudit"={"auditable"=true}, |
||
185 | * "importexport"={ |
||
186 | * "order"=10, |
||
187 | * "identity"=true |
||
188 | * } |
||
189 | * } |
||
190 | * ) |
||
191 | */ |
||
192 | protected $name; |
||
193 | |||
194 | /** |
||
195 | * @var \DateTime |
||
196 | * |
||
197 | * @ORM\Column(name="close_date", type="date", nullable=true) |
||
198 | * @Oro\Versioned |
||
199 | * @ConfigField( |
||
200 | * defaultValues={ |
||
201 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
202 | * "importexport"={ |
||
203 | * "order"=20 |
||
204 | * } |
||
205 | * } |
||
206 | * ) |
||
207 | */ |
||
208 | protected $closeDate; |
||
209 | |||
210 | /** |
||
211 | * @var float |
||
212 | * |
||
213 | * @ORM\Column(name="probability", type="percent", nullable=true) |
||
214 | * @Oro\Versioned |
||
215 | * @ConfigField( |
||
216 | * defaultValues={ |
||
217 | * "form"={ |
||
218 | * "form_type"="oro_percent", |
||
219 | * "form_options"={ |
||
220 | * "constraints"={{"Range":{"min":0, "max":100}}}, |
||
221 | * } |
||
222 | * }, |
||
223 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
224 | * "importexport"={ |
||
225 | * "order"=30 |
||
226 | * } |
||
227 | * } |
||
228 | * ) |
||
229 | */ |
||
230 | protected $probability; |
||
231 | |||
232 | /** |
||
233 | * Changes to this value object wont affect entity change set |
||
234 | * To change persisted price value you should create and set new Multicurrency |
||
235 | * |
||
236 | * @var Multicurrency |
||
237 | */ |
||
238 | protected $budgetAmount; |
||
239 | |||
240 | /** |
||
241 | * @var string |
||
242 | * |
||
243 | * @ORM\Column(name="budget_amount_currency", type="currency", length=3, nullable=true) |
||
244 | * @Oro\Versioned |
||
245 | * @ConfigField( |
||
246 | * defaultValues={ |
||
247 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
248 | * "importexport"={ |
||
249 | * "order"=55 |
||
250 | * } |
||
251 | * } |
||
252 | * ) |
||
253 | */ |
||
254 | protected $budgetAmountCurrency; |
||
255 | |||
256 | /** |
||
257 | * @var double |
||
258 | * |
||
259 | * @ORM\Column(name="budget_amount_value", type="money", nullable=true) |
||
260 | * @Oro\Versioned |
||
261 | * @ConfigField( |
||
262 | * defaultValues={ |
||
263 | * "form"={ |
||
264 | * "form_type"="oro_money", |
||
265 | * "form_options"={ |
||
266 | * "constraints"={{"Range":{"min":0}}}, |
||
267 | * } |
||
268 | * }, |
||
269 | * "dataaudit"={ |
||
270 | * "auditable"=true |
||
271 | * }, |
||
272 | * "importexport"={ |
||
273 | * "order"=50 |
||
274 | * } |
||
275 | * } |
||
276 | * ) |
||
277 | */ |
||
278 | protected $budgetAmountValue; |
||
279 | |||
280 | /** |
||
281 | * Changes to this value object wont affect entity change set |
||
282 | * To change persisted price value you should create and set new Multicurrency |
||
283 | * |
||
284 | * @var Multicurrency |
||
285 | */ |
||
286 | protected $closeRevenue; |
||
287 | |||
288 | /** |
||
289 | * @var string |
||
290 | * |
||
291 | * @ORM\Column(name="close_revenue_currency", type="currency", length=3, nullable=true) |
||
292 | * @Oro\Versioned |
||
293 | * @ConfigField( |
||
294 | * defaultValues={ |
||
295 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
296 | * "importexport"={ |
||
297 | * "order"=65 |
||
298 | * } |
||
299 | * } |
||
300 | * ) |
||
301 | */ |
||
302 | protected $closeRevenueCurrency; |
||
303 | |||
304 | /** |
||
305 | * @var double |
||
306 | * |
||
307 | * @ORM\Column(name="close_revenue_value", type="money", nullable=true) |
||
308 | * @Oro\Versioned |
||
309 | * @ConfigField( |
||
310 | * defaultValues={ |
||
311 | * "form"={ |
||
312 | * "form_type"="oro_money", |
||
313 | * "form_options"={ |
||
314 | * "constraints"={{"Range":{"min":0}}}, |
||
315 | * } |
||
316 | * }, |
||
317 | * "dataaudit"={ |
||
318 | * "auditable"=true |
||
319 | * }, |
||
320 | * "importexport"={ |
||
321 | * "order"=60 |
||
322 | * } |
||
323 | * } |
||
324 | * ) |
||
325 | */ |
||
326 | protected $closeRevenueValue; |
||
327 | |||
328 | /** |
||
329 | * @var string |
||
330 | * |
||
331 | * @ORM\Column(name="customer_need", type="text", nullable=true) |
||
332 | * @Oro\Versioned |
||
333 | * @ConfigField( |
||
334 | * defaultValues={ |
||
335 | * "dataaudit"={"auditable"=true}, |
||
336 | * "importexport"={ |
||
337 | * "order"=60 |
||
338 | * } |
||
339 | * } |
||
340 | * ) |
||
341 | */ |
||
342 | protected $customerNeed; |
||
343 | |||
344 | /** |
||
345 | * @var string |
||
346 | * |
||
347 | * @ORM\Column(name="proposed_solution", type="text", nullable=true) |
||
348 | * @Oro\Versioned |
||
349 | * @ConfigField( |
||
350 | * defaultValues={ |
||
351 | * "dataaudit"={"auditable"=true}, |
||
352 | * "importexport"={ |
||
353 | * "order"=70 |
||
354 | * } |
||
355 | * } |
||
356 | * ) |
||
357 | */ |
||
358 | protected $proposedSolution; |
||
359 | |||
360 | /** |
||
361 | * @var \DateTime |
||
362 | * |
||
363 | * @ORM\Column(name="created_at", type="datetime") |
||
364 | * @ConfigField( |
||
365 | * defaultValues={ |
||
366 | * "entity"={ |
||
367 | * "label"="oro.ui.created_at" |
||
368 | * }, |
||
369 | * "importexport"={ |
||
370 | * "excluded"=true |
||
371 | * } |
||
372 | * } |
||
373 | * ) |
||
374 | */ |
||
375 | protected $createdAt; |
||
376 | |||
377 | /** |
||
378 | * @var \DateTime |
||
379 | * |
||
380 | * @ORM\Column(name="updated_at", type="datetime") |
||
381 | * @ConfigField( |
||
382 | * defaultValues={ |
||
383 | * "entity"={ |
||
384 | * "label"="oro.ui.updated_at" |
||
385 | * }, |
||
386 | * "importexport"={ |
||
387 | * "excluded"=true |
||
388 | * } |
||
389 | * } |
||
390 | * ) |
||
391 | */ |
||
392 | protected $updatedAt; |
||
393 | |||
394 | /** |
||
395 | * @var string |
||
396 | * |
||
397 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
398 | * @Oro\Versioned |
||
399 | * @ConfigField( |
||
400 | * defaultValues={ |
||
401 | * "dataaudit"={ |
||
402 | * "auditable"=true |
||
403 | * }, |
||
404 | * "importexport"={ |
||
405 | * "order"=80 |
||
406 | * } |
||
407 | * } |
||
408 | * ) |
||
409 | */ |
||
410 | protected $notes; |
||
411 | |||
412 | /** |
||
413 | * @var Organization |
||
414 | * |
||
415 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
416 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
417 | */ |
||
418 | protected $organization; |
||
419 | |||
420 | /** |
||
421 | * @var B2bCustomer |
||
422 | * |
||
423 | * @ORM\ManyToOne( |
||
424 | * targetEntity="OroCRM\Bundle\SalesBundle\Entity\B2bCustomer", |
||
425 | * inversedBy="opportunities", |
||
426 | * cascade={"persist"} |
||
427 | * ) |
||
428 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL") |
||
429 | * @Oro\Versioned |
||
430 | * @ConfigField( |
||
431 | * defaultValues={ |
||
432 | * "dataaudit"={"auditable"=true}, |
||
433 | * "importexport"={ |
||
434 | * "order"=110, |
||
435 | * "short"=true |
||
436 | * }, |
||
437 | * "form"={ |
||
438 | * "form_type"="orocrm_sales_b2bcustomer_select" |
||
439 | * } |
||
440 | * } |
||
441 | * ) |
||
442 | */ |
||
443 | protected $customer; |
||
444 | |||
445 | /** |
||
446 | * @var \DateTime |
||
447 | * |
||
448 | * @ORM\Column(type="datetime", name="closed_at", nullable=true) |
||
449 | * @ConfigField( |
||
450 | * defaultValues={ |
||
451 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
452 | * "importexport"={"excluded"=true, "immutable"=true} |
||
453 | * } |
||
454 | * ) |
||
455 | */ |
||
456 | protected $closedAt; |
||
457 | |||
458 | /** |
||
459 | * @return int |
||
460 | */ |
||
461 | public function getId() |
||
465 | |||
466 | /** |
||
467 | * @param Lead $lead |
||
468 | * @return Opportunity |
||
469 | */ |
||
470 | public function setLead($lead) |
||
476 | |||
477 | /** |
||
478 | * @return Lead |
||
479 | */ |
||
480 | public function getLead() |
||
484 | |||
485 | /** |
||
486 | * @return MultiCurrency|null |
||
487 | */ |
||
488 | public function getBudgetAmount() |
||
492 | |||
493 | /** |
||
494 | * @param MultiCurrency $budgetAmount|null |
||
|
|||
495 | * @return Opportunity |
||
496 | */ |
||
497 | public function setBudgetAmount(MultiCurrency $budgetAmount = null) |
||
504 | |||
505 | /** |
||
506 | * @ORM\PostLoad |
||
507 | */ |
||
508 | public function loadMultiCurrencyFields() |
||
513 | |||
514 | /** |
||
515 | * @ORM\PrePersist |
||
516 | * @ORM\PreUpdate |
||
517 | * |
||
518 | * @return void |
||
519 | */ |
||
520 | public function updateMultiCurrencyFields() |
||
537 | |||
538 | /** |
||
539 | * @param string $currency |
||
540 | * @return Opportunity |
||
541 | */ |
||
542 | public function setBudgetAmountCurrency($currency) |
||
552 | |||
553 | /** |
||
554 | * @param string $budgetAmountValue |
||
555 | * @return Opportunity |
||
556 | */ |
||
557 | public function setBudgetAmountValue($budgetAmountValue) |
||
567 | |||
568 | /** |
||
569 | * @return string |
||
570 | */ |
||
571 | public function getBudgetAmountCurrency() |
||
575 | |||
576 | /** |
||
577 | * @return float |
||
578 | */ |
||
579 | public function getBudgetAmountValue() |
||
583 | |||
584 | /** |
||
585 | * @param string $currency |
||
586 | * @return Opportunity |
||
587 | */ |
||
588 | public function setCloseRevenueCurrency($currency) |
||
598 | |||
599 | /** |
||
600 | * @param float $closeRevenueValue |
||
601 | * @return Opportunity |
||
602 | */ |
||
603 | public function setCloseRevenueValue($closeRevenueValue) |
||
613 | |||
614 | /** |
||
615 | * @return string |
||
616 | */ |
||
617 | public function getCloseRevenueCurrency() |
||
621 | |||
622 | /** |
||
623 | * @return float |
||
624 | */ |
||
625 | public function getCloseRevenueValue() |
||
629 | |||
630 | /** |
||
631 | * @param \DateTime $closeDate |
||
632 | * @return Opportunity |
||
633 | */ |
||
634 | public function setCloseDate($closeDate) |
||
640 | |||
641 | /** |
||
642 | * @return \DateTime |
||
643 | */ |
||
644 | public function getCloseDate() |
||
648 | |||
649 | /** |
||
650 | * @param Contact $contact |
||
651 | * @return Opportunity |
||
652 | */ |
||
653 | public function setContact($contact) |
||
659 | |||
660 | /** |
||
661 | * @return Contact |
||
662 | */ |
||
663 | public function getContact() |
||
667 | |||
668 | /** |
||
669 | * @param string $customerNeed |
||
670 | * @return Opportunity |
||
671 | */ |
||
672 | public function setCustomerNeed($customerNeed) |
||
678 | |||
679 | /** |
||
680 | * @return string |
||
681 | */ |
||
682 | public function getCustomerNeed() |
||
686 | |||
687 | /** |
||
688 | * @param float $probability |
||
689 | * @return Opportunity |
||
690 | */ |
||
691 | public function setProbability($probability) |
||
697 | |||
698 | /** |
||
699 | * @return float |
||
700 | */ |
||
701 | public function getProbability() |
||
705 | |||
706 | /** |
||
707 | * @param string $proposedSolution |
||
708 | * @return Opportunity |
||
709 | */ |
||
710 | public function setProposedSolution($proposedSolution) |
||
716 | |||
717 | /** |
||
718 | * @return string |
||
719 | */ |
||
720 | public function getProposedSolution() |
||
724 | |||
725 | /** |
||
726 | * @param string $name |
||
727 | * @return Opportunity |
||
728 | */ |
||
729 | public function setName($name) |
||
735 | |||
736 | /** |
||
737 | * @return string |
||
738 | */ |
||
739 | public function getName() |
||
743 | |||
744 | /** |
||
745 | * @param OpportunityCloseReason $closeReason |
||
746 | * @return Opportunity |
||
747 | */ |
||
748 | public function setCloseReason($closeReason) |
||
754 | |||
755 | /** |
||
756 | * @return OpportunityCloseReason |
||
757 | */ |
||
758 | public function getCloseReason() |
||
762 | |||
763 | /** |
||
764 | * @param MultiCurrency $closeRevenue|null |
||
765 | * @return Opportunity |
||
766 | */ |
||
767 | public function setCloseRevenue(MultiCurrency $closeRevenue = null) |
||
776 | |||
777 | /** |
||
778 | * @return MultiCurrency|null |
||
779 | */ |
||
780 | public function getCloseRevenue() |
||
784 | |||
785 | /** |
||
786 | * @return \DateTime |
||
787 | */ |
||
788 | public function getCreatedAt() |
||
792 | |||
793 | /** |
||
794 | * @param \DateTime $created |
||
795 | * @return Opportunity |
||
796 | */ |
||
797 | public function setCreatedAt($created) |
||
803 | |||
804 | /** |
||
805 | * @return \DateTime |
||
806 | */ |
||
807 | public function getUpdatedAt() |
||
811 | |||
812 | /** |
||
813 | * @param \DateTime $updated |
||
814 | * @return Opportunity |
||
815 | */ |
||
816 | public function setUpdatedAt($updated) |
||
822 | |||
823 | /** |
||
824 | * Get the primary email address of the related contact |
||
825 | * |
||
826 | * @return string |
||
827 | */ |
||
828 | public function getEmail() |
||
837 | |||
838 | public function __toString() |
||
842 | /** |
||
843 | * @ORM\PrePersist |
||
844 | */ |
||
845 | public function beforeSave() |
||
850 | |||
851 | /** |
||
852 | * @ORM\PreUpdate |
||
853 | */ |
||
854 | public function beforeUpdate() |
||
858 | |||
859 | /** |
||
860 | * @return User |
||
861 | */ |
||
862 | public function getOwner() |
||
866 | |||
867 | /** |
||
868 | * @param User $owningUser |
||
869 | * @return Opportunity |
||
870 | */ |
||
871 | public function setOwner($owningUser) |
||
877 | |||
878 | /** |
||
879 | * @return string |
||
880 | */ |
||
881 | public function getNotes() |
||
885 | |||
886 | /** |
||
887 | * @param string $notes |
||
888 | * @return Opportunity |
||
889 | */ |
||
890 | public function setNotes($notes) |
||
896 | |||
897 | /** |
||
898 | * @param B2bCustomer $customer |
||
899 | * @TODO remove null after BAP-5248 |
||
900 | */ |
||
901 | public function setCustomer(B2bCustomer $customer = null) |
||
905 | |||
906 | /** |
||
907 | * @return B2bCustomer |
||
908 | */ |
||
909 | public function getCustomer() |
||
913 | |||
914 | /** |
||
915 | * Set organization |
||
916 | * |
||
917 | * @param Organization $organization |
||
918 | * @return Opportunity |
||
919 | */ |
||
920 | public function setOrganization(Organization $organization = null) |
||
926 | |||
927 | /** |
||
928 | * Get organization |
||
929 | * |
||
930 | * @return Organization |
||
931 | */ |
||
932 | public function getOrganization() |
||
936 | |||
937 | /** |
||
938 | * Remove Customer |
||
939 | * |
||
940 | * @return Lead |
||
941 | */ |
||
942 | public function removeCustomer() |
||
946 | |||
947 | /** |
||
948 | * @param \DateTime $closedAt |
||
949 | */ |
||
950 | public function setClosedAt(\DateTime $closedAt = null) |
||
954 | |||
955 | /** |
||
956 | * @return \DateTime |
||
957 | */ |
||
958 | public function getClosedAt() |
||
962 | } |
||
963 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.