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 |
||
56 | class CaseEntity extends ExtendCaseEntity implements EmailHolderInterface |
||
57 | { |
||
58 | /** |
||
59 | * @var integer |
||
60 | * |
||
61 | * @ORM\Column(type="integer") |
||
62 | * @ORM\Id |
||
63 | * @ORM\GeneratedValue(strategy="AUTO") |
||
64 | * @ConfigField( |
||
65 | * defaultValues={ |
||
66 | * "dataaudit"={ |
||
67 | * "auditable"=true |
||
68 | * } |
||
69 | * } |
||
70 | * ) |
||
71 | */ |
||
72 | protected $id; |
||
73 | |||
74 | /** |
||
75 | * @var string |
||
76 | * |
||
77 | * @ORM\Column(name="subject", type="string", length=255) |
||
78 | * @Oro\Versioned |
||
79 | * @ConfigField( |
||
80 | * defaultValues={ |
||
81 | * "dataaudit"={ |
||
82 | * "auditable"=true |
||
83 | * } |
||
84 | * } |
||
85 | * ) |
||
86 | */ |
||
87 | protected $subject; |
||
88 | |||
89 | /** |
||
90 | * @var string |
||
91 | * |
||
92 | * @ORM\Column(name="description", type="text", nullable=true) |
||
93 | * @Oro\Versioned |
||
94 | * @ConfigField( |
||
95 | * defaultValues={ |
||
96 | * "dataaudit"={ |
||
97 | * "auditable"=true |
||
98 | * } |
||
99 | * } |
||
100 | * ) |
||
101 | */ |
||
102 | protected $description; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | * |
||
107 | * @ORM\Column(name="resolution", type="text", nullable=true) |
||
108 | * @Oro\Versioned |
||
109 | * @ConfigField( |
||
110 | * defaultValues={ |
||
111 | * "dataaudit"={ |
||
112 | * "auditable"=true |
||
113 | * } |
||
114 | * } |
||
115 | * ) |
||
116 | */ |
||
117 | protected $resolution; |
||
118 | |||
119 | /** |
||
120 | * @var CaseSource |
||
121 | * |
||
122 | * @ORM\ManyToOne(targetEntity="CaseSource") |
||
123 | * @ORM\JoinColumn(name="source_name", referencedColumnName="name", onDelete="SET NULL") |
||
124 | * @Oro\Versioned |
||
125 | * @ConfigField( |
||
126 | * defaultValues={ |
||
127 | * "dataaudit"={ |
||
128 | * "auditable"=true |
||
129 | * } |
||
130 | * } |
||
131 | * ) |
||
132 | */ |
||
133 | protected $source; |
||
134 | |||
135 | /** |
||
136 | * @var CaseStatus |
||
137 | * |
||
138 | * @ORM\ManyToOne(targetEntity="CaseStatus") |
||
139 | * @ORM\JoinColumn(name="status_name", referencedColumnName="name", onDelete="SET NULL") |
||
140 | * @Oro\Versioned |
||
141 | * @ConfigField( |
||
142 | * defaultValues={ |
||
143 | * "dataaudit"={ |
||
144 | * "auditable"=true |
||
145 | * } |
||
146 | * } |
||
147 | * ) |
||
148 | */ |
||
149 | protected $status; |
||
150 | |||
151 | /** |
||
152 | * @var CasePriority |
||
153 | * |
||
154 | * @ORM\ManyToOne(targetEntity="CasePriority") |
||
155 | * @ORM\JoinColumn(name="priority_name", referencedColumnName="name", onDelete="SET NULL") |
||
156 | * @Oro\Versioned |
||
157 | * @ConfigField( |
||
158 | * defaultValues={ |
||
159 | * "dataaudit"={ |
||
160 | * "auditable"=true |
||
161 | * } |
||
162 | * } |
||
163 | * ) |
||
164 | */ |
||
165 | protected $priority; |
||
166 | |||
167 | /** |
||
168 | * @var Contact |
||
169 | * |
||
170 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact") |
||
171 | * @ORM\JoinColumn(name="related_contact_id", referencedColumnName="id", onDelete="SET NULL") |
||
172 | * @ConfigField( |
||
173 | * defaultValues={ |
||
174 | * "dataaudit"={ |
||
175 | * "auditable"=true |
||
176 | * } |
||
177 | * } |
||
178 | * ) |
||
179 | */ |
||
180 | protected $relatedContact; |
||
181 | |||
182 | /** |
||
183 | * @var Account |
||
184 | * |
||
185 | * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\AccountBundle\Entity\Account") |
||
186 | * @ORM\JoinColumn(name="related_account_id", referencedColumnName="id", onDelete="SET NULL") |
||
187 | * @ConfigField( |
||
188 | * defaultValues={ |
||
189 | * "dataaudit"={ |
||
190 | * "auditable"=true |
||
191 | * } |
||
192 | * } |
||
193 | * ) |
||
194 | */ |
||
195 | protected $relatedAccount; |
||
196 | |||
197 | /** |
||
198 | * @var User |
||
199 | * |
||
200 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
201 | * @ORM\JoinColumn(name="assigned_to_id", referencedColumnName="id", onDelete="SET NULL") |
||
202 | * @ConfigField( |
||
203 | * defaultValues={ |
||
204 | * "dataaudit"={ |
||
205 | * "auditable"=true |
||
206 | * } |
||
207 | * } |
||
208 | * ) |
||
209 | * @Oro\Versioned |
||
210 | */ |
||
211 | protected $assignedTo; |
||
212 | |||
213 | /** |
||
214 | * @var User |
||
215 | * |
||
216 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User") |
||
217 | * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", onDelete="SET NULL") |
||
218 | * @Oro\Versioned |
||
219 | * @ConfigField( |
||
220 | * defaultValues={ |
||
221 | * "dataaudit"={ |
||
222 | * "auditable"=true |
||
223 | * } |
||
224 | * } |
||
225 | * ) |
||
226 | */ |
||
227 | protected $owner; |
||
228 | |||
229 | /** |
||
230 | * @var Collection |
||
231 | * |
||
232 | * @ORM\OneToMany( |
||
233 | * targetEntity="CaseComment", |
||
234 | * mappedBy="case", |
||
235 | * cascade={"ALL"}, |
||
236 | * orphanRemoval=true |
||
237 | * ) |
||
238 | * @ORM\OrderBy({"createdAt"="DESC"}) |
||
239 | */ |
||
240 | protected $comments; |
||
241 | |||
242 | /** |
||
243 | * @var \DateTime |
||
244 | * |
||
245 | * @ORM\Column(type="datetime") |
||
246 | * @ConfigField( |
||
247 | * defaultValues={ |
||
248 | * "entity"={ |
||
249 | * "label"="oro.ui.created_at" |
||
250 | * } |
||
251 | * } |
||
252 | * ) |
||
253 | */ |
||
254 | protected $createdAt; |
||
255 | |||
256 | /** |
||
257 | * @var \DateTime |
||
258 | * |
||
259 | * @ORM\Column(type="datetime", nullable=true) |
||
260 | * @ConfigField( |
||
261 | * defaultValues={ |
||
262 | * "entity"={ |
||
263 | * "label"="oro.ui.updated_at" |
||
264 | * } |
||
265 | * } |
||
266 | * ) |
||
267 | */ |
||
268 | protected $updatedAt; |
||
269 | |||
270 | /** |
||
271 | * @var \DateTime |
||
272 | * |
||
273 | * @ORM\Column(type="datetime") |
||
274 | */ |
||
275 | protected $reportedAt; |
||
276 | |||
277 | /** |
||
278 | * @var \DateTime |
||
279 | * |
||
280 | * @ORM\Column(type="datetime", nullable=true) |
||
281 | */ |
||
282 | protected $closedAt; |
||
283 | |||
284 | /** |
||
285 | * Flag to update closedAt field when status is set to closed. |
||
286 | * Use null instead of false because of behaviour of BeSimpleSoapBundle. |
||
287 | * |
||
288 | * @var bool |
||
289 | */ |
||
290 | private $updateClosedAt = null; |
||
291 | |||
292 | /** |
||
293 | * @var Organization |
||
294 | * |
||
295 | * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization") |
||
296 | * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") |
||
297 | */ |
||
298 | protected $organization; |
||
299 | |||
300 | public function __construct() |
||
306 | |||
307 | /** |
||
308 | * @return integer |
||
309 | */ |
||
310 | public function getId() |
||
314 | |||
315 | /** |
||
316 | * @param string $subject |
||
317 | * @return CaseEntity |
||
318 | */ |
||
319 | public function setSubject($subject) |
||
325 | |||
326 | /** |
||
327 | * @return string |
||
328 | */ |
||
329 | public function getSubject() |
||
333 | |||
334 | /** |
||
335 | * @param string $description |
||
336 | * @return CaseEntity |
||
337 | */ |
||
338 | public function setDescription($description) |
||
344 | |||
345 | /** |
||
346 | * @return string |
||
347 | */ |
||
348 | public function getDescription() |
||
352 | |||
353 | /** |
||
354 | * @param string $resolution |
||
355 | * @return CaseEntity |
||
356 | */ |
||
357 | public function setResolution($resolution) |
||
363 | |||
364 | /** |
||
365 | * @return string |
||
366 | */ |
||
367 | public function getResolution() |
||
371 | |||
372 | /** |
||
373 | * @param CaseSource|null $source |
||
374 | * @return CaseEntity |
||
375 | */ |
||
376 | public function setSource($source) |
||
382 | |||
383 | /** |
||
384 | * @return CaseSource |
||
385 | */ |
||
386 | public function getSource() |
||
390 | |||
391 | /** |
||
392 | * @param CaseStatus|null $status |
||
393 | * @return CaseEntity |
||
394 | */ |
||
395 | public function setStatus($status) |
||
402 | |||
403 | /** |
||
404 | * @param mixed $newStatus |
||
405 | * @param mixed $oldStatus |
||
406 | */ |
||
407 | protected function updateClosedAt($newStatus, $oldStatus) |
||
418 | |||
419 | /** |
||
420 | * @return CaseStatus |
||
421 | */ |
||
422 | public function getStatus() |
||
426 | |||
427 | /** |
||
428 | * @param CasePriority|null $priority |
||
429 | * @return CaseEntity |
||
430 | */ |
||
431 | public function setPriority($priority) |
||
437 | |||
438 | /** |
||
439 | * @return CasePriority |
||
440 | */ |
||
441 | public function getPriority() |
||
445 | |||
446 | /** |
||
447 | * @param Contact|null $relatedContact |
||
448 | * @return CaseEntity |
||
449 | */ |
||
450 | public function setRelatedContact($relatedContact = null) |
||
456 | |||
457 | /** |
||
458 | * @return Contact |
||
459 | */ |
||
460 | public function getRelatedContact() |
||
464 | |||
465 | /** |
||
466 | * @param Account|null $relatedAccount |
||
467 | * @return CaseEntity |
||
468 | */ |
||
469 | public function setRelatedAccount($relatedAccount = null) |
||
475 | |||
476 | /** |
||
477 | * @return Account |
||
478 | */ |
||
479 | public function getRelatedAccount() |
||
483 | |||
484 | /** |
||
485 | * @param User $assignee |
||
486 | * @return CaseEntity |
||
487 | */ |
||
488 | public function setAssignedTo($assignee) |
||
494 | |||
495 | /** |
||
496 | * @return User|null |
||
497 | */ |
||
498 | public function getAssignedTo() |
||
502 | |||
503 | /** |
||
504 | * @param User $owner |
||
505 | * @return CaseEntity |
||
506 | */ |
||
507 | public function setOwner($owner) |
||
513 | |||
514 | /** |
||
515 | * @return User |
||
516 | */ |
||
517 | public function getOwner() |
||
521 | |||
522 | /** |
||
523 | * @return Collection |
||
524 | */ |
||
525 | public function getComments() |
||
529 | |||
530 | /** |
||
531 | * @param CaseComment $comment |
||
532 | * @return CaseEntity |
||
533 | */ |
||
534 | public function addComment(CaseComment $comment) |
||
541 | |||
542 | /** |
||
543 | * @param \DateTime $createdAt |
||
544 | * @return CaseEntity |
||
545 | */ |
||
546 | public function setCreatedAt(\DateTime $createdAt) |
||
552 | |||
553 | /** |
||
554 | * @return \DateTime |
||
555 | */ |
||
556 | public function getCreatedAt() |
||
560 | |||
561 | /** |
||
562 | * @param \DateTime $updatedAt |
||
563 | * @return CaseEntity |
||
564 | */ |
||
565 | public function setUpdatedAt(\DateTime $updatedAt) |
||
571 | |||
572 | /** |
||
573 | * @return \DateTime |
||
574 | */ |
||
575 | public function getUpdatedAt() |
||
579 | |||
580 | /** |
||
581 | * @param \DateTime $reportedAt |
||
582 | * @return CaseEntity |
||
583 | */ |
||
584 | public function setReportedAt(\DateTime $reportedAt = null) |
||
590 | |||
591 | /** |
||
592 | * @return \DateTime |
||
593 | */ |
||
594 | public function getReportedAt() |
||
598 | |||
599 | /** |
||
600 | * @param \DateTime $closedAt |
||
601 | * @return CaseEntity |
||
602 | */ |
||
603 | public function setClosedAt(\DateTime $closedAt = null) |
||
613 | |||
614 | /** |
||
615 | * @return \DateTime |
||
616 | */ |
||
617 | public function getClosedAt() |
||
621 | |||
622 | /** |
||
623 | * Get the primary email address of the related contact |
||
624 | * |
||
625 | * @return string |
||
626 | */ |
||
627 | public function getEmail() |
||
636 | |||
637 | /** |
||
638 | * @ORM\PrePersist |
||
639 | */ |
||
640 | public function prePersist() |
||
648 | |||
649 | /** |
||
650 | * @ORM\PreUpdate |
||
651 | */ |
||
652 | public function preUpdate() |
||
659 | |||
660 | /** |
||
661 | * @return string |
||
662 | */ |
||
663 | public function __toString() |
||
667 | |||
668 | /** |
||
669 | * Set organization |
||
670 | * |
||
671 | * @param Organization $organization |
||
672 | * @return CaseEntity |
||
673 | */ |
||
674 | public function setOrganization(Organization $organization = null) |
||
680 | |||
681 | /** |
||
682 | * Get organization |
||
683 | * |
||
684 | * @return Organization |
||
685 | */ |
||
686 | public function getOrganization() |
||
690 | } |
||
691 |