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 | * The object manager |
||
31 | * |
||
32 | * @var \TYPO3\CMS\Extbase\Object\ObjectManager |
||
33 | * */ |
||
34 | protected $objectManager; |
||
35 | |||
36 | /** |
||
37 | * RegistrationRepository |
||
38 | * |
||
39 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
||
40 | * */ |
||
41 | protected $registrationRepository; |
||
42 | |||
43 | /** |
||
44 | * FrontendUserRepository |
||
45 | * |
||
46 | * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository |
||
47 | * */ |
||
48 | protected $frontendUserRepository; |
||
49 | |||
50 | /** |
||
51 | * Hash Service |
||
52 | * |
||
53 | * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService |
||
54 | * */ |
||
55 | protected $hashService; |
||
56 | |||
57 | /** |
||
58 | * Payment Service |
||
59 | * |
||
60 | * @var \DERHANSEN\SfEventMgt\Service\PaymentService |
||
61 | * */ |
||
62 | protected $paymentService; |
||
63 | |||
64 | /** |
||
65 | * DI for $frontendUserRepository |
||
66 | * |
||
67 | * @param \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository $frontendUserRepository |
||
68 | */ |
||
69 | public function injectFrontendUserRepository( |
||
74 | |||
75 | /** |
||
76 | * DI for $hashService |
||
77 | * |
||
78 | 4 | * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService |
|
79 | */ |
||
80 | 4 | public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService) |
|
84 | 4 | ||
85 | 2 | /** |
|
86 | 2 | * DI for $objectManager |
|
87 | 2 | * |
|
88 | 2 | * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager |
|
89 | */ |
||
90 | 4 | public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) |
|
94 | |||
95 | /** |
||
96 | * DI for $paymentService |
||
97 | * |
||
98 | * @param \DERHANSEN\SfEventMgt\Service\PaymentService $paymentService |
||
99 | */ |
||
100 | public function injectPaymentService(\DERHANSEN\SfEventMgt\Service\PaymentService $paymentService) |
||
104 | 2 | ||
105 | 2 | /** |
|
106 | * DI for $registrationRepository |
||
107 | 2 | * |
|
108 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository |
|
109 | 2 | */ |
|
110 | 2 | public function injectRegistrationRepository( |
|
115 | 2 | ||
116 | 2 | /** |
|
117 | 2 | * Duplicates (all public accessable properties) the given registration the |
|
118 | * amount of times configured in amountOfRegistrations |
||
119 | * |
||
120 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
121 | */ |
||
122 | public function createDependingRegistrations($registration) |
||
139 | |||
140 | /** |
||
141 | * Confirms all depending registrations based on the given main registration |
||
142 | * |
||
143 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
144 | 8 | */ |
|
145 | public function confirmDependingRegistrations($registration) |
||
154 | 2 | ||
155 | 2 | /** |
|
156 | 2 | * Checks if the registration can be confirmed and returns an array of variables |
|
157 | 6 | * |
|
158 | * @param int $reguid UID of registration |
||
159 | * @param string $hmac HMAC for parameters |
||
160 | 8 | * |
|
161 | 2 | * @return array |
|
162 | 2 | */ |
|
163 | 2 | public function checkConfirmRegistration($reguid, $hmac) |
|
209 | |||
210 | /** |
||
211 | * Cancels all depending registrations based on the given main registration |
||
212 | * |
||
213 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
214 | 8 | */ |
|
215 | public function cancelDependingRegistrations($registration) |
||
222 | 8 | ||
223 | 2 | /** |
|
224 | 2 | * Checks if the registration can be cancelled and returns an array of variables |
|
225 | 2 | * |
|
226 | 2 | * @param int $reguid UID of registration |
|
227 | 6 | * @param string $hmac HMAC for parameters |
|
228 | * |
||
229 | * @return array |
||
230 | 8 | */ |
|
231 | 2 | public function checkCancelRegistration($reguid, $hmac) |
|
280 | |||
281 | /** |
||
282 | 38 | * Returns the current frontend user object if available |
|
283 | * |
||
284 | 38 | * @return mixed \TYPO3\CMS\Extbase\Domain\Model\FrontendUser|null |
|
285 | 38 | */ |
|
286 | 4 | public function getCurrentFeUserObject() |
|
294 | 30 | ||
295 | 26 | /** |
|
296 | 26 | * Checks, if the registration can successfully be created. Note, that |
|
297 | 4 | * $result is passed by reference! |
|
298 | 4 | * |
|
299 | 26 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
300 | 22 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
|
301 | 22 | * @param int $result Result |
|
302 | 4 | * |
|
303 | 4 | * @return array |
|
304 | 22 | */ |
|
305 | 4 | public function checkRegistrationSuccess($event, $registration, $result) |
|
343 | |||
344 | /** |
||
345 | * Returns if the given email is registered to the given event |
||
346 | 2 | * |
|
347 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
|
348 | 2 | * @param string $email |
|
349 | * @return bool |
||
350 | */ |
||
351 | protected function emailNotUnique($event, $email) |
||
373 | 4 | ||
374 | 8 | /** |
|
375 | * Returns, if payment redirect for the payment method is enabled |
||
376 | * |
||
377 | * @param Registration $registration |
||
378 | * @return bool |
||
379 | */ |
||
380 | public function redirectPaymentEnabled($registration) |
||
394 | |||
395 | /** |
||
396 | * Returns if the given amount of registrations for the event will be registrations for the waitlist |
||
397 | * (depending on the total amount of registrations and free places) |
||
398 | * |
||
399 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event |
||
400 | * @param int $amountOfRegistrations |
||
401 | * @return bool |
||
402 | */ |
||
403 | public function isWaitlistRegistration($event, $amountOfRegistrations) |
||
417 | |||
418 | /** |
||
419 | * Fixes the event uid of a registration if the event has been saved as a child of a translated event. |
||
420 | * |
||
421 | * Since TYPO3 9.5 (#82363), registrations for events are saved to the translated event record |
||
422 | * |
||
423 | * Example: |
||
424 | * |
||
425 | * When a registration is saved for a translated event, the registration $registration->setEvent($event) will |
||
426 | * now save the UID of the translated event instead of the uid of the event in default language. |
||
427 | * |
||
428 | * This behavior breaks limitations on events (e.g. max participants). Therefore, the registration must always |
||
429 | * be related to the default event language (Extbase behavior before TYPO3 9.5) |
||
430 | * |
||
431 | * @param Registration $registration |
||
432 | * @param Event $event |
||
433 | */ |
||
434 | public function fixRegistrationEvent(Registration $registration, Event $event) |
||
443 | |||
444 | /** |
||
445 | * Ensures, that the field "sys_language_uid" for registration fields values has the same value as the |
||
446 | * language of the registration and event. This is required, so emails include registration field values |
||
447 | * and correct registration field labels in their translated state. |
||
448 | * |
||
449 | * @param Registration $registration |
||
450 | * @param Event $event |
||
451 | */ |
||
452 | public function fixRegistationFieldValueLanguage(Registration $registration, Event $event) |
||
461 | |||
462 | /** |
||
463 | * Updates the field "sys_language_uid" for all registration field values of the given registration |
||
464 | * |
||
465 | * @param Registration $registration |
||
466 | * @param int $sysLanguageUid |
||
467 | */ |
||
468 | protected function updateRegistrationFieldValueLanguage(Registration $registration, int $sysLanguageUid) |
||
482 | |||
483 | /** |
||
484 | * Sets the "event" field of the given registration to the uid of the given event |
||
485 | * |
||
486 | * @param Registration $registration |
||
487 | * @param Event $event |
||
488 | */ |
||
489 | protected function updateRegistrationEventUid(Registration $registration, Event $event) |
||
503 | |||
504 | /** |
||
505 | * Updates registration/waitlist registration counters for the given event |
||
506 | * |
||
507 | * @param Event $event |
||
508 | */ |
||
509 | protected function updateEventRegistrationCounters(Event $event) |
||
534 | |||
535 | /** |
||
536 | * Returns the total amount of registrations/waitlist registrations for an event |
||
537 | * |
||
538 | * @param Event $event |
||
539 | * @param int $waitlist |
||
540 | * @return mixed |
||
541 | */ |
||
542 | protected function getEventRegistrationCount(Event $event, int $waitlist = 0) |
||
563 | } |
||
564 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.