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 |
||
| 19 | class Registration extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Firstname |
||
| 23 | * |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $firstname = ''; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Lastname |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $lastname = ''; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Title |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $title = ''; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Company |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $company = ''; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Address |
||
| 51 | * |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $address = ''; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Zip |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $zip = ''; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * City |
||
| 65 | * |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $city = ''; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Country |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $country = ''; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Phone |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $phone = ''; |
||
| 83 | |||
| 84 | /** |
||
| 85 | |||
| 86 | * |
||
| 87 | * @var string |
||
| 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; |
||
| 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; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Main registration (if available) |
||
| 149 | * |
||
| 150 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
| 151 | */ |
||
| 152 | protected $mainRegistration; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * DateTime until the registration must be confirmed |
||
| 156 | * |
||
| 157 | * @var \DateTime |
||
| 158 | */ |
||
| 159 | protected $confirmationUntil; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The registration date |
||
| 163 | * |
||
| 164 | * @var \DateTime |
||
| 165 | */ |
||
| 166 | protected $registrationDate; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Indicates if record is hidden |
||
| 170 | * |
||
| 171 | * @var bool |
||
| 172 | */ |
||
| 173 | protected $hidden = false; |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Amount of registrations (if multiple registrations created by one user) |
||
| 177 | * |
||
| 178 | * @var int |
||
| 179 | */ |
||
| 180 | protected $amountOfRegistrations = 1; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * The language (e.g. de) |
||
| 184 | * |
||
| 185 | * @var string |
||
| 186 | */ |
||
| 187 | protected $language = ''; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * reCaptcha |
||
| 191 | * |
||
| 192 | * @var string |
||
| 193 | */ |
||
| 194 | protected $recaptcha = ''; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * FrontendUser if available |
||
| 198 | * |
||
| 199 | * @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
| 200 | */ |
||
| 201 | protected $feUser; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Payment method |
||
| 205 | * |
||
| 206 | * @var string |
||
| 207 | */ |
||
| 208 | protected $paymentmethod = ''; |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Payment reference (e.g. from Payment provider) |
||
| 212 | * |
||
| 213 | * @var string |
||
| 214 | */ |
||
| 215 | protected $paymentReference = ''; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Flags if this is a registration on the waitlist |
||
| 219 | * |
||
| 220 | * @var bool |
||
| 221 | */ |
||
| 222 | protected $waitlist = false; |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Registration fields |
||
| 226 | * |
||
| 227 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Registration\FieldValue> |
||
| 228 | * @Extbase\ORM\Cascade("remove") |
||
| 229 | * @Extbase\ORM\Lazy |
||
| 230 | */ |
||
| 231 | protected $fieldValues; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Registration constructor. |
||
| 235 | */ |
||
| 236 | public function __construct() |
||
| 237 | { |
||
| 238 | $this->fieldValues = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Returns the firstname |
||
| 243 | * |
||
| 244 | * @return string $firstname |
||
| 245 | */ |
||
| 246 | public function getFirstname() |
||
| 247 | { |
||
| 248 | return $this->firstname; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Sets the firstname |
||
| 253 | * |
||
| 254 | * @param string $firstname Firstname |
||
| 255 | */ |
||
| 256 | public function setFirstname($firstname) |
||
| 257 | { |
||
| 258 | $this->firstname = $firstname; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Returns the lastname |
||
| 263 | * |
||
| 264 | * @return string $lastname |
||
| 265 | */ |
||
| 266 | public function getLastname() |
||
| 267 | { |
||
| 268 | return $this->lastname; |
||
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Sets the lastname |
||
| 273 | * |
||
| 274 | * @param string $lastname Lastname |
||
| 275 | */ |
||
| 276 | public function setLastname($lastname) |
||
| 277 | { |
||
| 278 | $this->lastname = $lastname; |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Returns the title |
||
| 283 | * |
||
| 284 | * @return string $title |
||
| 285 | */ |
||
| 286 | public function getTitle() |
||
| 287 | { |
||
| 288 | return $this->title; |
||
| 289 | } |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Sets the title |
||
| 293 | * |
||
| 294 | * @param string $title Title |
||
| 295 | */ |
||
| 296 | public function setTitle($title) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Returns the company |
||
| 303 | * |
||
| 304 | * @return string $company |
||
| 305 | */ |
||
| 306 | public function getCompany() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Sets the company |
||
| 313 | * |
||
| 314 | * @param string $company Company |
||
| 315 | */ |
||
| 316 | public function setCompany($company) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Returns the address |
||
| 323 | * |
||
| 324 | * @return string $address |
||
| 325 | */ |
||
| 326 | public function getAddress() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Sets the address |
||
| 333 | * |
||
| 334 | * @param string $address Address |
||
| 335 | */ |
||
| 336 | public function setAddress($address) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Returns the zip |
||
| 343 | * |
||
| 344 | * @return string $zip |
||
| 345 | */ |
||
| 346 | public function getZip() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Sets the zip |
||
| 353 | * |
||
| 354 | * @param string $zip Zip |
||
| 355 | */ |
||
| 356 | public function setZip($zip) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Returns the city |
||
| 363 | * |
||
| 364 | * @return string $city |
||
| 365 | */ |
||
| 366 | public function getCity() |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Sets the city |
||
| 373 | * |
||
| 374 | * @param string $city City |
||
| 375 | */ |
||
| 376 | public function setCity($city) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Returns the country |
||
| 383 | * |
||
| 384 | * @return string $country |
||
| 385 | */ |
||
| 386 | public function getCountry() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Sets the country |
||
| 393 | * |
||
| 394 | * @param string $country Country |
||
| 395 | */ |
||
| 396 | public function setCountry($country) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Returns the phone |
||
| 403 | * |
||
| 404 | * @return string $phone |
||
| 405 | */ |
||
| 406 | public function getPhone() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Sets the phone |
||
| 413 | * |
||
| 414 | * @param string $phone Phone |
||
| 415 | */ |
||
| 416 | public function setPhone($phone) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Returns the email |
||
| 423 | * |
||
| 424 | * @return string $email |
||
| 425 | */ |
||
| 426 | public function getEmail() |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Sets the email |
||
| 433 | * |
||
| 434 | * @param string $email E-Mail |
||
| 435 | */ |
||
| 436 | public function setEmail($email) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Returns boolean state of ignoreNotifications |
||
| 443 | * |
||
| 444 | * @return bool |
||
| 445 | */ |
||
| 446 | public function isIgnoreNotifications() |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Returns ignoreNotifications |
||
| 453 | * |
||
| 454 | * @return bool |
||
| 455 | */ |
||
| 456 | public function getIgnoreNotifications() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Sets ignoreNotifications |
||
| 463 | * |
||
| 464 | * @param bool $ignoreNotifications IgnoreNotifications |
||
| 465 | */ |
||
| 466 | public function setIgnoreNotifications($ignoreNotifications) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Returns the gender |
||
| 473 | * |
||
| 474 | * @return string $gender |
||
| 475 | */ |
||
| 476 | public function getGender() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Sets the gender |
||
| 483 | * |
||
| 484 | * @param string $gender Gender |
||
| 485 | */ |
||
| 486 | public function setGender($gender) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Sets the date of birth |
||
| 493 | * |
||
| 494 | * @param \DateTime $dateOfBirth DateOfBirth |
||
| 495 | */ |
||
| 496 | public function setDateOfBirth($dateOfBirth) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Returns the date of birth |
||
| 503 | * |
||
| 504 | * @return \DateTime |
||
| 505 | */ |
||
| 506 | public function getDateOfBirth() |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Returns accept terms and conditions |
||
| 513 | * |
||
| 514 | * @return bool $accepttc |
||
| 515 | */ |
||
| 516 | public function getAccepttc() |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Sets accept terms and conditions |
||
| 523 | * |
||
| 524 | * @param bool $accepttc Accept terms and conditions |
||
| 525 | */ |
||
| 526 | public function setAccepttc($accepttc) |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Returns the confirmed |
||
| 533 | * |
||
| 534 | * @return bool $confirmed Confirmed |
||
| 535 | */ |
||
| 536 | public function getConfirmed() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Sets the confirmed |
||
| 543 | * |
||
| 544 | * @param bool $confirmed Confirmed |
||
| 545 | */ |
||
| 546 | public function setConfirmed($confirmed) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Returns the boolean state of confirmed |
||
| 553 | * |
||
| 554 | * @return bool |
||
| 555 | */ |
||
| 556 | public function isConfirmed() |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Returns the paid |
||
| 563 | * |
||
| 564 | * @return bool $paid |
||
| 565 | */ |
||
| 566 | public function getPaid() |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Sets the paid |
||
| 573 | * |
||
| 574 | * @param bool $paid Paid |
||
| 575 | */ |
||
| 576 | public function setPaid($paid) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Returns the boolean state of paid |
||
| 583 | * |
||
| 584 | * @return bool |
||
| 585 | */ |
||
| 586 | public function isPaid() |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Sets the event |
||
| 593 | * |
||
| 594 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 595 | */ |
||
| 596 | public function setEvent($event) |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Returns the event |
||
| 603 | * |
||
| 604 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 605 | */ |
||
| 606 | public function getEvent() |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Sets the mainRegistration |
||
| 613 | * |
||
| 614 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 615 | */ |
||
| 616 | public function setMainRegistration($registration) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Returns the event |
||
| 623 | * |
||
| 624 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
| 625 | */ |
||
| 626 | public function getMainRegistration() |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Setter for notes |
||
| 633 | * |
||
| 634 | * @param string $notes Notes |
||
| 635 | */ |
||
| 636 | public function setNotes($notes) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Getter for notes |
||
| 643 | * |
||
| 644 | * @return string |
||
| 645 | */ |
||
| 646 | public function getNotes() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Sets confirmUntil |
||
| 653 | * |
||
| 654 | * @param \DateTime $confirmationUntil Confirmation Until |
||
| 655 | */ |
||
| 656 | public function setConfirmationUntil($confirmationUntil) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Returns confirmationUntil |
||
| 663 | * |
||
| 664 | * @return \DateTime |
||
| 665 | */ |
||
| 666 | public function getConfirmationUntil() |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Returns registrationDate |
||
| 673 | * |
||
| 674 | * @return \DateTime |
||
| 675 | */ |
||
| 676 | public function getRegistrationDate() |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Sets registrationDate |
||
| 683 | * |
||
| 684 | * @param \DateTime $registrationDate |
||
| 685 | */ |
||
| 686 | public function setRegistrationDate($registrationDate) |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Sets hidden |
||
| 693 | * |
||
| 694 | * @param bool $hidden Hidden |
||
| 695 | */ |
||
| 696 | public function setHidden($hidden) |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Returns hidden |
||
| 703 | * |
||
| 704 | * @return bool |
||
| 705 | */ |
||
| 706 | public function getHidden() |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Returns amountOfRegistrations |
||
| 713 | * |
||
| 714 | * @return int |
||
| 715 | */ |
||
| 716 | public function getAmountOfRegistrations() |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Sets amountOfRegistrations |
||
| 723 | * |
||
| 724 | * @param int $amountOfRegistrations AmountOfRegistrations |
||
| 725 | */ |
||
| 726 | public function setAmountOfRegistrations($amountOfRegistrations) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Returns the language |
||
| 733 | * |
||
| 734 | * @return string |
||
| 735 | */ |
||
| 736 | public function getLanguage() |
||
| 740 | |||
| 741 | /** |
||
| 742 | * Sets the language |
||
| 743 | * |
||
| 744 | * @param string $language |
||
| 745 | */ |
||
| 746 | public function setLanguage($language) |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Returns recaptcha |
||
| 753 | * |
||
| 754 | * @return string |
||
| 755 | */ |
||
| 756 | public function getRecaptcha() |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Sets recaptcha |
||
| 763 | * |
||
| 764 | * @param string $recaptcha |
||
| 765 | */ |
||
| 766 | public function setRecaptcha($recaptcha) |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Returns the frontenduser |
||
| 773 | * |
||
| 774 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
| 775 | */ |
||
| 776 | public function getFeUser() |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Sets the frontenduser |
||
| 783 | * |
||
| 784 | * @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feUser |
||
| 785 | */ |
||
| 786 | public function setFeUser($feUser) |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Returns the payment method |
||
| 793 | * |
||
| 794 | * @return string |
||
| 795 | */ |
||
| 796 | public function getPaymentmethod() |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Sets the payment method |
||
| 803 | * |
||
| 804 | * @param string $paymentmethod |
||
| 805 | */ |
||
| 806 | public function setPaymentmethod($paymentmethod) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Returns paymentReference |
||
| 813 | * |
||
| 814 | * @return string |
||
| 815 | */ |
||
| 816 | public function getPaymentReference() |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Sets paymentReference |
||
| 823 | * |
||
| 824 | * @param string $paymentReference |
||
| 825 | */ |
||
| 826 | public function setPaymentReference($paymentReference) |
||
| 830 | |||
| 831 | /** |
||
| 832 | * Returns waitlist |
||
| 833 | * |
||
| 834 | * @return bool |
||
| 835 | */ |
||
| 836 | public function getWaitlist() |
||
| 840 | |||
| 841 | /** |
||
| 842 | * Sets waitlist |
||
| 843 | * |
||
| 844 | * @param bool $waitlist |
||
| 845 | */ |
||
| 846 | public function setWaitlist($waitlist) |
||
| 850 | |||
| 851 | /** |
||
| 852 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage |
||
| 853 | */ |
||
| 854 | public function getFieldValues() |
||
| 858 | |||
| 859 | /** |
||
| 860 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $fieldValues |
||
| 861 | */ |
||
| 862 | public function setFieldValues($fieldValues) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * @return string |
||
| 869 | */ |
||
| 870 | public function getFullname() |
||
| 874 | } |
||
| 875 |