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 | 1 | 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 | 1 | 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 | 2 | protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand) |
|
206 | |||
207 | /** |
||
208 | * Initialize list action and set format |
||
209 | * |
||
210 | * @return void |
||
211 | */ |
||
212 | public function initializeListAction() |
||
213 | { |
||
214 | if (isset($this->settings['list']['format'])) { |
||
215 | $this->request->setFormat($this->settings['list']['format']); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * List view |
||
221 | * |
||
222 | * @param array $overwriteDemand OverwriteDemand |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | 3 | public function listAction(array $overwriteDemand = []) |
|
227 | { |
||
228 | 3 | $eventDemand = $this->createEventDemandObjectFromSettings($this->settings); |
|
229 | 3 | $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings); |
|
230 | 3 | $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings); |
|
231 | 3 | if ($this->isOverwriteDemand($overwriteDemand)) { |
|
232 | 1 | $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand); |
|
233 | 1 | } |
|
234 | 3 | $events = $this->eventRepository->findDemanded($eventDemand); |
|
235 | 3 | $categories = $this->categoryRepository->findDemanded($categoryDemand); |
|
236 | 3 | $locations = $this->locationRepository->findDemanded($foreignRecordDemand); |
|
237 | 3 | $this->view->assign('events', $events); |
|
238 | 3 | $this->view->assign('categories', $categories); |
|
239 | 3 | $this->view->assign('locations', $locations); |
|
240 | 3 | $this->view->assign('overwriteDemand', $overwriteDemand); |
|
241 | 3 | } |
|
242 | |||
243 | /** |
||
244 | * Detail view for an event |
||
245 | * |
||
246 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | 1 | public function detailAction(Event $event = null) |
|
254 | |||
255 | /** |
||
256 | * Initiates the iCalendar download for the given event |
||
257 | * |
||
258 | * @param Event $event The event |
||
259 | * |
||
260 | * @return bool |
||
261 | */ |
||
262 | 1 | public function icalDownloadAction(Event $event) |
|
267 | |||
268 | /** |
||
269 | * Registration view for an event |
||
270 | * |
||
271 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
272 | * |
||
273 | * @return void |
||
274 | */ |
||
275 | 1 | public function registrationAction(Event $event) |
|
285 | |||
286 | /** |
||
287 | * Set date format for field dateOfBirth |
||
288 | * |
||
289 | * @return void |
||
290 | */ |
||
291 | 1 | public function initializeSaveRegistrationAction() |
|
301 | |||
302 | /** |
||
303 | * Saves the registration |
||
304 | * |
||
305 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration |
||
306 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event |
||
307 | * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator |
||
308 | * |
||
309 | * @return void |
||
310 | */ |
||
311 | 11 | public function saveRegistrationAction(Registration $registration, Event $event) |
|
397 | |||
398 | /** |
||
399 | * Shows the result of the saveRegistrationAction |
||
400 | * |
||
401 | * @param int $result Result |
||
402 | * |
||
403 | * @return void |
||
404 | */ |
||
405 | 9 | public function saveRegistrationResultAction($result) |
|
452 | |||
453 | /** |
||
454 | * Confirms the registration if possible and sends e-mails to admin and user |
||
455 | * |
||
456 | * @param int $reguid UID of registration |
||
457 | * @param string $hmac HMAC for parameters |
||
458 | * |
||
459 | * @return void |
||
460 | */ |
||
461 | 3 | public function confirmRegistrationAction($reguid, $hmac) |
|
517 | |||
518 | /** |
||
519 | * Cancels the registration if possible and sends e-mails to admin and user |
||
520 | * |
||
521 | * @param int $reguid UID of registration |
||
522 | * @param string $hmac HMAC for parameters |
||
523 | * |
||
524 | * @return void |
||
525 | */ |
||
526 | 2 | public function cancelRegistrationAction($reguid, $hmac) |
|
560 | |||
561 | /** |
||
562 | * Set date format for field startDate and endDate |
||
563 | * |
||
564 | * @return void |
||
565 | */ |
||
566 | 1 | public function initializeSearchAction() |
|
585 | |||
586 | /** |
||
587 | * Search view |
||
588 | * |
||
589 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand |
||
590 | * @param array $overwriteDemand OverwriteDemand |
||
591 | * |
||
592 | * @return void |
||
593 | */ |
||
594 | 6 | public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = []) |
|
628 | |||
629 | /** |
||
630 | * Returns if a demand object can be overwritten with the given overwriteDemand array |
||
631 | * |
||
632 | * @param array $overwriteDemand |
||
633 | * @return bool |
||
634 | */ |
||
635 | 9 | protected function isOverwriteDemand($overwriteDemand) |
|
639 | |||
640 | } |
||
641 |