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 | /** |
||
| 26 | * Firstname |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | * @validate NotEmpty |
||
| 30 | */ |
||
| 31 | protected $firstname = ''; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Lastname |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | * @validate NotEmpty |
||
| 38 | */ |
||
| 39 | protected $lastname = ''; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Title |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $title = ''; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Company |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | protected $company = ''; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Address |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $address = ''; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Zip |
||
| 64 | * |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $zip = ''; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * City |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $city = ''; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Country |
||
| 78 | * |
||
| 79 | * @var string |
||
| 80 | */ |
||
| 81 | protected $country = ''; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Phone |
||
| 85 | * |
||
| 86 | * @var string |
||
| 87 | */ |
||
| 88 | protected $phone = ''; |
||
| 89 | |||
| 90 | /** |
||
| 91 | |||
| 92 | * |
||
| 93 | * @var string |
||
| 94 | * @validate NotEmpty, EmailAddress |
||
| 95 | */ |
||
| 96 | protected $email = ''; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Ignore notifications |
||
| 100 | * |
||
| 101 | * @var bool |
||
| 102 | */ |
||
| 103 | protected $ignoreNotifications = false; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Gender |
||
| 107 | * |
||
| 108 | * @var string |
||
| 109 | */ |
||
| 110 | protected $gender = ''; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Date of birth |
||
| 114 | * |
||
| 115 | * @var \DateTime |
||
| 116 | */ |
||
| 117 | protected $dateOfBirth = null; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Accept terms and conditions |
||
| 121 | * |
||
| 122 | * @var bool |
||
| 123 | */ |
||
| 124 | protected $accepttc = false; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Confirmed |
||
| 128 | * |
||
| 129 | * @var bool |
||
| 130 | */ |
||
| 131 | protected $confirmed = false; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Paid |
||
| 135 | * |
||
| 136 | * @var bool |
||
| 137 | */ |
||
| 138 | protected $paid = false; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Notes |
||
| 142 | * |
||
| 143 | * @var string |
||
| 144 | */ |
||
| 145 | protected $notes = ''; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Event |
||
| 149 | * |
||
| 150 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 151 | */ |
||
| 152 | protected $event = null; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Main registration (if available) |
||
| 156 | * |
||
| 157 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
| 158 | */ |
||
| 159 | protected $mainRegistration = null; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * DateTime until the registration must be confirmed |
||
| 163 | * |
||
| 164 | * @var \DateTime |
||
| 165 | */ |
||
| 166 | protected $confirmationUntil = null; |
||
| 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 = null; |
||
| 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 | * Returns the firstname |
||
| 219 | * |
||
| 220 | * @return string $firstname |
||
| 221 | */ |
||
| 222 | public function getFirstname() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Sets the firstname |
||
| 229 | * |
||
| 230 | * @param string $firstname Firstname |
||
| 231 | * |
||
| 232 | * @return void |
||
| 233 | */ |
||
| 234 | public function setFirstname($firstname) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Returns the lastname |
||
| 241 | * |
||
| 242 | * @return string $lastname |
||
| 243 | */ |
||
| 244 | public function getLastname() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Sets the lastname |
||
| 251 | * |
||
| 252 | * @param string $lastname Lastname |
||
| 253 | * |
||
| 254 | * @return void |
||
| 255 | */ |
||
| 256 | public function setLastname($lastname) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Returns the title |
||
| 263 | * |
||
| 264 | * @return string $title |
||
| 265 | */ |
||
| 266 | public function getTitle() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Sets the title |
||
| 273 | * |
||
| 274 | * @param string $title Title |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | public function setTitle($title) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Returns the company |
||
| 285 | * |
||
| 286 | * @return string $company |
||
| 287 | */ |
||
| 288 | public function getCompany() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Sets the company |
||
| 295 | * |
||
| 296 | * @param string $company Company |
||
| 297 | * |
||
| 298 | * @return void |
||
| 299 | */ |
||
| 300 | public function setCompany($company) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Returns the address |
||
| 307 | * |
||
| 308 | * @return string $address |
||
| 309 | */ |
||
| 310 | public function getAddress() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Sets the address |
||
| 317 | * |
||
| 318 | * @param string $address Address |
||
| 319 | * |
||
| 320 | * @return void |
||
| 321 | */ |
||
| 322 | public function setAddress($address) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Returns the zip |
||
| 329 | * |
||
| 330 | * @return string $zip |
||
| 331 | */ |
||
| 332 | public function getZip() |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Sets the zip |
||
| 339 | * |
||
| 340 | * @param string $zip Zip |
||
| 341 | * |
||
| 342 | * @return void |
||
| 343 | */ |
||
| 344 | public function setZip($zip) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Returns the city |
||
| 351 | * |
||
| 352 | * @return string $city |
||
| 353 | */ |
||
| 354 | public function getCity() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Sets the city |
||
| 361 | * |
||
| 362 | * @param string $city City |
||
| 363 | * |
||
| 364 | * @return void |
||
| 365 | */ |
||
| 366 | public function setCity($city) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Returns the country |
||
| 373 | * |
||
| 374 | * @return string $country |
||
| 375 | */ |
||
| 376 | public function getCountry() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Sets the country |
||
| 383 | * |
||
| 384 | * @param string $country Country |
||
| 385 | * |
||
| 386 | * @return void |
||
| 387 | */ |
||
| 388 | public function setCountry($country) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Returns the phone |
||
| 395 | * |
||
| 396 | * @return string $phone |
||
| 397 | */ |
||
| 398 | public function getPhone() |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Sets the phone |
||
| 405 | * |
||
| 406 | * @param string $phone Phone |
||
| 407 | * |
||
| 408 | * @return void |
||
| 409 | */ |
||
| 410 | public function setPhone($phone) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Returns the email |
||
| 417 | * |
||
| 418 | * @return string $email |
||
| 419 | */ |
||
| 420 | public function getEmail() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Sets the email |
||
| 427 | * |
||
| 428 | * @param string $email E-Mail |
||
| 429 | * |
||
| 430 | * @return void |
||
| 431 | */ |
||
| 432 | public function setEmail($email) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Returns boolean state of ignoreNotifications |
||
| 439 | * |
||
| 440 | * @return bool |
||
| 441 | */ |
||
| 442 | public function isIgnoreNotifications() |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Returns ignoreNotifications |
||
| 449 | * |
||
| 450 | * @return bool |
||
| 451 | */ |
||
| 452 | public function getIgnoreNotifications() |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Sets ignoreNotifications |
||
| 459 | * |
||
| 460 | * @param bool $ignoreNotifications IgnoreNotifications |
||
| 461 | * |
||
| 462 | * @return void |
||
| 463 | */ |
||
| 464 | public function setIgnoreNotifications($ignoreNotifications) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Returns the gender |
||
| 471 | * |
||
| 472 | * @return string $gender |
||
| 473 | */ |
||
| 474 | public function getGender() |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Sets the gender |
||
| 481 | * |
||
| 482 | * @param string $gender Gender |
||
| 483 | * |
||
| 484 | * @return void |
||
| 485 | */ |
||
| 486 | public function setGender($gender) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Sets the date of birth |
||
| 493 | * |
||
| 494 | * @param \DateTime $dateOfBirth DateOfBirth |
||
| 495 | * |
||
| 496 | * @return void |
||
| 497 | */ |
||
| 498 | public function setDateOfBirth($dateOfBirth) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Returns the date of birth |
||
| 505 | * |
||
| 506 | * @return \DateTime |
||
| 507 | */ |
||
| 508 | public function getDateOfBirth() |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Returns accept terms and conditions |
||
| 515 | * |
||
| 516 | * @return bool $accepttc |
||
| 517 | */ |
||
| 518 | public function getAccepttc() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Sets accept terms and conditions |
||
| 525 | * |
||
| 526 | * @param bool $accepttc Accept terms and conditions |
||
| 527 | * |
||
| 528 | * @return void |
||
| 529 | */ |
||
| 530 | public function setAccepttc($accepttc) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Returns the confirmed |
||
| 537 | * |
||
| 538 | * @return bool $confirmed Confirmed |
||
| 539 | */ |
||
| 540 | public function getConfirmed() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Sets the confirmed |
||
| 547 | * |
||
| 548 | * @param bool $confirmed Confirmed |
||
| 549 | * |
||
| 550 | * @return void |
||
| 551 | */ |
||
| 552 | public function setConfirmed($confirmed) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Returns the boolean state of confirmed |
||
| 559 | * |
||
| 560 | * @return bool |
||
| 561 | */ |
||
| 562 | public function isConfirmed() |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Returns the paid |
||
| 569 | * |
||
| 570 | * @return bool $paid |
||
| 571 | */ |
||
| 572 | public function getPaid() |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Sets the paid |
||
| 579 | * |
||
| 580 | * @param bool $paid Paid |
||
| 581 | * |
||
| 582 | * @return void |
||
| 583 | */ |
||
| 584 | public function setPaid($paid) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Returns the boolean state of paid |
||
| 591 | * |
||
| 592 | * @return bool |
||
| 593 | */ |
||
| 594 | public function isPaid() |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Sets the event |
||
| 601 | * |
||
| 602 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 603 | * |
||
| 604 | * @return void |
||
| 605 | */ |
||
| 606 | public function setEvent($event) |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Returns the event |
||
| 613 | * |
||
| 614 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 615 | */ |
||
| 616 | public function getEvent() |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Sets the mainRegistration |
||
| 623 | * |
||
| 624 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 625 | * |
||
| 626 | * @return void |
||
| 627 | */ |
||
| 628 | public function setMainRegistration($registration) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Returns the event |
||
| 635 | * |
||
| 636 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
| 637 | */ |
||
| 638 | public function getMainRegistration() |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Setter for notes |
||
| 645 | * |
||
| 646 | * @param string $notes Notes |
||
| 647 | * |
||
| 648 | * @return void |
||
| 649 | */ |
||
| 650 | public function setNotes($notes) |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Getter for notes |
||
| 657 | * |
||
| 658 | * @return string |
||
| 659 | */ |
||
| 660 | public function getNotes() |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Sets confirmUntil |
||
| 667 | * |
||
| 668 | * @param \DateTime $confirmationUntil Confirmation Until |
||
| 669 | * |
||
| 670 | * @return void |
||
| 671 | */ |
||
| 672 | public function setConfirmationUntil($confirmationUntil) |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Returns confirmationUntil |
||
| 679 | * |
||
| 680 | * @return \DateTime |
||
| 681 | */ |
||
| 682 | public function getConfirmationUntil() |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Sets hidden |
||
| 689 | * |
||
| 690 | * @param bool $hidden Hidden |
||
| 691 | * |
||
| 692 | * @return void |
||
| 693 | */ |
||
| 694 | public function setHidden($hidden) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Returns hidden |
||
| 701 | * |
||
| 702 | * @return bool |
||
| 703 | */ |
||
| 704 | public function getHidden() |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Returns amountOfRegistrations |
||
| 711 | * |
||
| 712 | * @return int |
||
| 713 | */ |
||
| 714 | public function getAmountOfRegistrations() |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Sets amountOfRegistrations |
||
| 721 | * |
||
| 722 | * @param int $amountOfRegistrations AmountOfRegistrations |
||
| 723 | * |
||
| 724 | * @return void |
||
| 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 | * @return void |
||
| 746 | */ |
||
| 747 | public function setLanguage($language) |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Returns recaptcha |
||
| 754 | * |
||
| 755 | * @return string |
||
| 756 | */ |
||
| 757 | public function getRecaptcha() |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Sets recaptcha |
||
| 764 | * |
||
| 765 | * @param string $recaptcha |
||
| 766 | * @return void |
||
| 767 | */ |
||
| 768 | public function setRecaptcha($recaptcha) |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Returns the frontenduser |
||
| 775 | * |
||
| 776 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
| 777 | */ |
||
| 778 | public function getFeUser() |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Sets the frontenduser |
||
| 785 | * |
||
| 786 | * @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feUser |
||
| 787 | * @return void |
||
| 788 | */ |
||
| 789 | public function setFeUser($feUser) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Returns the payment method |
||
| 796 | * |
||
| 797 | * @return string |
||
| 798 | */ |
||
| 799 | public function getPaymentmethod() |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Sets the payment method |
||
| 806 | * |
||
| 807 | * @param string $paymentmethod |
||
| 808 | * @return void |
||
| 809 | */ |
||
| 810 | public function setPaymentmethod($paymentmethod) |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Returns paymentReference |
||
| 817 | * |
||
| 818 | * @return string |
||
| 819 | */ |
||
| 820 | public function getPaymentReference() |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Sets paymentReference |
||
| 827 | * |
||
| 828 | * @param string $paymentReference |
||
| 829 | * @return void |
||
| 830 | */ |
||
| 831 | public function setPaymentReference($paymentReference) |
||
| 835 | |||
| 836 | } |