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 | * Returns the firstname |
||
| 205 | * |
||
| 206 | * @return string $firstname |
||
| 207 | */ |
||
| 208 | 2 | public function getFirstname() |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Sets the firstname |
||
| 215 | * |
||
| 216 | * @param string $firstname Firstname |
||
| 217 | * |
||
| 218 | * @return void |
||
| 219 | */ |
||
| 220 | 22 | public function setFirstname($firstname) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * Returns the lastname |
||
| 227 | * |
||
| 228 | * @return string $lastname |
||
| 229 | */ |
||
| 230 | 2 | public function getLastname() |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Sets the lastname |
||
| 237 | * |
||
| 238 | * @param string $lastname Lastname |
||
| 239 | * |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | 22 | public function setLastname($lastname) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * Returns the title |
||
| 249 | * |
||
| 250 | * @return string $title |
||
| 251 | */ |
||
| 252 | 2 | public function getTitle() |
|
| 256 | |||
| 257 | /** |
||
| 258 | * Sets the title |
||
| 259 | * |
||
| 260 | * @param string $title Title |
||
| 261 | * |
||
| 262 | * @return void |
||
| 263 | */ |
||
| 264 | 2 | public function setTitle($title) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * Returns the company |
||
| 271 | * |
||
| 272 | * @return string $company |
||
| 273 | */ |
||
| 274 | 2 | public function getCompany() |
|
| 278 | |||
| 279 | /** |
||
| 280 | * Sets the company |
||
| 281 | * |
||
| 282 | * @param string $company Company |
||
| 283 | * |
||
| 284 | * @return void |
||
| 285 | */ |
||
| 286 | 2 | public function setCompany($company) |
|
| 290 | |||
| 291 | /** |
||
| 292 | * Returns the address |
||
| 293 | * |
||
| 294 | * @return string $address |
||
| 295 | */ |
||
| 296 | 2 | public function getAddress() |
|
| 300 | |||
| 301 | /** |
||
| 302 | * Sets the address |
||
| 303 | * |
||
| 304 | * @param string $address Address |
||
| 305 | * |
||
| 306 | * @return void |
||
| 307 | */ |
||
| 308 | 2 | public function setAddress($address) |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Returns the zip |
||
| 315 | * |
||
| 316 | * @return string $zip |
||
| 317 | */ |
||
| 318 | 2 | public function getZip() |
|
| 322 | |||
| 323 | /** |
||
| 324 | * Sets the zip |
||
| 325 | * |
||
| 326 | * @param string $zip Zip |
||
| 327 | * |
||
| 328 | * @return void |
||
| 329 | */ |
||
| 330 | 2 | public function setZip($zip) |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Returns the city |
||
| 337 | * |
||
| 338 | * @return string $city |
||
| 339 | */ |
||
| 340 | 2 | public function getCity() |
|
| 344 | |||
| 345 | /** |
||
| 346 | * Sets the city |
||
| 347 | * |
||
| 348 | * @param string $city City |
||
| 349 | * |
||
| 350 | * @return void |
||
| 351 | */ |
||
| 352 | 2 | public function setCity($city) |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Returns the country |
||
| 359 | * |
||
| 360 | * @return string $country |
||
| 361 | */ |
||
| 362 | 2 | public function getCountry() |
|
| 366 | |||
| 367 | /** |
||
| 368 | * Sets the country |
||
| 369 | * |
||
| 370 | * @param string $country Country |
||
| 371 | * |
||
| 372 | * @return void |
||
| 373 | */ |
||
| 374 | 2 | public function setCountry($country) |
|
| 378 | |||
| 379 | /** |
||
| 380 | * Returns the phone |
||
| 381 | * |
||
| 382 | * @return string $phone |
||
| 383 | */ |
||
| 384 | 2 | public function getPhone() |
|
| 388 | |||
| 389 | /** |
||
| 390 | * Sets the phone |
||
| 391 | * |
||
| 392 | * @param string $phone Phone |
||
| 393 | * |
||
| 394 | * @return void |
||
| 395 | */ |
||
| 396 | 2 | public function setPhone($phone) |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Returns the email |
||
| 403 | * |
||
| 404 | * @return string $email |
||
| 405 | */ |
||
| 406 | 14 | public function getEmail() |
|
| 410 | |||
| 411 | /** |
||
| 412 | * Sets the email |
||
| 413 | * |
||
| 414 | * @param string $email E-Mail |
||
| 415 | * |
||
| 416 | * @return void |
||
| 417 | */ |
||
| 418 | 40 | public function setEmail($email) |
|
| 422 | |||
| 423 | /** |
||
| 424 | * Returns boolean state of ignoreNotifications |
||
| 425 | * |
||
| 426 | * @return bool |
||
| 427 | */ |
||
| 428 | 22 | public function isIgnoreNotifications() |
|
| 429 | { |
||
| 430 | 22 | return $this->ignoreNotifications; |
|
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Returns ignoreNotifications |
||
| 435 | * |
||
| 436 | * @return bool |
||
| 437 | */ |
||
| 438 | 4 | public function getIgnoreNotifications() |
|
| 439 | { |
||
| 440 | 4 | return $this->ignoreNotifications; |
|
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Sets ignoreNotifications |
||
| 445 | * |
||
| 446 | * @param bool $ignoreNotifications IgnoreNotifications |
||
| 447 | * |
||
| 448 | * @return void |
||
| 449 | */ |
||
| 450 | 14 | public function setIgnoreNotifications($ignoreNotifications) |
|
| 451 | { |
||
| 452 | 14 | $this->ignoreNotifications = $ignoreNotifications; |
|
| 453 | 14 | } |
|
| 454 | |||
| 455 | /** |
||
| 456 | * Returns the gender |
||
| 457 | * |
||
| 458 | * @return string $gender |
||
| 459 | */ |
||
| 460 | 2 | public function getGender() |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Sets the gender |
||
| 467 | * |
||
| 468 | * @param string $gender Gender |
||
| 469 | * |
||
| 470 | * @return void |
||
| 471 | */ |
||
| 472 | 2 | public function setGender($gender) |
|
| 476 | |||
| 477 | /** |
||
| 478 | * Sets the date of birth |
||
| 479 | * |
||
| 480 | * @param \DateTime $dateOfBirth DateOfBirth |
||
| 481 | * |
||
| 482 | * @return void |
||
| 483 | */ |
||
| 484 | 2 | public function setDateOfBirth($dateOfBirth) |
|
| 488 | |||
| 489 | /** |
||
| 490 | * Returns the date of birth |
||
| 491 | * |
||
| 492 | * @return \DateTime |
||
| 493 | */ |
||
| 494 | 2 | public function getDateOfBirth() |
|
| 498 | |||
| 499 | /** |
||
| 500 | * Returns accept terms and conditions |
||
| 501 | * |
||
| 502 | * @return bool $accepttc |
||
| 503 | */ |
||
| 504 | 2 | public function getAccepttc() |
|
| 505 | { |
||
| 506 | 2 | return $this->accepttc; |
|
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Sets accept terms and conditions |
||
| 511 | * |
||
| 512 | * @param bool $accepttc Accept terms and conditions |
||
| 513 | * |
||
| 514 | * @return void |
||
| 515 | */ |
||
| 516 | 2 | public function setAccepttc($accepttc) |
|
| 517 | { |
||
| 518 | 2 | $this->accepttc = $accepttc; |
|
| 519 | 2 | } |
|
| 520 | |||
| 521 | /** |
||
| 522 | * Returns the confirmed |
||
| 523 | * |
||
| 524 | * @return bool $confirmed Confirmed |
||
| 525 | */ |
||
| 526 | 2 | public function getConfirmed() |
|
| 530 | |||
| 531 | /** |
||
| 532 | * Sets the confirmed |
||
| 533 | * |
||
| 534 | * @param bool $confirmed Confirmed |
||
| 535 | * |
||
| 536 | * @return void |
||
| 537 | */ |
||
| 538 | 10 | public function setConfirmed($confirmed) |
|
| 542 | |||
| 543 | /** |
||
| 544 | * Returns the boolean state of confirmed |
||
| 545 | * |
||
| 546 | * @return bool |
||
| 547 | */ |
||
| 548 | 8 | public function isConfirmed() |
|
| 552 | |||
| 553 | /** |
||
| 554 | * Returns the paid |
||
| 555 | * |
||
| 556 | * @return bool $paid |
||
| 557 | */ |
||
| 558 | 2 | public function getPaid() |
|
| 562 | |||
| 563 | /** |
||
| 564 | * Sets the paid |
||
| 565 | * |
||
| 566 | * @param bool $paid Paid |
||
| 567 | * |
||
| 568 | * @return void |
||
| 569 | */ |
||
| 570 | 4 | public function setPaid($paid) |
|
| 574 | |||
| 575 | /** |
||
| 576 | * Returns the boolean state of paid |
||
| 577 | * |
||
| 578 | * @return bool |
||
| 579 | */ |
||
| 580 | 2 | public function isPaid() |
|
| 584 | |||
| 585 | /** |
||
| 586 | * Sets the event |
||
| 587 | * |
||
| 588 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 589 | * |
||
| 590 | * @return void |
||
| 591 | */ |
||
| 592 | 2 | public function setEvent($event) |
|
| 596 | |||
| 597 | /** |
||
| 598 | * Returns the event |
||
| 599 | * |
||
| 600 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Event |
||
| 601 | */ |
||
| 602 | 2 | public function getEvent() |
|
| 606 | |||
| 607 | /** |
||
| 608 | * Sets the mainRegistration |
||
| 609 | * |
||
| 610 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 611 | * |
||
| 612 | * @return void |
||
| 613 | */ |
||
| 614 | 2 | public function setMainRegistration($registration) |
|
| 615 | { |
||
| 616 | 2 | $this->mainRegistration = $registration; |
|
| 617 | 2 | } |
|
| 618 | |||
| 619 | /** |
||
| 620 | * Returns the event |
||
| 621 | * |
||
| 622 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Registration |
||
| 623 | */ |
||
| 624 | 4 | public function getMainRegistration() |
|
| 625 | { |
||
| 626 | 4 | return $this->mainRegistration; |
|
| 627 | } |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Setter for notes |
||
| 631 | * |
||
| 632 | * @param string $notes Notes |
||
| 633 | * |
||
| 634 | * @return void |
||
| 635 | */ |
||
| 636 | 2 | public function setNotes($notes) |
|
| 640 | |||
| 641 | /** |
||
| 642 | * Getter for notes |
||
| 643 | * |
||
| 644 | * @return string |
||
| 645 | */ |
||
| 646 | 2 | public function getNotes() |
|
| 650 | |||
| 651 | /** |
||
| 652 | * Sets confirmUntil |
||
| 653 | * |
||
| 654 | * @param \DateTime $confirmationUntil Confirmation Until |
||
| 655 | * |
||
| 656 | * @return void |
||
| 657 | */ |
||
| 658 | 2 | public function setConfirmationUntil($confirmationUntil) |
|
| 662 | |||
| 663 | /** |
||
| 664 | * Returns confirmationUntil |
||
| 665 | * |
||
| 666 | * @return \DateTime |
||
| 667 | */ |
||
| 668 | 2 | public function getConfirmationUntil() |
|
| 672 | |||
| 673 | /** |
||
| 674 | * Sets hidden |
||
| 675 | * |
||
| 676 | * @param bool $hidden Hidden |
||
| 677 | * |
||
| 678 | * @return void |
||
| 679 | */ |
||
| 680 | 2 | public function setHidden($hidden) |
|
| 684 | |||
| 685 | /** |
||
| 686 | * Returns hidden |
||
| 687 | * |
||
| 688 | * @return bool |
||
| 689 | */ |
||
| 690 | 4 | public function getHidden() |
|
| 694 | |||
| 695 | /** |
||
| 696 | * Returns amountOfRegistrations |
||
| 697 | * |
||
| 698 | * @return int |
||
| 699 | */ |
||
| 700 | 4 | public function getAmountOfRegistrations() |
|
| 701 | { |
||
| 702 | 4 | return $this->amountOfRegistrations; |
|
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Sets amountOfRegistrations |
||
| 707 | * |
||
| 708 | * @param int $amountOfRegistrations AmountOfRegistrations |
||
| 709 | * |
||
| 710 | * @return void |
||
| 711 | */ |
||
| 712 | 2 | public function setAmountOfRegistrations($amountOfRegistrations) |
|
| 713 | { |
||
| 714 | 2 | $this->amountOfRegistrations = $amountOfRegistrations; |
|
| 715 | 2 | } |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Returns the language |
||
| 719 | * |
||
| 720 | * @return string |
||
| 721 | */ |
||
| 722 | 40 | public function getLanguage() |
|
| 726 | |||
| 727 | /** |
||
| 728 | * Sets the language |
||
| 729 | * |
||
| 730 | * @param string $language |
||
| 731 | * @return void |
||
| 732 | */ |
||
| 733 | 2 | public function setLanguage($language) |
|
| 737 | |||
| 738 | /** |
||
| 739 | * Returns recaptcha |
||
| 740 | * |
||
| 741 | * @return string |
||
| 742 | */ |
||
| 743 | 4 | public function getRecaptcha() |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Sets recaptcha |
||
| 750 | * |
||
| 751 | * @param string $recaptcha |
||
| 752 | * @return void |
||
| 753 | */ |
||
| 754 | 2 | public function setRecaptcha($recaptcha) |
|
| 758 | |||
| 759 | /** |
||
| 760 | * Returns the frontenduser |
||
| 761 | * |
||
| 762 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser |
||
| 763 | */ |
||
| 764 | 4 | public function getFeUser() |
|
| 768 | |||
| 769 | /** |
||
| 770 | * Sets the frontenduser |
||
| 771 | * |
||
| 772 | * @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feUser |
||
| 773 | * @return void |
||
| 774 | */ |
||
| 775 | 2 | public function setFeUser($feUser) |
|
| 779 | |||
| 780 | } |