Complex classes like CharContract 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 CharContract, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class CharContract |
||
18 | { |
||
19 | /** |
||
20 | * @var integer |
||
21 | * |
||
22 | * @ORM\Id |
||
23 | * @ORM\GeneratedValue |
||
24 | * @ORM\Column(name="ID", type="bigint", options={"unsigned"=true}) |
||
25 | */ |
||
26 | private $id; |
||
27 | |||
28 | /** |
||
29 | * @var integer |
||
30 | * |
||
31 | * @ORM\Column(name="contractID", type="bigint", options={"unsigned"=true}) |
||
32 | */ |
||
33 | private $contractId; |
||
34 | |||
35 | /** |
||
36 | * @var integer |
||
37 | * |
||
38 | * @ORM\Column(name="ownerID", type="bigint", options={"unsigned"=true}) |
||
39 | */ |
||
40 | private $ownerId; |
||
41 | |||
42 | /** |
||
43 | * @var integer |
||
44 | * |
||
45 | * @ORM\Column(name="issuerID", type="bigint", options={"unsigned"=true}) |
||
46 | */ |
||
47 | private $issuerId; |
||
48 | |||
49 | /** |
||
50 | * @var integer |
||
51 | * |
||
52 | * @ORM\Column(name="issuerCorpID", type="bigint", options={"unsigned"=true}) |
||
53 | */ |
||
54 | private $issuerCorpId; |
||
55 | |||
56 | /** |
||
57 | * @var integer |
||
58 | * |
||
59 | * @ORM\Column(name="assigneeID", type="bigint", options={"unsigned"=true}) |
||
60 | */ |
||
61 | private $assigneeId; |
||
62 | |||
63 | /** |
||
64 | * @var integer |
||
65 | * |
||
66 | * @ORM\Column(name="acceptorID", type="bigint", options={"unsigned"=true}) |
||
67 | */ |
||
68 | private $acceptorId; |
||
69 | |||
70 | /** |
||
71 | * @var integer |
||
72 | * |
||
73 | * @ORM\Column(name="startStationID", type="bigint", options={"unsigned"=true}) |
||
74 | */ |
||
75 | private $startStationId; |
||
76 | |||
77 | /** |
||
78 | * @var integer |
||
79 | * |
||
80 | * @ORM\Column(name="endStationID", type="bigint", options={"unsigned"=true}) |
||
81 | */ |
||
82 | private $endStationId; |
||
83 | |||
84 | /** |
||
85 | * @var string |
||
86 | * |
||
87 | * @ORM\Column(name="type", type="string", length=255) |
||
88 | */ |
||
89 | private $type; |
||
90 | |||
91 | /** |
||
92 | * @var string |
||
93 | * |
||
94 | * @ORM\Column(name="status", type="string", length=255) |
||
95 | */ |
||
96 | private $status; |
||
97 | |||
98 | /** |
||
99 | * @var string |
||
100 | * |
||
101 | * @ORM\Column(name="title", type="string", length=255, nullable=true) |
||
102 | */ |
||
103 | private $title; |
||
104 | |||
105 | /** |
||
106 | * @var boolean |
||
107 | * |
||
108 | * @ORM\Column(name="forCorp", type="boolean") |
||
109 | */ |
||
110 | private $forCorp; |
||
111 | |||
112 | /** |
||
113 | * @var string |
||
114 | * |
||
115 | * @ORM\Column(name="availability", type="string", length=255) |
||
116 | */ |
||
117 | private $availability; |
||
118 | |||
119 | /** |
||
120 | * @var \DateTime |
||
121 | * |
||
122 | * @ORM\Column(name="dateIssued", type="datetime") |
||
123 | */ |
||
124 | private $dateIssued; |
||
125 | |||
126 | /** |
||
127 | * @var \DateTime |
||
128 | * |
||
129 | * @ORM\Column(name="dateExpired", type="datetime") |
||
130 | */ |
||
131 | private $dateExpired; |
||
132 | |||
133 | /** |
||
134 | * @var \DateTime |
||
135 | * |
||
136 | * @ORM\Column(name="dateAccepted", type="datetime", nullable=true) |
||
137 | */ |
||
138 | private $dateAccepted; |
||
139 | |||
140 | /** |
||
141 | * @var integer |
||
142 | * |
||
143 | * @ORM\Column(name="numDays", type="smallint") |
||
144 | */ |
||
145 | private $numDays; |
||
146 | |||
147 | /** |
||
148 | * @var \DateTime |
||
149 | * |
||
150 | * @ORM\Column(name="dateCompleted", type="datetime", nullable=true) |
||
151 | */ |
||
152 | private $dateCompleted; |
||
153 | |||
154 | /** |
||
155 | * @var float |
||
156 | * |
||
157 | * @ORM\Column(name="price", type="decimal", precision=17, scale=2) |
||
158 | */ |
||
159 | private $price; |
||
160 | |||
161 | /** |
||
162 | * @var float |
||
163 | * |
||
164 | * @ORM\Column(name="reward", type="decimal", precision=17, scale=2) |
||
165 | */ |
||
166 | private $reward; |
||
167 | |||
168 | /** |
||
169 | * @var float |
||
170 | * |
||
171 | * @ORM\Column(name="collateral", type="decimal", precision=17, scale=2) |
||
172 | */ |
||
173 | private $collateral; |
||
174 | |||
175 | /** |
||
176 | * @var float |
||
177 | * |
||
178 | * @ORM\Column(name="buyout", type="decimal", precision=17, scale=2) |
||
179 | */ |
||
180 | private $buyout; |
||
181 | |||
182 | /** |
||
183 | * @var integer |
||
184 | * |
||
185 | * @ORM\Column(name="volume", type="bigint", options={"unsigned"=true}) |
||
186 | */ |
||
187 | private $volume; |
||
188 | |||
189 | public function __construct($contractId, $ownerId) |
||
190 | { |
||
191 | $this->contractId = $contractId; |
||
192 | $this->ownerId = $ownerId; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Get Id |
||
197 | * |
||
198 | * @return integer |
||
199 | */ |
||
200 | public function getId() |
||
204 | |||
205 | /** |
||
206 | * Get contractId |
||
207 | * |
||
208 | * @return integer |
||
209 | */ |
||
210 | public function getContractId() |
||
214 | |||
215 | /** |
||
216 | * Set ownerId |
||
217 | * |
||
218 | * @param integer $ownerId |
||
219 | * @return CharContract |
||
220 | */ |
||
221 | public function setOwnerId($ownerId) |
||
222 | { |
||
223 | $this->ownerId = $ownerId; |
||
224 | |||
225 | return $this; |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Get ownerId |
||
230 | * |
||
231 | * @return integer |
||
232 | */ |
||
233 | public function getOwnerId() |
||
237 | |||
238 | /** |
||
239 | * Set issuerId |
||
240 | * |
||
241 | * @param integer $issuerId |
||
242 | * @return CharContract |
||
243 | */ |
||
244 | public function setIssuerId($issuerId) |
||
245 | { |
||
246 | $this->issuerId = $issuerId; |
||
247 | |||
248 | return $this; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Get issuerId |
||
253 | * |
||
254 | * @return integer |
||
255 | */ |
||
256 | public function getIssuerId() |
||
260 | |||
261 | /** |
||
262 | * Set issuerCorpId |
||
263 | * |
||
264 | * @param integer $issuerCorpId |
||
265 | * @return CharContract |
||
266 | */ |
||
267 | public function setIssuerCorpId($issuerCorpId) |
||
268 | { |
||
269 | $this->issuerCorpId = $issuerCorpId; |
||
270 | |||
271 | return $this; |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Get issuerCorpId |
||
276 | * |
||
277 | * @return integer |
||
278 | */ |
||
279 | public function getIssuerCorpId() |
||
283 | |||
284 | /** |
||
285 | * Set assigneeId |
||
286 | * |
||
287 | * @param integer $assigneeId |
||
288 | * @return CharContract |
||
289 | */ |
||
290 | public function setAssigneeId($assigneeId) |
||
291 | { |
||
292 | $this->assigneeId = $assigneeId; |
||
293 | |||
294 | return $this; |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * Get assigneeId |
||
299 | * |
||
300 | * @return integer |
||
301 | */ |
||
302 | public function getAssigneeId() |
||
306 | |||
307 | /** |
||
308 | * Set acceptorId |
||
309 | * |
||
310 | * @param integer $acceptorId |
||
311 | * @return CharContract |
||
312 | */ |
||
313 | public function setAcceptorId($acceptorId) |
||
314 | { |
||
315 | $this->acceptorId = $acceptorId; |
||
316 | |||
317 | return $this; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Get acceptorId |
||
322 | * |
||
323 | * @return integer |
||
324 | */ |
||
325 | public function getAcceptorId() |
||
329 | |||
330 | /** |
||
331 | * Set startStationId |
||
332 | * |
||
333 | * @param integer $startStationId |
||
334 | * @return CharContract |
||
335 | */ |
||
336 | public function setStartStationId($startStationId) |
||
337 | { |
||
338 | $this->startStationId = $startStationId; |
||
339 | |||
340 | return $this; |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * Get startStationId |
||
345 | * |
||
346 | * @return integer |
||
347 | */ |
||
348 | public function getStartStationId() |
||
352 | |||
353 | /** |
||
354 | * Set endStationId |
||
355 | * |
||
356 | * @param integer $endStationId |
||
357 | * @return CharContract |
||
358 | */ |
||
359 | public function setEndStationId($endStationId) |
||
360 | { |
||
361 | $this->endStationId = $endStationId; |
||
362 | |||
363 | return $this; |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * Get endStationId |
||
368 | * |
||
369 | * @return integer |
||
370 | */ |
||
371 | public function getEndStationId() |
||
375 | |||
376 | /** |
||
377 | * Set type |
||
378 | * |
||
379 | * @param string $type |
||
380 | * @return CharContract |
||
381 | */ |
||
382 | public function setType($type) |
||
383 | { |
||
384 | $this->type = $type; |
||
385 | |||
386 | return $this; |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * Get type |
||
391 | * |
||
392 | * @return string |
||
393 | */ |
||
394 | public function getType() |
||
398 | |||
399 | /** |
||
400 | * Set status |
||
401 | * |
||
402 | * @param string $status |
||
403 | * @return CharContract |
||
404 | */ |
||
405 | public function setStatus($status) |
||
406 | { |
||
407 | $this->status = $status; |
||
408 | |||
409 | return $this; |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Get status |
||
414 | * |
||
415 | * @return string |
||
416 | */ |
||
417 | public function getStatus() |
||
421 | |||
422 | /** |
||
423 | * Set title |
||
424 | * |
||
425 | * @param string $title |
||
426 | * @return CharContract |
||
427 | */ |
||
428 | public function setTitle($title) |
||
429 | { |
||
430 | $this->title = $title; |
||
431 | |||
432 | return $this; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * Get title |
||
437 | * |
||
438 | * @return string |
||
439 | */ |
||
440 | public function getTitle() |
||
444 | |||
445 | /** |
||
446 | * Set forCorp |
||
447 | * |
||
448 | * @param boolean $forCorp |
||
449 | * @return CharContract |
||
450 | */ |
||
451 | public function setForCorp($forCorp) |
||
452 | { |
||
453 | $this->forCorp = $forCorp; |
||
454 | |||
455 | return $this; |
||
456 | } |
||
457 | |||
458 | /** |
||
459 | * Get forCorp |
||
460 | * |
||
461 | * @return boolean |
||
462 | */ |
||
463 | public function isForCorp() |
||
467 | |||
468 | /** |
||
469 | * Set availability |
||
470 | * |
||
471 | * @param string $availability |
||
472 | * @return CharContract |
||
473 | */ |
||
474 | public function setAvailability($availability) |
||
475 | { |
||
476 | $this->availability = $availability; |
||
477 | |||
478 | return $this; |
||
479 | } |
||
480 | |||
481 | /** |
||
482 | * Get availability |
||
483 | * |
||
484 | * @return string |
||
485 | */ |
||
486 | public function getAvailability() |
||
490 | |||
491 | /** |
||
492 | * Set dateIssued |
||
493 | * |
||
494 | * @param \DateTime $dateIssued |
||
495 | * @return CharContract |
||
496 | */ |
||
497 | public function setDateIssued($dateIssued) |
||
498 | { |
||
499 | $this->dateIssued = $dateIssued; |
||
500 | |||
501 | return $this; |
||
502 | } |
||
503 | |||
504 | /** |
||
505 | * Get dateIssued |
||
506 | * |
||
507 | * @return \DateTime |
||
508 | */ |
||
509 | public function getDateIssued() |
||
513 | |||
514 | /** |
||
515 | * Set dateExpired |
||
516 | * |
||
517 | * @param \DateTime $dateExpired |
||
518 | * @return CharContract |
||
519 | */ |
||
520 | public function setDateExpired($dateExpired) |
||
521 | { |
||
522 | $this->dateExpired = $dateExpired; |
||
523 | |||
524 | return $this; |
||
525 | } |
||
526 | |||
527 | /** |
||
528 | * Get dateExpired |
||
529 | * |
||
530 | * @return \DateTime |
||
531 | */ |
||
532 | public function getDateExpired() |
||
536 | |||
537 | /** |
||
538 | * Set dateAccepted |
||
539 | * |
||
540 | * @param \DateTime $dateAccepted |
||
541 | * @return CharContract |
||
542 | */ |
||
543 | public function setDateAccepted($dateAccepted) |
||
544 | { |
||
545 | $this->dateAccepted = $dateAccepted; |
||
546 | |||
547 | return $this; |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Get dateAccepted |
||
552 | * |
||
553 | * @return \DateTime |
||
554 | */ |
||
555 | public function getDateAccepted() |
||
559 | |||
560 | /** |
||
561 | * Set numDays |
||
562 | * |
||
563 | * @param integer $numDays |
||
564 | * @return CharContract |
||
565 | */ |
||
566 | public function setNumDays($numDays) |
||
567 | { |
||
568 | $this->numDays = $numDays; |
||
569 | |||
570 | return $this; |
||
571 | } |
||
572 | |||
573 | /** |
||
574 | * Get numDays |
||
575 | * |
||
576 | * @return integer |
||
577 | */ |
||
578 | public function getNumDays() |
||
582 | |||
583 | /** |
||
584 | * Set dateCompleted |
||
585 | * |
||
586 | * @param \DateTime $dateCompleted |
||
587 | * @return CharContract |
||
588 | */ |
||
589 | public function setDateCompleted($dateCompleted) |
||
590 | { |
||
591 | $this->dateCompleted = $dateCompleted; |
||
592 | |||
593 | return $this; |
||
594 | } |
||
595 | |||
596 | /** |
||
597 | * Get dateCompleted |
||
598 | * |
||
599 | * @return \DateTime |
||
600 | */ |
||
601 | public function getDateCompleted() |
||
605 | |||
606 | /** |
||
607 | * Set price |
||
608 | * |
||
609 | * @param float $price |
||
610 | * @return CharContract |
||
611 | */ |
||
612 | public function setPrice($price) |
||
613 | { |
||
614 | $this->price = $price; |
||
615 | |||
616 | return $this; |
||
617 | } |
||
618 | |||
619 | /** |
||
620 | * Get price |
||
621 | * |
||
622 | * @return float |
||
623 | */ |
||
624 | public function getPrice() |
||
628 | |||
629 | /** |
||
630 | * Set reward |
||
631 | * |
||
632 | * @param float $reward |
||
633 | * @return CharContract |
||
634 | */ |
||
635 | public function setReward($reward) |
||
636 | { |
||
637 | $this->reward = $reward; |
||
638 | |||
639 | return $this; |
||
640 | } |
||
641 | |||
642 | /** |
||
643 | * Get reward |
||
644 | * |
||
645 | * @return float |
||
646 | */ |
||
647 | public function getReward() |
||
651 | |||
652 | /** |
||
653 | * Set collateral |
||
654 | * |
||
655 | * @param float $collateral |
||
656 | * @return CharContract |
||
657 | */ |
||
658 | public function setCollateral($collateral) |
||
659 | { |
||
660 | $this->collateral = $collateral; |
||
661 | |||
662 | return $this; |
||
663 | } |
||
664 | |||
665 | /** |
||
666 | * Get collateral |
||
667 | * |
||
668 | * @return float |
||
669 | */ |
||
670 | public function getCollateral() |
||
674 | |||
675 | /** |
||
676 | * Set buyout |
||
677 | * |
||
678 | * @param float $buyout |
||
679 | * @return CharContract |
||
680 | */ |
||
681 | public function setBuyout($buyout) |
||
682 | { |
||
683 | $this->buyout = $buyout; |
||
684 | |||
685 | return $this; |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * Get buyout |
||
690 | * |
||
691 | * @return float |
||
692 | */ |
||
693 | public function getBuyout() |
||
697 | |||
698 | /** |
||
699 | * Set volume |
||
700 | * |
||
701 | * @param integer $volume |
||
702 | * @return CharContract |
||
703 | */ |
||
704 | public function setVolume($volume) |
||
705 | { |
||
706 | $this->volume = $volume; |
||
707 | |||
708 | return $this; |
||
709 | } |
||
710 | |||
711 | /** |
||
712 | * Get volume |
||
713 | * |
||
714 | * @return integer |
||
715 | */ |
||
716 | public function getVolume() |
||
720 | } |
||
721 |