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 | * Payment Service |
||
64 | * |
||
65 | * @var \DERHANSEN\SfEventMgt\Service\PaymentService |
||
66 | * @inject |
||
67 | */ |
||
68 | protected $paymentService; |
||
69 | |||
70 | /** |
||
71 | * Handles expired registrations. If the $delete parameter is set, then |
||
72 | * registrations are deleted, else just hidden |
||
73 | * |
||
74 | * @param bool $delete Delete |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | 2 | public function handleExpiredRegistrations($delete = false) |
|
93 | |||
94 | /** |
||
95 | * Duplicates (all public accessable properties) the given registration the |
||
96 | * amount of times configured in amountOfRegistrations |
||
97 | * |
||
98 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | 1 | public function createDependingRegistrations($registration) |
|
118 | |||
119 | /** |
||
120 | * Confirms all depending registrations based on the given main registration |
||
121 | * |
||
122 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 1 | public function confirmDependingRegistrations($registration) |
|
135 | |||
136 | /** |
||
137 | * Checks if the registration can be confirmed and returns an array of variables |
||
138 | * |
||
139 | * @param int $reguid UID of registration |
||
140 | * @param string $hmac HMAC for parameters |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | 4 | public function checkConfirmRegistration($reguid, $hmac) |
|
190 | |||
191 | /** |
||
192 | * Cancels all depending registrations based on the given main registration |
||
193 | * |
||
194 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
195 | * |
||
196 | * @return void |
||
197 | */ |
||
198 | 1 | public function cancelDependingRegistrations($registration) |
|
205 | |||
206 | /** |
||
207 | * Checks if the registration can be cancelled and returns an array of variables |
||
208 | * |
||
209 | * @param int $reguid UID of registration |
||
210 | * @param string $hmac HMAC for parameters |
||
211 | * |
||
212 | * @return array |
||
213 | */ |
||
214 | 4 | public function checkCancelRegistration($reguid, $hmac) |
|
257 | |||
258 | /** |
||
259 | * Returns the current frontend user object if available |
||
260 | * |
||
261 | * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser|null |
||
262 | */ |
||
263 | 5 | public function getCurrentFeUserObject() |
|
271 | |||
272 | /** |
||
273 | * Checks, if the registration can successfully be created. Note, that |
||
274 | * $result is passed by reference! |
||
275 | * |
||
276 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
277 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
278 | * @param RegistrationResult $result Result |
||
279 | * |
||
280 | * @return bool |
||
281 | */ |
||
282 | 19 | public function checkRegistrationSuccess($event, $registration, &$result) |
|
319 | |||
320 | /** |
||
321 | * Returns if the given e-mail is registered to the given event |
||
322 | * |
||
323 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
324 | * @param string $email |
||
325 | * @return bool |
||
326 | */ |
||
327 | 2 | protected function emailNotUnique($event, $email) |
|
332 | |||
333 | /** |
||
334 | * Returns, if payment redirect for the payment method is enabled |
||
335 | * |
||
336 | * @param Registration $registration |
||
337 | * @return bool |
||
338 | */ |
||
339 | 2 | public function redirectPaymentEnabled($registration) |
|
353 | |||
354 | /** |
||
355 | * Returns if the given amount of registrations for the event will be registrations for the waitlist |
||
356 | * (depending on the total amount of registrations and free places) |
||
357 | * |
||
358 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
359 | * @param int $amountOfRegistrations |
||
360 | * @return bool |
||
361 | */ |
||
362 | 7 | public function isWaitlistRegistration($event, $amountOfRegistrations) |
|
376 | } |
||
377 |