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 |
||
33 | class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController |
||
34 | { |
||
35 | |||
36 | /** |
||
37 | * Configuration Manager |
||
38 | * |
||
39 | * @var ConfigurationManagerInterface |
||
40 | */ |
||
41 | protected $configurationManager; |
||
42 | |||
43 | /** |
||
44 | * EventRepository |
||
45 | * |
||
46 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository |
||
47 | * @inject |
||
48 | */ |
||
49 | protected $eventRepository = null; |
||
50 | |||
51 | /** |
||
52 | * Registration repository |
||
53 | * |
||
54 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository |
||
55 | * @inject |
||
56 | */ |
||
57 | protected $registrationRepository = null; |
||
58 | |||
59 | /** |
||
60 | * Category repository |
||
61 | * |
||
62 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository |
||
63 | * @inject |
||
64 | */ |
||
65 | protected $categoryRepository = null; |
||
66 | |||
67 | /** |
||
68 | * Location repository |
||
69 | * |
||
70 | * @var \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository |
||
71 | * @inject |
||
72 | */ |
||
73 | protected $locationRepository = null; |
||
74 | |||
75 | /** |
||
76 | * Notification Service |
||
77 | * |
||
78 | * @var \DERHANSEN\SfEventMgt\Service\NotificationService |
||
79 | * @inject |
||
80 | */ |
||
81 | protected $notificationService = null; |
||
82 | |||
83 | /** |
||
84 | * ICalendar Service |
||
85 | * |
||
86 | * @var \DERHANSEN\SfEventMgt\Service\ICalendarService |
||
87 | * @inject |
||
88 | */ |
||
89 | protected $icalendarService = null; |
||
90 | |||
91 | /** |
||
92 | * Hash Service |
||
93 | * |
||
94 | * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService |
||
95 | * @inject |
||
96 | */ |
||
97 | protected $hashService; |
||
98 | |||
99 | /** |
||
100 | * RegistrationService |
||
101 | * |
||
102 | * @var \DERHANSEN\SfEventMgt\Service\RegistrationService |
||
103 | * @inject |
||
104 | */ |
||
105 | protected $registrationService = null; |
||
106 | |||
107 | /** |
||
108 | * UtilityService |
||
109 | * |
||
110 | * @var \DERHANSEN\SfEventMgt\Service\UtilityService |
||
111 | * @inject |
||
112 | */ |
||
113 | protected $utilityService = null; |
||
114 | |||
115 | /** |
||
116 | * PaymentMethodService |
||
117 | * |
||
118 | * @var \DERHANSEN\SfEventMgt\Service\PaymentService |
||
119 | * @inject |
||
120 | */ |
||
121 | protected $paymentService = null; |
||
122 | |||
123 | /** |
||
124 | * Properties in this array will be ignored by overwriteDemandObject() |
||
125 | * |
||
126 | * @var array |
||
127 | */ |
||
128 | protected $ignoredSettingsForOverwriteDemand = ['storagePage']; |
||
129 | |||
130 | /** |
||
131 | * Creates an event demand object with the given settings |
||
132 | * |
||
133 | * @param array $settings The settings |
||
134 | * |
||
135 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
136 | */ |
||
137 | public function createEventDemandObjectFromSettings(array $settings) |
||
152 | |||
153 | /** |
||
154 | * Creates a foreign record demand object with the given settings |
||
155 | * |
||
156 | * @param array $settings The settings |
||
157 | * |
||
158 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand |
||
159 | */ |
||
160 | public function createForeignRecordDemandObjectFromSettings(array $settings) |
||
168 | |||
169 | /** |
||
170 | * Creates a category demand object with the given settings |
||
171 | * |
||
172 | * @param array $settings The settings |
||
173 | * |
||
174 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand |
||
175 | */ |
||
176 | public function createCategoryDemandObjectFromSettings(array $settings) |
||
186 | |||
187 | /** |
||
188 | * Overwrites a given demand object by an propertyName => $propertyValue array |
||
189 | * |
||
190 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand |
||
191 | * @param array $overwriteDemand OwerwriteDemand |
||
192 | * |
||
193 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand |
||
194 | */ |
||
195 | protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand) |
||
206 | |||
207 | /** |
||
208 | * List view |
||
209 | * |
||
210 | * @param array $overwriteDemand OverwriteDemand |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | public function listAction(array $overwriteDemand = []) |
||
230 | |||
231 | /** |
||
232 | * Detail view for an event |
||
233 | * |
||
234 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
235 | * |
||
236 | * @return void |
||
237 | */ |
||
238 | public function detailAction(Event $event = null) |
||
242 | |||
243 | /** |
||
244 | * Initiates the iCalendar download for the given event |
||
245 | * |
||
246 | * @param Event $event The event |
||
247 | * |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function icalDownloadAction(Event $event) |
||
255 | |||
256 | /** |
||
257 | * Registration view for an event |
||
258 | * |
||
259 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
260 | * |
||
261 | * @return void |
||
262 | */ |
||
263 | public function registrationAction(Event $event) |
||
270 | |||
271 | /** |
||
272 | * Set date format for field dateOfBirth |
||
273 | * |
||
274 | * @return void |
||
275 | */ |
||
276 | public function initializeSaveRegistrationAction() |
||
286 | |||
287 | /** |
||
288 | * Saves the registration |
||
289 | * |
||
290 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
291 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
292 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
||
293 | * |
||
294 | * @return void |
||
295 | */ |
||
296 | public function saveRegistrationAction(Registration $registration, Event $event) |
||
371 | |||
372 | /** |
||
373 | * Shows the result of the saveRegistrationAction |
||
374 | * |
||
375 | * @param int $result Result |
||
376 | * |
||
377 | * @return void |
||
378 | */ |
||
379 | public function saveRegistrationResultAction($result) |
||
422 | |||
423 | /** |
||
424 | * Confirms the registration if possible and sends e-mails to admin and user |
||
425 | * |
||
426 | * @param int $reguid UID of registration |
||
427 | * @param string $hmac HMAC for parameters |
||
428 | * |
||
429 | * @return void |
||
430 | */ |
||
431 | public function confirmRegistrationAction($reguid, $hmac) |
||
462 | |||
463 | /** |
||
464 | * Cancels the registration if possible and sends e-mails to admin and user |
||
465 | * |
||
466 | * @param int $reguid UID of registration |
||
467 | * @param string $hmac HMAC for parameters |
||
468 | * |
||
469 | * @return void |
||
470 | */ |
||
471 | public function cancelRegistrationAction($reguid, $hmac) |
||
505 | |||
506 | /** |
||
507 | * Set date format for field startDate and endDate |
||
508 | * |
||
509 | * @return void |
||
510 | */ |
||
511 | public function initializeSearchAction() |
||
530 | |||
531 | /** |
||
532 | * Search view |
||
533 | * |
||
534 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
535 | * @param array $overwriteDemand OverwriteDemand |
||
536 | * |
||
537 | * @return void |
||
538 | */ |
||
539 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
||
573 | |||
574 | /** |
||
575 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
576 | * |
||
577 | * @param array $overwriteDemand |
||
578 | * @return bool |
||
579 | */ |
||
580 | protected function isOverwriteDemand($overwriteDemand) |
||
584 | |||
585 | } |
||
586 |