Complex classes like CaseEntity 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 CaseEntity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 60 | class CaseEntity extends ExtendCaseEntity implements EmailHolderInterface |
||
| 61 | { |
||
| 62 | /** |
||
| 63 | * @var integer |
||
| 64 | * |
||
| 65 | * @ORM\Column(type="integer") |
||
| 66 | * @ORM\Id |
||
| 67 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 68 | * @ConfigField( |
||
| 69 | * defaultValues={ |
||
| 70 | * "dataaudit"={ |
||
| 71 | * "auditable"=true |
||
| 72 | * } |
||
| 73 | * } |
||
| 74 | * ) |
||
| 75 | */ |
||
| 76 | protected $id; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="subject", type="string", length=255) |
||
| 82 | * @Oro\Versioned |
||
| 83 | * @ConfigField( |
||
| 84 | * defaultValues={ |
||
| 85 | * "dataaudit"={ |
||
| 86 | * "auditable"=true |
||
| 87 | * } |
||
| 88 | * } |
||
| 89 | * ) |
||
| 90 | */ |
||
| 91 | protected $subject; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | * |
||
| 96 | * @ORM\Column(name="description", type="text", nullable=true) |
||
| 97 | * @Oro\Versioned |
||
| 98 | * @ConfigField( |
||
| 99 | * defaultValues={ |
||
| 100 | * "dataaudit"={ |
||
| 101 | * "auditable"=true |
||
| 102 | * } |
||
| 103 | * } |
||
| 104 | * ) |
||
| 105 | */ |
||
| 106 | protected $description; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string |
||
| 110 | * |
||
| 111 | * @ORM\Column(name="resolution", type="text", nullable=true) |
||
| 112 | * @Oro\Versioned |
||
| 113 | * @ConfigField( |
||
| 114 | * defaultValues={ |
||
| 115 | * "dataaudit"={ |
||
| 116 | * "auditable"=true |
||
| 117 | * } |
||
| 118 | * } |
||
| 119 | * ) |
||
| 120 | */ |
||
| 121 | protected $resolution; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var CaseSource |
||
| 125 | * |
||
| 126 | * @ORM\ManyToOne(targetEntity="CaseSource") |
||
| 127 | * @ORM\JoinColumn(name="source_name", referencedColumnName="name", onDelete="SET NULL") |
||
| 128 | * @Oro\Versioned |
||
| 129 | * @ConfigField( |
||
| 130 | * defaultValues={ |
||
| 131 | * "dataaudit"={ |
||
| 132 | * "auditable"=true |
||
| 133 | * } |
||
| 134 | * } |
||
| 135 | * ) |
||
| 136 | */ |
||
| 137 | protected $source; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var CaseStatus |
||
| 141 | * |
||
| 142 | * @ORM\ManyToOne(targetEntity="CaseStatus") |
||
| 143 | * @ORM\JoinColumn(name="status_name", referencedColumnName="name", onDelete="SET NULL") |
||
| 144 | * @Oro\Versioned |
||
| 145 | * @ConfigField( |
||
| 146 | * defaultValues={ |
||
| 147 | * "dataaudit"={ |
||
| 148 | * "auditable"=true |
||
| 149 | * } |
||
| 150 | * } |
||
| 151 | * ) |
||
| 152 | */ |
||
| 153 | protected $status; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @var CasePriority |
||
| 157 | * |
||
| 158 | * @ORM\ManyToOne(targetEntity="CasePriority") |
||
| 159 | * @ORM\JoinColumn(name="priority_name", referencedColumnName="name", onDelete="SET NULL") |
||
| 160 | * @Oro\Versioned |
||
| 161 | * @ConfigField( |
||
| 162 | * defaultValues={ |
||
| 163 | * "dataaudit"={ |
||
| 164 | * "auditable"=true |
||
| 165 | * } |
||
| 166 | * } |
||
| 167 | * ) |
||
| 168 | */ |
||
| 169 | protected $priority; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var Contact |
||
| 173 | * |
||
| 174 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact") |
||
| 175 | * @ORM\JoinColumn(name="related_contact_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 176 | * @ConfigField( |
||
| 177 | * defaultValues={ |
||
| 178 | * "dataaudit"={ |
||
| 179 | * "auditable"=true |
||
| 180 | * } |
||
| 181 | * } |
||
| 182 | * ) |
||
| 183 | */ |
||
| 184 | protected $relatedContact; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @var Account |
||
| 188 | * |
||
| 189 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\AccountBundle\Entity\Account") |
||
| 190 | * @ORM\JoinColumn(name="related_account_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 191 | * @ConfigField( |
||
| 192 | * defaultValues={ |
||
| 193 | * "dataaudit"={ |
||
| 194 | * "auditable"=true |
||
| 195 | * } |
||
| 196 | * } |
||
| 197 | * ) |
||
| 198 | */ |
||
| 199 | protected $relatedAccount; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @var User |
||
| 203 | * |
||
| 204 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
| 205 | * @ORM\JoinColumn(name="assigned_to_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 206 | * @ConfigField( |
||
| 207 | * defaultValues={ |
||
| 208 | * "dataaudit"={ |
||
| 209 | * "auditable"=true |
||
| 210 | * } |
||
| 211 | * } |
||
| 212 | * ) |
||
| 213 | * @Oro\Versioned |
||
| 214 | */ |
||
| 215 | protected $assignedTo; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @var User |
||
| 219 | * |
||
| 220 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
| 221 | * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 222 | * @Oro\Versioned |
||
| 223 | * @ConfigField( |
||
| 224 | * defaultValues={ |
||
| 225 | * "dataaudit"={ |
||
| 226 | * "auditable"=true |
||
| 227 | * } |
||
| 228 | * } |
||
| 229 | * ) |
||
| 230 | */ |
||
| 231 | protected $owner; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var Collection |
||
| 235 | * |
||
| 236 | * @ORM\OneToMany( |
||
| 237 | * targetEntity="CaseComment", |
||
| 238 | * mappedBy="case", |
||
| 239 | * cascade={"ALL"}, |
||
| 240 | * orphanRemoval=true |
||
| 241 | * ) |
||
| 242 | * @ORM\OrderBy({"createdAt"="DESC"}) |
||
| 243 | */ |
||
| 244 | protected $comments; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @var \DateTime |
||
| 248 | * |
||
| 249 | * @ORM\Column(type="datetime") |
||
| 250 | * @ConfigField( |
||
| 251 | * defaultValues={ |
||
| 252 | * "entity"={ |
||
| 253 | * "label"="oro.ui.created_at" |
||
| 254 | * } |
||
| 255 | * } |
||
| 256 | * ) |
||
| 257 | */ |
||
| 258 | protected $createdAt; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @var \DateTime |
||
| 262 | * |
||
| 263 | * @ORM\Column(type="datetime", nullable=true) |
||
| 264 | * @ConfigField( |
||
| 265 | * defaultValues={ |
||
| 266 | * "entity"={ |
||
| 267 | * "label"="oro.ui.updated_at" |
||
| 268 | * } |
||
| 269 | * } |
||
| 270 | * ) |
||
| 271 | */ |
||
| 272 | protected $updatedAt; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @var \DateTime |
||
| 276 | * |
||
| 277 | * @ORM\Column(type="datetime") |
||
| 278 | */ |
||
| 279 | protected $reportedAt; |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @var \DateTime |
||
| 283 | * |
||
| 284 | * @ORM\Column(type="datetime", nullable=true) |
||
| 285 | */ |
||
| 286 | protected $closedAt; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Flag to update closedAt field when status is set to closed. |
||
| 290 | * Use null instead of false because of behaviour of BeSimpleSoapBundle. |
||
| 291 | * |
||
| 292 | * @var bool |
||
| 293 | */ |
||
| 294 | private $updateClosedAt = null; |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @var Organization |
||
| 298 | * |
||
| 299 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
| 300 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 301 | */ |
||
| 302 | protected $organization; |
||
| 303 | |||
| 304 | public function __construct() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @return integer |
||
| 313 | */ |
||
| 314 | public function getId() |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @param string $subject |
||
| 321 | * @return CaseEntity |
||
| 322 | */ |
||
| 323 | public function setSubject($subject) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getSubject() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $description |
||
| 340 | * @return CaseEntity |
||
| 341 | */ |
||
| 342 | public function setDescription($description) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @return string |
||
| 351 | */ |
||
| 352 | public function getDescription() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @param string $resolution |
||
| 359 | * @return CaseEntity |
||
| 360 | */ |
||
| 361 | public function setResolution($resolution) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @return string |
||
| 370 | */ |
||
| 371 | public function getResolution() |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param CaseSource|null $source |
||
| 378 | * @return CaseEntity |
||
| 379 | */ |
||
| 380 | public function setSource($source) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @return CaseSource |
||
| 389 | */ |
||
| 390 | public function getSource() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param CaseStatus|null $status |
||
| 397 | * @return CaseEntity |
||
| 398 | */ |
||
| 399 | public function setStatus($status) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @param mixed $newStatus |
||
| 409 | * @param mixed $oldStatus |
||
| 410 | */ |
||
| 411 | protected function updateClosedAt($newStatus, $oldStatus) |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @return CaseStatus |
||
| 425 | */ |
||
| 426 | public function getStatus() |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @param CasePriority|null $priority |
||
| 433 | * @return CaseEntity |
||
| 434 | */ |
||
| 435 | public function setPriority($priority) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return CasePriority |
||
| 444 | */ |
||
| 445 | public function getPriority() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param Contact|null $relatedContact |
||
| 452 | * @return CaseEntity |
||
| 453 | */ |
||
| 454 | public function setRelatedContact($relatedContact = null) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @return Contact |
||
| 463 | */ |
||
| 464 | public function getRelatedContact() |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param Account|null $relatedAccount |
||
| 471 | * @return CaseEntity |
||
| 472 | */ |
||
| 473 | public function setRelatedAccount($relatedAccount = null) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return Account |
||
| 482 | */ |
||
| 483 | public function getRelatedAccount() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param User $assignee |
||
| 490 | * @return CaseEntity |
||
| 491 | */ |
||
| 492 | public function setAssignedTo($assignee) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @return User|null |
||
| 501 | */ |
||
| 502 | public function getAssignedTo() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @param User $owner |
||
| 509 | * @return CaseEntity |
||
| 510 | */ |
||
| 511 | public function setOwner($owner) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @return User |
||
| 520 | */ |
||
| 521 | public function getOwner() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @return Collection |
||
| 528 | */ |
||
| 529 | public function getComments() |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param CaseComment $comment |
||
| 536 | * @return CaseEntity |
||
| 537 | */ |
||
| 538 | public function addComment(CaseComment $comment) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * @param CaseComment $comment |
||
| 548 | * @return CaseEntity |
||
| 549 | */ |
||
| 550 | public function removeComment(CaseComment $comment) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * @param \DateTime|null $createdAt |
||
| 559 | * @return CaseEntity |
||
| 560 | */ |
||
| 561 | public function setCreatedAt(\DateTime $createdAt = null) |
||
| 567 | |||
| 568 | /** |
||
| 569 | * @return \DateTime |
||
| 570 | */ |
||
| 571 | public function getCreatedAt() |
||
| 575 | |||
| 576 | /** |
||
| 577 | * @param \DateTime|null $updatedAt |
||
| 578 | * @return CaseEntity |
||
| 579 | */ |
||
| 580 | public function setUpdatedAt(\DateTime $updatedAt = null) |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @return \DateTime |
||
| 589 | */ |
||
| 590 | public function getUpdatedAt() |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @param \DateTime $reportedAt |
||
| 597 | * @return CaseEntity |
||
| 598 | */ |
||
| 599 | public function setReportedAt(\DateTime $reportedAt = null) |
||
| 605 | |||
| 606 | /** |
||
| 607 | * @return \DateTime |
||
| 608 | */ |
||
| 609 | public function getReportedAt() |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @param \DateTime $closedAt |
||
| 616 | * @return CaseEntity |
||
| 617 | */ |
||
| 618 | public function setClosedAt(\DateTime $closedAt = null) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * @return \DateTime |
||
| 631 | */ |
||
| 632 | public function getClosedAt() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Get the primary email address of the related contact |
||
| 639 | * |
||
| 640 | * @return string |
||
| 641 | */ |
||
| 642 | public function getEmail() |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @ORM\PrePersist |
||
| 654 | */ |
||
| 655 | public function prePersist() |
||
| 663 | |||
| 664 | /** |
||
| 665 | * @ORM\PreUpdate |
||
| 666 | */ |
||
| 667 | public function preUpdate() |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @return string |
||
| 677 | */ |
||
| 678 | public function __toString() |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Set organization |
||
| 685 | * |
||
| 686 | * @param Organization $organization |
||
| 687 | * @return CaseEntity |
||
| 688 | */ |
||
| 689 | public function setOrganization(Organization $organization = null) |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Get organization |
||
| 698 | * |
||
| 699 | * @return Organization |
||
| 700 | */ |
||
| 701 | public function getOrganization() |
||
| 705 | } |
||
| 706 |