Complex classes like EventController 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 EventController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * Configuration Manager |
||
42 | * |
||
43 | * @var ConfigurationManagerInterface |
||
44 | */ |
||
45 | protected $configurationManager; |
||
46 | |||
47 | /** |
||
48 | * EventRepository |
||
49 | * |
||
50 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository |
||
51 | */ |
||
52 | protected $eventRepository = null; |
||
53 | |||
54 | /** |
||
55 | * Registration repository |
||
56 | * |
||
57 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
||
58 | */ |
||
59 | protected $registrationRepository = null; |
||
60 | |||
61 | /** |
||
62 | * Category repository |
||
63 | * |
||
64 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository |
||
65 | */ |
||
66 | protected $categoryRepository = null; |
||
67 | |||
68 | /** |
||
69 | * Location repository |
||
70 | * |
||
71 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository |
||
72 | */ |
||
73 | protected $locationRepository = null; |
||
74 | |||
75 | /** |
||
76 | * Organisator repository |
||
77 | * |
||
78 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository |
||
79 | */ |
||
80 | protected $organisatorRepository = null; |
||
81 | |||
82 | /** |
||
83 | * Notification Service |
||
84 | * |
||
85 | * @var \DERHANSEN\SfEventMgt\Service\NotificationService |
||
86 | */ |
||
87 | protected $notificationService = null; |
||
88 | |||
89 | /** |
||
90 | * ICalendar Service |
||
91 | * |
||
92 | * @var \DERHANSEN\SfEventMgt\Service\ICalendarService |
||
93 | */ |
||
94 | protected $icalendarService = null; |
||
95 | |||
96 | /** |
||
97 | * Hash Service |
||
98 | * |
||
99 | * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService |
||
100 | */ |
||
101 | protected $hashService; |
||
102 | |||
103 | /** |
||
104 | * RegistrationService |
||
105 | * |
||
106 | * @var \DERHANSEN\SfEventMgt\Service\RegistrationService |
||
107 | */ |
||
108 | protected $registrationService = null; |
||
109 | |||
110 | /** |
||
111 | * CalendarService |
||
112 | * |
||
113 | * @var \DERHANSEN\SfEventMgt\Service\CalendarService |
||
114 | */ |
||
115 | protected $calendarService = null; |
||
116 | |||
117 | /** |
||
118 | * UtilityService |
||
119 | * |
||
120 | * @var \DERHANSEN\SfEventMgt\Service\UtilityService |
||
121 | */ |
||
122 | protected $utilityService = null; |
||
123 | |||
124 | /** |
||
125 | * PaymentMethodService |
||
126 | * |
||
127 | * @var \DERHANSEN\SfEventMgt\Service\PaymentService |
||
128 | */ |
||
129 | protected $paymentService = null; |
||
130 | |||
131 | /** |
||
132 | * Properties in this array will be ignored by overwriteDemandObject() |
||
133 | * |
||
134 | * @var array |
||
135 | */ |
||
136 | protected $ignoredSettingsForOverwriteDemand = ['storagepage', 'orderfieldallowed']; |
||
137 | 1 | ||
138 | /** |
||
139 | * DI for $calendarService |
||
140 | 1 | * |
|
141 | 1 | * @param \DERHANSEN\SfEventMgt\Service\CalendarService $calendarService |
|
142 | 1 | */ |
|
143 | 1 | public function injectCalendarService(\DERHANSEN\SfEventMgt\Service\CalendarService $calendarService) |
|
147 | 1 | ||
148 | 1 | /** |
|
149 | 1 | * DI for $categoryRepository |
|
150 | 1 | * |
|
151 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository $categoryRepository |
||
152 | */ |
||
153 | public function injectCategoryRepository( |
||
158 | |||
159 | /** |
||
160 | * DI for $eventRepository |
||
161 | * |
||
162 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository |
||
163 | */ |
||
164 | public function injectEventRepository(\DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository) |
||
168 | |||
169 | /** |
||
170 | * DI for $hashService |
||
171 | * |
||
172 | * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService |
||
173 | */ |
||
174 | public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService) |
||
178 | |||
179 | 1 | /** |
|
180 | 1 | * DI for $icalendarService |
|
181 | 1 | * |
|
182 | 1 | * @param \DERHANSEN\SfEventMgt\Service\ICalendarService $icalendarService |
|
183 | 1 | */ |
|
184 | 1 | public function injectIcalendarService(\DERHANSEN\SfEventMgt\Service\ICalendarService $icalendarService) |
|
188 | |||
189 | /** |
||
190 | * DI for $locationRepository |
||
191 | * |
||
192 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository $locationRepository |
||
193 | */ |
||
194 | public function injectLocationRepository( |
||
199 | 2 | ||
200 | /** |
||
201 | 2 | * DI for $notificationService |
|
202 | 2 | * |
|
203 | 2 | * @param \DERHANSEN\SfEventMgt\Service\NotificationService $notificationService |
|
204 | 2 | */ |
|
205 | public function injectNotificationService(\DERHANSEN\SfEventMgt\Service\NotificationService $notificationService) |
||
209 | |||
210 | /** |
||
211 | * DI for $organisatorRepository |
||
212 | * |
||
213 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository $organisatorRepository |
||
214 | */ |
||
215 | public function injectOrganisatorRepository( |
||
220 | |||
221 | /** |
||
222 | * DI for $paymentService |
||
223 | * |
||
224 | * @param \DERHANSEN\SfEventMgt\Service\PaymentService $paymentService |
||
225 | */ |
||
226 | 3 | public function injectPaymentService(\DERHANSEN\SfEventMgt\Service\PaymentService $paymentService) |
|
230 | 3 | ||
231 | 3 | /** |
|
232 | 1 | * DI for $registrationRepository |
|
233 | 1 | * |
|
234 | 3 | * @param \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository |
|
235 | 3 | */ |
|
236 | 3 | public function injectRegistrationRepository( |
|
241 | 3 | ||
242 | /** |
||
243 | * DI for $registrationService |
||
244 | * |
||
245 | * @param \DERHANSEN\SfEventMgt\Service\RegistrationService $registrationService |
||
246 | */ |
||
247 | public function injectRegistrationService(\DERHANSEN\SfEventMgt\Service\RegistrationService $registrationService) |
||
251 | |||
252 | 1 | /** |
|
253 | 1 | * DI for $utilityService |
|
254 | * |
||
255 | * @param \DERHANSEN\SfEventMgt\Service\UtilityService $utilityService |
||
256 | */ |
||
257 | public function injectUtilityService(\DERHANSEN\SfEventMgt\Service\UtilityService $utilityService) |
||
261 | |||
262 | 1 | /** |
|
263 | * Creates an event demand object with the given settings |
||
264 | 1 | * |
|
265 | 1 | * @param array $settings The settings |
|
266 | * |
||
267 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
268 | */ |
||
269 | public function createEventDemandObjectFromSettings(array $settings) |
||
287 | |||
288 | /** |
||
289 | * Creates a foreign record demand object with the given settings |
||
290 | * |
||
291 | 1 | * @param array $settings The settings |
|
292 | * |
||
293 | 1 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
|
294 | 1 | */ |
|
295 | 1 | public function createForeignRecordDemandObjectFromSettings(array $settings) |
|
303 | |||
304 | /** |
||
305 | * Creates a category demand object with the given settings |
||
306 | * |
||
307 | * @param array $settings The settings |
||
308 | * |
||
309 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
||
310 | */ |
||
311 | 11 | public function createCategoryDemandObjectFromSettings(array $settings) |
|
321 | 4 | ||
322 | 4 | /** |
|
323 | 4 | * Overwrites a given demand object by an propertyName => $propertyValue array |
|
324 | 4 | * |
|
325 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand |
||
326 | 4 | * @param array $overwriteDemand OwerwriteDemand |
|
327 | 4 | * |
|
328 | 4 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
|
329 | 4 | */ |
|
330 | protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand) |
||
344 | 4 | ||
345 | 1 | /** |
|
346 | 1 | * Hook into request processing and catch exceptions |
|
347 | 1 | * |
|
348 | 3 | * @param RequestInterface $request |
|
349 | 3 | * @param ResponseInterface $response |
|
350 | * @throws \Exception |
||
351 | 4 | */ |
|
352 | public function processRequest(RequestInterface $request, ResponseInterface $response) |
||
360 | 3 | ||
361 | 3 | /** |
|
362 | 3 | * Handle known exceptions |
|
363 | 3 | * |
|
364 | 3 | * @param \Exception $exception |
|
365 | * @throws \Exception |
||
366 | 3 | */ |
|
367 | 3 | private function handleKnownExceptionsElseThrowAgain(\Exception $exception) |
|
378 | 11 | ||
379 | 1 | /** |
|
380 | 1 | * Initialize list action and set format |
|
381 | 1 | * |
|
382 | 1 | * @return void |
|
383 | */ |
||
384 | 1 | public function initializeListAction() |
|
390 | 10 | ||
391 | 10 | /** |
|
392 | 10 | * List view |
|
393 | 10 | * |
|
394 | 10 | * @param array $overwriteDemand OverwriteDemand |
|
395 | * |
||
396 | 11 | * @return void |
|
397 | */ |
||
398 | public function listAction(array $overwriteDemand = []) |
||
419 | 1 | ||
420 | 7 | /** |
|
421 | 1 | * Calendar view |
|
422 | 1 | * |
|
423 | 1 | * @param array $overwriteDemand OverwriteDemand |
|
424 | 6 | * |
|
425 | 1 | * @return void |
|
426 | 1 | */ |
|
427 | 1 | public function calendarAction(array $overwriteDemand = []) |
|
479 | 2 | ||
480 | /** |
||
481 | 2 | * Changes the given event demand object to select a date range for a calendar month including days of the previous |
|
482 | 2 | * month for the first week and they days for the next month for the last week |
|
483 | 2 | * |
|
484 | 2 | * @param EventDemand $eventDemand |
|
485 | 2 | * @return EventDemand |
|
486 | */ |
||
487 | 2 | protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand) |
|
510 | |||
511 | /** |
||
512 | * Detail view for an event |
||
513 | * |
||
514 | 3 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
515 | 3 | * @return string |
|
516 | 3 | */ |
|
517 | public function detailAction(Event $event = null) |
||
524 | |||
525 | /** |
||
526 | 2 | * Error handling if event is not found |
|
527 | * |
||
528 | * @param array $settings |
||
529 | 2 | * @return string |
|
530 | */ |
||
531 | 2 | protected function handleEventNotFoundError($settings) |
|
559 | 2 | ||
560 | /** |
||
561 | * Initiates the iCalendar download for the given event |
||
562 | * |
||
563 | * @param Event $event The event |
||
564 | * |
||
565 | * @return bool |
||
566 | 1 | */ |
|
567 | public function icalDownloadAction(Event $event) |
||
572 | 1 | ||
573 | 1 | /** |
|
574 | 1 | * Registration view for an event |
|
575 | 1 | * |
|
576 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
577 | 1 | * |
|
578 | 1 | * @return string |
|
579 | 1 | */ |
|
580 | 1 | public function registrationAction(Event $event = null) |
|
596 | 6 | ||
597 | 6 | /** |
|
598 | 6 | * Set date format for field dateOfBirth |
|
599 | 6 | * |
|
600 | * @return void |
||
601 | 6 | */ |
|
602 | 5 | public function initializeSaveRegistrationAction() |
|
612 | |||
613 | 6 | /** |
|
614 | 1 | * Saves the registration |
|
615 | 1 | * |
|
616 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
617 | 6 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
|
618 | 6 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
|
619 | * |
||
620 | 6 | * @return void |
|
621 | */ |
||
622 | 6 | public function saveRegistrationAction(Registration $registration, Event $event) |
|
712 | |||
713 | /** |
||
714 | * Shows the result of the saveRegistrationAction |
||
715 | * |
||
716 | * @param int $result Result |
||
717 | * @param int $eventuid |
||
718 | * @param string $hmac |
||
719 | * |
||
720 | * @return void |
||
721 | */ |
||
722 | public function saveRegistrationResultAction($result, $eventuid, $hmac) |
||
781 | |||
782 | /** |
||
783 | * Confirms the registration if possible and sends e-mails to admin and user |
||
784 | * |
||
785 | * @param int $reguid UID of registration |
||
786 | * @param string $hmac HMAC for parameters |
||
787 | * |
||
788 | * @return void |
||
789 | */ |
||
790 | public function confirmRegistrationAction($reguid, $hmac) |
||
855 | |||
856 | /** |
||
857 | * Cancels the registration if possible and sends e-mails to admin and user |
||
858 | * |
||
859 | * @param int $reguid UID of registration |
||
860 | * @param string $hmac HMAC for parameters |
||
861 | * |
||
862 | * @return void |
||
863 | */ |
||
864 | public function cancelRegistrationAction($reguid, $hmac) |
||
906 | |||
907 | /** |
||
908 | * Set date format for field startDate and endDate |
||
909 | * |
||
910 | * @return void |
||
911 | */ |
||
912 | public function initializeSearchAction() |
||
931 | |||
932 | /** |
||
933 | * Search view |
||
934 | * |
||
935 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
936 | * @param array $overwriteDemand OverwriteDemand |
||
937 | * |
||
938 | * @return void |
||
939 | */ |
||
940 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
978 | |||
979 | /** |
||
980 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
981 | * |
||
982 | * @param array $overwriteDemand |
||
983 | * @return bool |
||
984 | */ |
||
985 | protected function isOverwriteDemand($overwriteDemand) |
||
989 | |||
990 | } |
||
991 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.