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