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 |
||
| 68 | class Opportunity extends ExtendOpportunity implements |
||
| 69 | EmailHolderInterface, |
||
| 70 | ChannelAwareInterface |
||
| 71 | { |
||
| 72 | use ChannelEntityTrait; |
||
| 73 | |||
| 74 | const INTERNAL_STATUS_CODE = 'opportunity_status'; |
||
| 75 | |||
| 76 | const STATUS_LOST = 'lost'; |
||
| 77 | const STATUS_WON = 'won'; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The key in system config for probability - status map |
||
| 81 | */ |
||
| 82 | const PROBABILITIES_CONFIG_KEY = 'oro_crm_sales.default_opportunity_probabilities'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var int |
||
| 86 | * |
||
| 87 | * @ORM\Id |
||
| 88 | * @ORM\Column(type="integer", name="id") |
||
| 89 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 90 | * @ConfigField( |
||
| 91 | * defaultValues={ |
||
| 92 | * "importexport"={ |
||
| 93 | * "order"=0 |
||
| 94 | * } |
||
| 95 | * } |
||
| 96 | * ) |
||
| 97 | */ |
||
| 98 | protected $id; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var OpportunityCloseReason |
||
| 102 | * |
||
| 103 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\OpportunityCloseReason") |
||
| 104 | * @ORM\JoinColumn(name="close_reason_name", referencedColumnName="name") |
||
| 105 | * @Oro\Versioned |
||
| 106 | * @ConfigField( |
||
| 107 | * defaultValues={ |
||
| 108 | * "dataaudit"={"auditable"=true}, |
||
| 109 | * "importexport"={ |
||
| 110 | * "order"=100, |
||
| 111 | * "short"=true |
||
| 112 | * } |
||
| 113 | * } |
||
| 114 | * ) |
||
| 115 | **/ |
||
| 116 | protected $closeReason; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var Contact |
||
| 120 | * |
||
| 121 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", cascade={"persist"}) |
||
| 122 | * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 123 | * @Oro\Versioned |
||
| 124 | * @ConfigField( |
||
| 125 | * defaultValues={ |
||
| 126 | * "dataaudit"={"auditable"=true}, |
||
| 127 | * "importexport"={ |
||
| 128 | * "order"=120, |
||
| 129 | * "short"=true |
||
| 130 | * }, |
||
| 131 | * "form"={ |
||
| 132 | * "form_type"="orocrm_contact_select" |
||
| 133 | * } |
||
| 134 | * } |
||
| 135 | * ) |
||
| 136 | **/ |
||
| 137 | protected $contact; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var Lead |
||
| 141 | * |
||
| 142 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Lead", inversedBy="opportunities") |
||
| 143 | * @ORM\JoinColumn(name="lead_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 144 | * @Oro\Versioned |
||
| 145 | * @ConfigField( |
||
| 146 | * defaultValues={ |
||
| 147 | * "dataaudit"={"auditable"=true}, |
||
| 148 | * "importexport"={ |
||
| 149 | * "order"=130, |
||
| 150 | * "short"=true |
||
| 151 | * } |
||
| 152 | * } |
||
| 153 | * ) |
||
| 154 | **/ |
||
| 155 | protected $lead; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var User |
||
| 159 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
| 160 | * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 161 | * @Oro\Versioned |
||
| 162 | * @ConfigField( |
||
| 163 | * defaultValues={ |
||
| 164 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
| 165 | * "importexport"={ |
||
| 166 | * "order"=140, |
||
| 167 | * "short"=true |
||
| 168 | * } |
||
| 169 | * } |
||
| 170 | * ) |
||
| 171 | */ |
||
| 172 | protected $owner; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var string |
||
| 176 | * |
||
| 177 | * @ORM\Column(name="name", type="string", length=255, nullable=false) |
||
| 178 | * @Oro\Versioned |
||
| 179 | * @ConfigField( |
||
| 180 | * defaultValues={ |
||
| 181 | * "dataaudit"={"auditable"=true}, |
||
| 182 | * "importexport"={ |
||
| 183 | * "order"=10, |
||
| 184 | * "identity"=true |
||
| 185 | * } |
||
| 186 | * } |
||
| 187 | * ) |
||
| 188 | */ |
||
| 189 | protected $name; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @var \DateTime |
||
| 193 | * |
||
| 194 | * @ORM\Column(name="close_date", type="date", nullable=true) |
||
| 195 | * @Oro\Versioned |
||
| 196 | * @ConfigField( |
||
| 197 | * defaultValues={ |
||
| 198 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
| 199 | * "importexport"={ |
||
| 200 | * "order"=20 |
||
| 201 | * } |
||
| 202 | * } |
||
| 203 | * ) |
||
| 204 | */ |
||
| 205 | protected $closeDate; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @var float |
||
| 209 | * |
||
| 210 | * @ORM\Column(name="probability", type="percent", nullable=true) |
||
| 211 | * @Oro\Versioned |
||
| 212 | * @ConfigField( |
||
| 213 | * defaultValues={ |
||
| 214 | * "form"={ |
||
| 215 | * "form_type"="oro_percent", |
||
| 216 | * "form_options"={ |
||
| 217 | * "constraints"={{"Range":{"min":0, "max":100}}}, |
||
| 218 | * } |
||
| 219 | * }, |
||
| 220 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
| 221 | * "importexport"={ |
||
| 222 | * "order"=30 |
||
| 223 | * } |
||
| 224 | * } |
||
| 225 | * ) |
||
| 226 | */ |
||
| 227 | protected $probability; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @var double |
||
| 231 | * |
||
| 232 | * @ORM\Column(name="budget_amount", type="money", nullable=true) |
||
| 233 | * @Oro\Versioned |
||
| 234 | * @ConfigField( |
||
| 235 | * defaultValues={ |
||
| 236 | * "form"={ |
||
| 237 | * "form_type"="oro_money", |
||
| 238 | * "form_options"={ |
||
| 239 | * "constraints"={{"Range":{"min":0}}}, |
||
| 240 | * } |
||
| 241 | * }, |
||
| 242 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
| 243 | * "importexport"={ |
||
| 244 | * "order"=40 |
||
| 245 | * } |
||
| 246 | * } |
||
| 247 | * ) |
||
| 248 | */ |
||
| 249 | protected $budgetAmount; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @var double |
||
| 253 | * |
||
| 254 | * @ORM\Column(name="close_revenue", type="money", nullable=true) |
||
| 255 | * @Oro\Versioned |
||
| 256 | * @ConfigField( |
||
| 257 | * defaultValues={ |
||
| 258 | * "form"={ |
||
| 259 | * "form_type"="oro_money", |
||
| 260 | * "form_options"={ |
||
| 261 | * "constraints"={{"Range":{"min":0}}}, |
||
| 262 | * } |
||
| 263 | * }, |
||
| 264 | * "dataaudit"={ |
||
| 265 | * "auditable"=true |
||
| 266 | * }, |
||
| 267 | * "importexport"={ |
||
| 268 | * "order"=50 |
||
| 269 | * } |
||
| 270 | * } |
||
| 271 | * ) |
||
| 272 | */ |
||
| 273 | protected $closeRevenue; |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @var string |
||
| 277 | * |
||
| 278 | * @ORM\Column(name="customer_need", type="text", nullable=true) |
||
| 279 | * @Oro\Versioned |
||
| 280 | * @ConfigField( |
||
| 281 | * defaultValues={ |
||
| 282 | * "dataaudit"={"auditable"=true}, |
||
| 283 | * "importexport"={ |
||
| 284 | * "order"=60 |
||
| 285 | * } |
||
| 286 | * } |
||
| 287 | * ) |
||
| 288 | */ |
||
| 289 | protected $customerNeed; |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @var string |
||
| 293 | * |
||
| 294 | * @ORM\Column(name="proposed_solution", type="text", nullable=true) |
||
| 295 | * @Oro\Versioned |
||
| 296 | * @ConfigField( |
||
| 297 | * defaultValues={ |
||
| 298 | * "dataaudit"={"auditable"=true}, |
||
| 299 | * "importexport"={ |
||
| 300 | * "order"=70 |
||
| 301 | * } |
||
| 302 | * } |
||
| 303 | * ) |
||
| 304 | */ |
||
| 305 | protected $proposedSolution; |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @var \DateTime |
||
| 309 | * |
||
| 310 | * @ORM\Column(name="created_at", type="datetime") |
||
| 311 | * @ConfigField( |
||
| 312 | * defaultValues={ |
||
| 313 | * "entity"={ |
||
| 314 | * "label"="oro.ui.created_at" |
||
| 315 | * }, |
||
| 316 | * "importexport"={ |
||
| 317 | * "excluded"=true |
||
| 318 | * } |
||
| 319 | * } |
||
| 320 | * ) |
||
| 321 | */ |
||
| 322 | protected $createdAt; |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @var \DateTime |
||
| 326 | * |
||
| 327 | * @ORM\Column(name="updated_at", type="datetime") |
||
| 328 | * @ConfigField( |
||
| 329 | * defaultValues={ |
||
| 330 | * "entity"={ |
||
| 331 | * "label"="oro.ui.updated_at" |
||
| 332 | * }, |
||
| 333 | * "importexport"={ |
||
| 334 | * "excluded"=true |
||
| 335 | * } |
||
| 336 | * } |
||
| 337 | * ) |
||
| 338 | */ |
||
| 339 | protected $updatedAt; |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @var string |
||
| 343 | * |
||
| 344 | * @ORM\Column(name="notes", type="text", nullable=true) |
||
| 345 | * @Oro\Versioned |
||
| 346 | * @ConfigField( |
||
| 347 | * defaultValues={ |
||
| 348 | * "dataaudit"={ |
||
| 349 | * "auditable"=true |
||
| 350 | * }, |
||
| 351 | * "importexport"={ |
||
| 352 | * "order"=80 |
||
| 353 | * } |
||
| 354 | * } |
||
| 355 | * ) |
||
| 356 | */ |
||
| 357 | protected $notes; |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @var Organization |
||
| 361 | * |
||
| 362 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
| 363 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 364 | */ |
||
| 365 | protected $organization; |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @var B2bCustomer |
||
| 369 | * |
||
| 370 | * @ORM\ManyToOne( |
||
| 371 | * targetEntity="OroCRM\Bundle\SalesBundle\Entity\B2bCustomer", |
||
| 372 | * inversedBy="opportunities", |
||
| 373 | * cascade={"persist"} |
||
| 374 | * ) |
||
| 375 | * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 376 | * @Oro\Versioned |
||
| 377 | * @ConfigField( |
||
| 378 | * defaultValues={ |
||
| 379 | * "dataaudit"={"auditable"=true}, |
||
| 380 | * "importexport"={ |
||
| 381 | * "order"=110, |
||
| 382 | * "short"=true |
||
| 383 | * }, |
||
| 384 | * "form"={ |
||
| 385 | * "form_type"="orocrm_sales_b2bcustomer_select" |
||
| 386 | * } |
||
| 387 | * } |
||
| 388 | * ) |
||
| 389 | */ |
||
| 390 | protected $customer; |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @var \DateTime |
||
| 394 | * |
||
| 395 | * @ORM\Column(type="datetime", name="closed_at", nullable=true) |
||
| 396 | * @ConfigField( |
||
| 397 | * defaultValues={ |
||
| 398 | * "dataaudit"={"auditable"=true, "immutable"=true}, |
||
| 399 | * "importexport"={"excluded"=true, "immutable"=true} |
||
| 400 | * } |
||
| 401 | * ) |
||
| 402 | */ |
||
| 403 | protected $closedAt; |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return int |
||
| 407 | */ |
||
| 408 | public function getId() |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @param Lead $lead |
||
| 415 | * @return Opportunity |
||
| 416 | */ |
||
| 417 | public function setLead($lead) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return Lead |
||
| 426 | */ |
||
| 427 | public function getLead() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param float $budgetAmount |
||
| 434 | * @return Opportunity |
||
| 435 | */ |
||
| 436 | public function setBudgetAmount($budgetAmount) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @return float |
||
| 445 | */ |
||
| 446 | public function getBudgetAmount() |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @param \DateTime $closeDate |
||
| 453 | * @return Opportunity |
||
| 454 | */ |
||
| 455 | public function setCloseDate($closeDate) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @return \DateTime |
||
| 464 | */ |
||
| 465 | public function getCloseDate() |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @param Contact $contact |
||
| 472 | * @return Opportunity |
||
| 473 | */ |
||
| 474 | public function setContact($contact) |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @return Contact |
||
| 483 | */ |
||
| 484 | public function getContact() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @param string $customerNeed |
||
| 491 | * @return Opportunity |
||
| 492 | */ |
||
| 493 | public function setCustomerNeed($customerNeed) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @return string |
||
| 502 | */ |
||
| 503 | public function getCustomerNeed() |
||
| 507 | |||
| 508 | /** |
||
| 509 | * @param float $probability |
||
| 510 | * @return Opportunity |
||
| 511 | */ |
||
| 512 | public function setProbability($probability) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * @return float |
||
| 521 | */ |
||
| 522 | public function getProbability() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @param string $proposedSolution |
||
| 529 | * @return Opportunity |
||
| 530 | */ |
||
| 531 | public function setProposedSolution($proposedSolution) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @return string |
||
| 540 | */ |
||
| 541 | public function getProposedSolution() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @param string $name |
||
| 548 | * @return Opportunity |
||
| 549 | */ |
||
| 550 | public function setName($name) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * @return string |
||
| 559 | */ |
||
| 560 | public function getName() |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param OpportunityCloseReason $closeReason |
||
| 567 | * @return Opportunity |
||
| 568 | */ |
||
| 569 | public function setCloseReason($closeReason) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * @return OpportunityCloseReason |
||
| 578 | */ |
||
| 579 | public function getCloseReason() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @param float $revenue |
||
| 586 | */ |
||
| 587 | public function setCloseRevenue($revenue) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @return float |
||
| 594 | */ |
||
| 595 | public function getCloseRevenue() |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @return \DateTime |
||
| 602 | */ |
||
| 603 | public function getCreatedAt() |
||
| 607 | |||
| 608 | /** |
||
| 609 | * @param \DateTime $created |
||
| 610 | * @return Opportunity |
||
| 611 | */ |
||
| 612 | public function setCreatedAt($created) |
||
| 618 | |||
| 619 | /** |
||
| 620 | * @return \DateTime |
||
| 621 | */ |
||
| 622 | public function getUpdatedAt() |
||
| 626 | |||
| 627 | /** |
||
| 628 | * @param \DateTime $updated |
||
| 629 | * @return Opportunity |
||
| 630 | */ |
||
| 631 | public function setUpdatedAt($updated) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Get the primary email address of the related contact |
||
| 640 | * |
||
| 641 | * @return string |
||
| 642 | */ |
||
| 643 | public function getEmail() |
||
| 652 | |||
| 653 | public function __toString() |
||
| 657 | /** |
||
| 658 | * @ORM\PrePersist |
||
| 659 | */ |
||
| 660 | public function beforeSave() |
||
| 665 | |||
| 666 | /** |
||
| 667 | * @ORM\PreUpdate |
||
| 668 | */ |
||
| 669 | public function beforeUpdate() |
||
| 673 | |||
| 674 | /** |
||
| 675 | * @return User |
||
| 676 | */ |
||
| 677 | public function getOwner() |
||
| 681 | |||
| 682 | /** |
||
| 683 | * @param User $owningUser |
||
| 684 | * @return Opportunity |
||
| 685 | */ |
||
| 686 | public function setOwner($owningUser) |
||
| 692 | |||
| 693 | /** |
||
| 694 | * @return string |
||
| 695 | */ |
||
| 696 | public function getNotes() |
||
| 700 | |||
| 701 | /** |
||
| 702 | * @param string $notes |
||
| 703 | * @return Opportunity |
||
| 704 | */ |
||
| 705 | public function setNotes($notes) |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @param B2bCustomer $customer |
||
| 714 | * @TODO remove null after BAP-5248 |
||
| 715 | */ |
||
| 716 | public function setCustomer(B2bCustomer $customer = null) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * @return B2bCustomer |
||
| 723 | */ |
||
| 724 | public function getCustomer() |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Set organization |
||
| 731 | * |
||
| 732 | * @param Organization $organization |
||
| 733 | * @return Opportunity |
||
| 734 | */ |
||
| 735 | public function setOrganization(Organization $organization = null) |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Get organization |
||
| 744 | * |
||
| 745 | * @return Organization |
||
| 746 | */ |
||
| 747 | public function getOrganization() |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Remove Customer |
||
| 754 | * |
||
| 755 | * @return Lead |
||
| 756 | */ |
||
| 757 | public function removeCustomer() |
||
| 761 | |||
| 762 | /** |
||
| 763 | * @param \DateTime $closedAt |
||
| 764 | */ |
||
| 765 | public function setClosedAt(\DateTime $closedAt = null) |
||
| 769 | |||
| 770 | /** |
||
| 771 | * @return \DateTime |
||
| 772 | */ |
||
| 773 | public function getClosedAt() |
||
| 777 | } |
||
| 778 |