Complex classes like Registration 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 Registration, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class Registration extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity |
||
23 | { |
||
24 | /** |
||
25 | * Firstname |
||
26 | * |
||
27 | * @var string |
||
28 | * @validate NotEmpty |
||
29 | */ |
||
30 | protected $firstname = ''; |
||
31 | |||
32 | /** |
||
33 | * Lastname |
||
34 | * |
||
35 | * @var string |
||
36 | * @validate NotEmpty |
||
37 | */ |
||
38 | protected $lastname = ''; |
||
39 | |||
40 | /** |
||
41 | * Title |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $title = ''; |
||
46 | |||
47 | /** |
||
48 | * Company |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $company = ''; |
||
53 | |||
54 | /** |
||
55 | * Address |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $address = ''; |
||
60 | |||
61 | /** |
||
62 | * Zip |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $zip = ''; |
||
67 | |||
68 | /** |
||
69 | * City |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $city = ''; |
||
74 | |||
75 | /** |
||
76 | * Country |
||
77 | * |
||
78 | * @var string |
||
79 | */ |
||
80 | protected $country = ''; |
||
81 | |||
82 | /** |
||
83 | * Phone |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $phone = ''; |
||
88 | |||
89 | /** |
||
90 | |||
91 | * |
||
92 | * @var string |
||
93 | * @validate NotEmpty, EmailAddress |
||
94 | */ |
||
95 | protected $email = ''; |
||
96 | |||
97 | /** |
||
98 | * Ignore notifications |
||
99 | * |
||
100 | * @var bool |
||
101 | */ |
||
102 | protected $ignoreNotifications = false; |
||
103 | |||
104 | /** |
||
105 | * Gender |
||
106 | * |
||
107 | * @var string |
||
108 | */ |
||
109 | protected $gender = ''; |
||
110 | |||
111 | /** |
||
112 | * Date of birth |
||
113 | * |
||
114 | * @var \DateTime |
||
115 | */ |
||
116 | protected $dateOfBirth = null; |
||
117 | |||
118 | /** |
||
119 | * Accept terms and conditions |
||
120 | * |
||
121 | * @var bool |
||
122 | */ |
||
123 | protected $accepttc = false; |
||
124 | |||
125 | /** |
||
126 | * Confirmed |
||
127 | * |
||
128 | * @var bool |
||
129 | */ |
||
130 | protected $confirmed = false; |
||
131 | |||
132 | /** |
||
133 | * Paid |
||
134 | * |
||
135 | * @var bool |
||
136 | */ |
||
137 | protected $paid = false; |
||
138 | |||
139 | /** |
||
140 | * Notes |
||
141 | * |
||
142 | * @var string |
||
143 | */ |
||
144 | protected $notes = ''; |
||
145 | |||
146 | /** |
||
147 | * Event |
||
148 | * |
||
149 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
150 | */ |
||
151 | protected $event = null; |
||
152 | |||
153 | /** |
||
154 | * Main registration (if available) |
||
155 | * |
||
156 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
157 | */ |
||
158 | protected $mainRegistration = null; |
||
159 | |||
160 | /** |
||
161 | * DateTime until the registration must be confirmed |
||
162 | * |
||
163 | * @var \DateTime |
||
164 | */ |
||
165 | protected $confirmationUntil = null; |
||
166 | |||
167 | /** |
||
168 | * Indicates if record is hidden |
||
169 | * |
||
170 | * @var bool |
||
171 | */ |
||
172 | protected $hidden = false; |
||
173 | |||
174 | /** |
||
175 | * Amount of registrations (if multiple registrations created by one user) |
||
176 | * |
||
177 | * @var int |
||
178 | */ |
||
179 | protected $amountOfRegistrations = 1; |
||
180 | |||
181 | /** |
||
182 | * The language (e.g. de) |
||
183 | * |
||
184 | * @var string |
||
185 | */ |
||
186 | protected $language = ''; |
||
187 | |||
188 | /** |
||
189 | * reCaptcha |
||
190 | * |
||
191 | * @var string |
||
192 | */ |
||
193 | protected $recaptcha = ''; |
||
194 | |||
195 | /** |
||
196 | * FrontendUser if available |
||
197 | * |
||
198 | * @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
199 | */ |
||
200 | protected $feUser = null; |
||
201 | |||
202 | /** |
||
203 | * Payment method |
||
204 | * |
||
205 | * @var string |
||
206 | */ |
||
207 | protected $paymentmethod = ''; |
||
208 | |||
209 | /** |
||
210 | * Payment reference (e.g. from Payment provider) |
||
211 | * |
||
212 | * @var string |
||
213 | */ |
||
214 | protected $paymentReference = ''; |
||
215 | |||
216 | /** |
||
217 | * Flags if this is a registration on the waitlist |
||
218 | * |
||
219 | * @var bool |
||
220 | */ |
||
221 | protected $waitlist = false; |
||
222 | |||
223 | /** |
||
224 | * Returns the firstname |
||
225 | * |
||
226 | * @return string $firstname |
||
227 | */ |
||
228 | 1 | public function getFirstname() |
|
232 | |||
233 | /** |
||
234 | * Sets the firstname |
||
235 | * |
||
236 | * @param string $firstname Firstname |
||
237 | * |
||
238 | * @return void |
||
239 | */ |
||
240 | 11 | public function setFirstname($firstname) |
|
244 | |||
245 | /** |
||
246 | * Returns the lastname |
||
247 | * |
||
248 | * @return string $lastname |
||
249 | */ |
||
250 | 1 | public function getLastname() |
|
254 | |||
255 | /** |
||
256 | * Sets the lastname |
||
257 | * |
||
258 | * @param string $lastname Lastname |
||
259 | * |
||
260 | * @return void |
||
261 | */ |
||
262 | 11 | public function setLastname($lastname) |
|
266 | |||
267 | /** |
||
268 | * Returns the title |
||
269 | * |
||
270 | * @return string $title |
||
271 | */ |
||
272 | 1 | public function getTitle() |
|
276 | |||
277 | /** |
||
278 | * Sets the title |
||
279 | * |
||
280 | * @param string $title Title |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | 1 | public function setTitle($title) |
|
288 | |||
289 | /** |
||
290 | * Returns the company |
||
291 | * |
||
292 | * @return string $company |
||
293 | */ |
||
294 | 1 | public function getCompany() |
|
298 | |||
299 | /** |
||
300 | * Sets the company |
||
301 | * |
||
302 | * @param string $company Company |
||
303 | * |
||
304 | * @return void |
||
305 | */ |
||
306 | 1 | public function setCompany($company) |
|
310 | |||
311 | /** |
||
312 | * Returns the address |
||
313 | * |
||
314 | * @return string $address |
||
315 | */ |
||
316 | 1 | public function getAddress() |
|
320 | |||
321 | /** |
||
322 | * Sets the address |
||
323 | * |
||
324 | * @param string $address Address |
||
325 | * |
||
326 | * @return void |
||
327 | */ |
||
328 | 1 | public function setAddress($address) |
|
332 | |||
333 | /** |
||
334 | * Returns the zip |
||
335 | * |
||
336 | * @return string $zip |
||
337 | */ |
||
338 | 1 | public function getZip() |
|
342 | |||
343 | /** |
||
344 | * Sets the zip |
||
345 | * |
||
346 | * @param string $zip Zip |
||
347 | * |
||
348 | * @return void |
||
349 | */ |
||
350 | 1 | public function setZip($zip) |
|
354 | |||
355 | /** |
||
356 | * Returns the city |
||
357 | * |
||
358 | * @return string $city |
||
359 | */ |
||
360 | 1 | public function getCity() |
|
364 | |||
365 | /** |
||
366 | * Sets the city |
||
367 | * |
||
368 | * @param string $city City |
||
369 | * |
||
370 | * @return void |
||
371 | */ |
||
372 | 1 | public function setCity($city) |
|
376 | |||
377 | /** |
||
378 | * Returns the country |
||
379 | * |
||
380 | * @return string $country |
||
381 | */ |
||
382 | 1 | public function getCountry() |
|
386 | |||
387 | /** |
||
388 | * Sets the country |
||
389 | * |
||
390 | * @param string $country Country |
||
391 | * |
||
392 | * @return void |
||
393 | */ |
||
394 | 1 | public function setCountry($country) |
|
398 | |||
399 | /** |
||
400 | * Returns the phone |
||
401 | * |
||
402 | * @return string $phone |
||
403 | */ |
||
404 | 1 | public function getPhone() |
|
408 | |||
409 | /** |
||
410 | * Sets the phone |
||
411 | * |
||
412 | * @param string $phone Phone |
||
413 | * |
||
414 | * @return void |
||
415 | */ |
||
416 | 1 | public function setPhone($phone) |
|
420 | |||
421 | /** |
||
422 | * Returns the email |
||
423 | * |
||
424 | * @return string $email |
||
425 | */ |
||
426 | 11 | public function getEmail() |
|
430 | |||
431 | /** |
||
432 | * Sets the email |
||
433 | * |
||
434 | * @param string $email E-Mail |
||
435 | * |
||
436 | * @return void |
||
437 | */ |
||
438 | 26 | public function setEmail($email) |
|
442 | |||
443 | /** |
||
444 | * Returns boolean state of ignoreNotifications |
||
445 | * |
||
446 | * @return bool |
||
447 | */ |
||
448 | 17 | public function isIgnoreNotifications() |
|
452 | |||
453 | /** |
||
454 | * Returns ignoreNotifications |
||
455 | * |
||
456 | * @return bool |
||
457 | */ |
||
458 | 2 | public function getIgnoreNotifications() |
|
462 | |||
463 | /** |
||
464 | * Sets ignoreNotifications |
||
465 | * |
||
466 | * @param bool $ignoreNotifications IgnoreNotifications |
||
467 | * |
||
468 | * @return void |
||
469 | */ |
||
470 | 9 | public function setIgnoreNotifications($ignoreNotifications) |
|
474 | |||
475 | /** |
||
476 | * Returns the gender |
||
477 | * |
||
478 | * @return string $gender |
||
479 | */ |
||
480 | 1 | public function getGender() |
|
484 | |||
485 | /** |
||
486 | * Sets the gender |
||
487 | * |
||
488 | * @param string $gender Gender |
||
489 | * |
||
490 | * @return void |
||
491 | */ |
||
492 | 1 | public function setGender($gender) |
|
496 | |||
497 | /** |
||
498 | * Sets the date of birth |
||
499 | * |
||
500 | * @param \DateTime $dateOfBirth DateOfBirth |
||
501 | * |
||
502 | * @return void |
||
503 | */ |
||
504 | 1 | public function setDateOfBirth($dateOfBirth) |
|
508 | |||
509 | /** |
||
510 | * Returns the date of birth |
||
511 | * |
||
512 | * @return \DateTime |
||
513 | */ |
||
514 | 1 | public function getDateOfBirth() |
|
518 | |||
519 | /** |
||
520 | * Returns accept terms and conditions |
||
521 | * |
||
522 | * @return bool $accepttc |
||
523 | */ |
||
524 | 2 | public function getAccepttc() |
|
528 | |||
529 | /** |
||
530 | * Sets accept terms and conditions |
||
531 | * |
||
532 | * @param bool $accepttc Accept terms and conditions |
||
533 | * |
||
534 | * @return void |
||
535 | */ |
||
536 | 1 | public function setAccepttc($accepttc) |
|
540 | |||
541 | /** |
||
542 | * Returns the confirmed |
||
543 | * |
||
544 | * @return bool $confirmed Confirmed |
||
545 | */ |
||
546 | 1 | public function getConfirmed() |
|
550 | |||
551 | /** |
||
552 | * Sets the confirmed |
||
553 | * |
||
554 | * @param bool $confirmed Confirmed |
||
555 | * |
||
556 | * @return void |
||
557 | */ |
||
558 | 5 | public function setConfirmed($confirmed) |
|
562 | |||
563 | /** |
||
564 | * Returns the boolean state of confirmed |
||
565 | * |
||
566 | * @return bool |
||
567 | */ |
||
568 | 4 | public function isConfirmed() |
|
572 | |||
573 | /** |
||
574 | * Returns the paid |
||
575 | * |
||
576 | * @return bool $paid |
||
577 | */ |
||
578 | 1 | public function getPaid() |
|
582 | |||
583 | /** |
||
584 | * Sets the paid |
||
585 | * |
||
586 | * @param bool $paid Paid |
||
587 | * |
||
588 | * @return void |
||
589 | */ |
||
590 | 2 | public function setPaid($paid) |
|
594 | |||
595 | /** |
||
596 | * Returns the boolean state of paid |
||
597 | * |
||
598 | * @return bool |
||
599 | */ |
||
600 | 1 | public function isPaid() |
|
604 | |||
605 | /** |
||
606 | * Sets the event |
||
607 | * |
||
608 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
609 | * |
||
610 | * @return void |
||
611 | */ |
||
612 | 2 | public function setEvent($event) |
|
616 | |||
617 | /** |
||
618 | * Returns the event |
||
619 | * |
||
620 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
621 | */ |
||
622 | 7 | public function getEvent() |
|
626 | |||
627 | /** |
||
628 | * Sets the mainRegistration |
||
629 | * |
||
630 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
631 | * |
||
632 | * @return void |
||
633 | */ |
||
634 | 1 | public function setMainRegistration($registration) |
|
638 | |||
639 | /** |
||
640 | * Returns the event |
||
641 | * |
||
642 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
643 | */ |
||
644 | 2 | public function getMainRegistration() |
|
648 | |||
649 | /** |
||
650 | * Setter for notes |
||
651 | * |
||
652 | * @param string $notes Notes |
||
653 | * |
||
654 | * @return void |
||
655 | */ |
||
656 | 1 | public function setNotes($notes) |
|
660 | |||
661 | /** |
||
662 | * Getter for notes |
||
663 | * |
||
664 | * @return string |
||
665 | */ |
||
666 | 1 | public function getNotes() |
|
670 | |||
671 | /** |
||
672 | * Sets confirmUntil |
||
673 | * |
||
674 | * @param \DateTime $confirmationUntil Confirmation Until |
||
675 | * |
||
676 | * @return void |
||
677 | */ |
||
678 | 1 | public function setConfirmationUntil($confirmationUntil) |
|
682 | |||
683 | /** |
||
684 | * Returns confirmationUntil |
||
685 | * |
||
686 | * @return \DateTime |
||
687 | */ |
||
688 | 1 | public function getConfirmationUntil() |
|
692 | |||
693 | /** |
||
694 | * Sets hidden |
||
695 | * |
||
696 | * @param bool $hidden Hidden |
||
697 | * |
||
698 | * @return void |
||
699 | */ |
||
700 | 1 | public function setHidden($hidden) |
|
704 | |||
705 | /** |
||
706 | * Returns hidden |
||
707 | * |
||
708 | * @return bool |
||
709 | */ |
||
710 | 2 | public function getHidden() |
|
714 | |||
715 | /** |
||
716 | * Returns amountOfRegistrations |
||
717 | * |
||
718 | * @return int |
||
719 | */ |
||
720 | 2 | public function getAmountOfRegistrations() |
|
724 | |||
725 | /** |
||
726 | * Sets amountOfRegistrations |
||
727 | * |
||
728 | * @param int $amountOfRegistrations AmountOfRegistrations |
||
729 | * |
||
730 | * @return void |
||
731 | */ |
||
732 | 1 | public function setAmountOfRegistrations($amountOfRegistrations) |
|
736 | |||
737 | /** |
||
738 | * Returns the language |
||
739 | * |
||
740 | * @return string |
||
741 | */ |
||
742 | 32 | public function getLanguage() |
|
746 | |||
747 | /** |
||
748 | * Sets the language |
||
749 | * |
||
750 | * @param string $language |
||
751 | * @return void |
||
752 | */ |
||
753 | 1 | public function setLanguage($language) |
|
757 | |||
758 | /** |
||
759 | * Returns recaptcha |
||
760 | * |
||
761 | * @return string |
||
762 | */ |
||
763 | 2 | public function getRecaptcha() |
|
767 | |||
768 | /** |
||
769 | * Sets recaptcha |
||
770 | * |
||
771 | * @param string $recaptcha |
||
772 | * @return void |
||
773 | */ |
||
774 | 1 | public function setRecaptcha($recaptcha) |
|
778 | |||
779 | /** |
||
780 | * Returns the frontenduser |
||
781 | * |
||
782 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
783 | */ |
||
784 | 2 | public function getFeUser() |
|
788 | |||
789 | /** |
||
790 | * Sets the frontenduser |
||
791 | * |
||
792 | * @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feUser |
||
793 | * @return void |
||
794 | */ |
||
795 | 1 | public function setFeUser($feUser) |
|
799 | |||
800 | /** |
||
801 | * Returns the payment method |
||
802 | * |
||
803 | * @return string |
||
804 | */ |
||
805 | 2 | public function getPaymentmethod() |
|
809 | |||
810 | /** |
||
811 | * Sets the payment method |
||
812 | * |
||
813 | * @param string $paymentmethod |
||
814 | * @return void |
||
815 | */ |
||
816 | 1 | public function setPaymentmethod($paymentmethod) |
|
820 | |||
821 | /** |
||
822 | * Returns paymentReference |
||
823 | * |
||
824 | * @return string |
||
825 | */ |
||
826 | 2 | public function getPaymentReference() |
|
830 | |||
831 | /** |
||
832 | * Sets paymentReference |
||
833 | * |
||
834 | * @param string $paymentReference |
||
835 | * @return void |
||
836 | */ |
||
837 | 1 | public function setPaymentReference($paymentReference) |
|
841 | |||
842 | /** |
||
843 | * Returns waitlist |
||
844 | * |
||
845 | * @return boolean |
||
846 | */ |
||
847 | public function getWaitlist() |
||
851 | |||
852 | /** |
||
853 | * Sets waitlist |
||
854 | * |
||
855 | * @param boolean $waitlist |
||
856 | * @return void |
||
857 | */ |
||
858 | 1 | public function setWaitlist($waitlist) |
|
862 | } |
||
863 |