Complex classes like RegistrationService 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 RegistrationService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class RegistrationService |
||
| 28 | { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The object manager |
||
| 32 | * |
||
| 33 | * @var \TYPO3\CMS\Extbase\Object\ObjectManager |
||
| 34 | * @inject |
||
| 35 | */ |
||
| 36 | protected $objectManager; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * RegistrationRepository |
||
| 40 | * |
||
| 41 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
||
| 42 | * @inject |
||
| 43 | */ |
||
| 44 | protected $registrationRepository; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * FrontendUserRepository |
||
| 48 | * |
||
| 49 | * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository |
||
| 50 | * @inject |
||
| 51 | */ |
||
| 52 | protected $frontendUserRepository; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Hash Service |
||
| 56 | * |
||
| 57 | * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService |
||
| 58 | * @inject |
||
| 59 | */ |
||
| 60 | protected $hashService; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Handles expired registrations. If the $delete parameter is set, then |
||
| 64 | * registrations are deleted, else just hidden |
||
| 65 | * |
||
| 66 | * @param bool $delete Delete |
||
| 67 | * |
||
| 68 | * @return void |
||
| 69 | */ |
||
| 70 | public function handleExpiredRegistrations($delete = false) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Duplicates (all public accessable properties) the given registration the |
||
| 88 | * amount of times configured in amountOfRegistrations |
||
| 89 | * |
||
| 90 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | public function createDependingRegistrations($registration) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Confirms all depending registrations based on the given main registration |
||
| 113 | * |
||
| 114 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 115 | * |
||
| 116 | * @return void |
||
| 117 | */ |
||
| 118 | public function confirmDependingRegistrations($registration) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Checks if the registration can be confirmed and returns an array of variables |
||
| 130 | * |
||
| 131 | * @param int $reguid UID of registration |
||
| 132 | * @param string $hmac HMAC for parameters |
||
| 133 | * |
||
| 134 | * @return array |
||
| 135 | */ |
||
| 136 | public function checkConfirmRegistration($reguid, $hmac) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Cancels all depending registrations based on the given main registration |
||
| 180 | * |
||
| 181 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | public function cancelDependingRegistrations($registration) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Checks if the registration can be cancelled and returns an array of variables |
||
| 195 | * |
||
| 196 | * @param int $reguid UID of registration |
||
| 197 | * @param string $hmac HMAC for parameters |
||
| 198 | * |
||
| 199 | * @return array |
||
| 200 | */ |
||
| 201 | public function checkCancelRegistration($reguid, $hmac) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns the current frontend user object if available |
||
| 247 | * |
||
| 248 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser|null |
||
| 249 | */ |
||
| 250 | public function getCurrentFeUserObject() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Checks, if the registration can successfully be created. Note, that |
||
| 261 | * $result is passed by reference! |
||
| 262 | * |
||
| 263 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
| 264 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
| 265 | * @param RegistrationResult $result Result |
||
| 266 | * |
||
| 267 | * @return bool |
||
| 268 | */ |
||
| 269 | public function checkRegistrationSuccess($event, $registration, &$result) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Returns if the given e-mail is registered to the given event |
||
| 305 | * |
||
| 306 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
| 307 | * @param string $email |
||
| 308 | * @return bool |
||
| 309 | */ |
||
| 310 | protected function emailNotUnique($event, $email) |
||
| 315 | } |