Complex classes like CalendarController 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 CalendarController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class CalendarController extends AbstractController |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Init all actions |
||
| 26 | */ |
||
| 27 | public function initializeAction() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Latest action |
||
| 56 | * |
||
| 57 | * @param \HDNET\Calendarize\Domain\Model\Index $index |
||
| 58 | * @param \DateTime $startDate |
||
| 59 | * @param \DateTime $endDate |
||
| 60 | * @param array $customSearch * |
||
| 61 | * @param int $year |
||
| 62 | * @param int $month |
||
| 63 | * @param int $week |
||
| 64 | * |
||
| 65 | * @ignorevalidation $startDate |
||
| 66 | * @ignorevalidation $endDate |
||
| 67 | * @ignorevalidation $customSearch |
||
| 68 | * |
||
| 69 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 70 | */ |
||
| 71 | public function latestAction( |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Result action |
||
| 85 | * |
||
| 86 | * @param \HDNET\Calendarize\Domain\Model\Index $index |
||
| 87 | * @param \DateTime $startDate |
||
| 88 | * @param \DateTime $endDate |
||
| 89 | * @param array $customSearch * |
||
| 90 | * @param int $year |
||
| 91 | * @param int $month |
||
| 92 | * @param int $week |
||
| 93 | * |
||
| 94 | * @ignorevalidation $startDate |
||
| 95 | * @ignorevalidation $endDate |
||
| 96 | * @ignorevalidation $customSearch |
||
| 97 | * |
||
| 98 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 99 | */ |
||
| 100 | public function resultAction( |
||
| 111 | |||
| 112 | /** |
||
| 113 | * List action |
||
| 114 | * |
||
| 115 | * @param \HDNET\Calendarize\Domain\Model\Index $index |
||
| 116 | * @param \DateTime $startDate |
||
| 117 | * @param \DateTime $endDate |
||
| 118 | * @param array $customSearch * |
||
| 119 | * @param int $year |
||
| 120 | * @param int $month |
||
| 121 | * @param int $day |
||
| 122 | * @param int $week |
||
| 123 | * |
||
| 124 | * @ignorevalidation $startDate |
||
| 125 | * @ignorevalidation $endDate |
||
| 126 | * @ignorevalidation $customSearch |
||
| 127 | * |
||
| 128 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
| 129 | */ |
||
| 130 | public function listAction( |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Year action |
||
| 177 | * |
||
| 178 | * @param int $year |
||
| 179 | * |
||
| 180 | * @return void |
||
| 181 | */ |
||
| 182 | public function yearAction($year = null) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Month action |
||
| 194 | * |
||
| 195 | * @param int $year |
||
| 196 | * @param int $month |
||
| 197 | * @param int $day |
||
| 198 | * |
||
| 199 | * @return void |
||
| 200 | */ |
||
| 201 | public function monthAction($year = null, $month = null, $day = null) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Week action |
||
| 213 | * |
||
| 214 | * @param int $year |
||
| 215 | * @param int $week |
||
| 216 | * |
||
| 217 | * @return void |
||
| 218 | */ |
||
| 219 | public function weekAction($year = null, $week = null) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Day action |
||
| 250 | * |
||
| 251 | * @param int $year |
||
| 252 | * @param int $month |
||
| 253 | * @param int $day |
||
| 254 | * |
||
| 255 | * @return void |
||
| 256 | */ |
||
| 257 | public function dayAction($year = null, $month = null, $day = null) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Detail action |
||
| 278 | * |
||
| 279 | * @param \HDNET\Calendarize\Domain\Model\Index $index |
||
| 280 | * |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function detailAction(Index $index = null) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Render the search view |
||
| 312 | * |
||
| 313 | * @param \DateTime $startDate |
||
| 314 | * @param \DateTime $endDate |
||
| 315 | * @param array $customSearch |
||
| 316 | * |
||
| 317 | * @ignorevalidation $startDate |
||
| 318 | * @ignorevalidation $endDate |
||
| 319 | * @ignorevalidation $customSearch |
||
| 320 | */ |
||
| 321 | public function searchAction(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = []) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get the allowed actions |
||
| 342 | * |
||
| 343 | * @return array |
||
| 344 | */ |
||
| 345 | protected function getAllowedActions() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Get the current configurations |
||
| 357 | * |
||
| 358 | * @return array |
||
| 359 | */ |
||
| 360 | protected function getCurrentConfigurations() |
||
| 371 | } |
||
| 372 |