Complex classes like EventRepository 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 EventRepository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Set default sorting |
||
| 27 | * |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $defaultOrderings = [ |
||
| 31 | 'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
||
| 32 | ]; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Disable the use of storage records, because the StoragePage can be set |
||
| 36 | * in the plugin |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function initializeObject() |
||
| 45 | 31 | ||
| 46 | /** |
||
| 47 | 31 | * Returns the objects of this repository matching the given demand |
|
| 48 | 31 | * |
|
| 49 | 31 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 50 | * |
||
| 51 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
||
| 52 | */ |
||
| 53 | public function findDemanded(EventDemand $eventDemand) |
||
| 88 | |||
| 89 | 30 | /** |
|
| 90 | * Sets a query limit to the given query for the given demand |
||
| 91 | 30 | * |
|
| 92 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 93 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 94 | 30 | * |
|
| 95 | 1 | * @return void |
|
| 96 | 1 | */ |
|
| 97 | 30 | protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
|
| 106 | |||
| 107 | 30 | /** |
|
| 108 | * Sets the ordering to the given query for the given demand |
||
| 109 | 30 | * |
|
| 110 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 111 | 6 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 112 | 6 | * |
|
| 113 | 3 | * @return void |
|
| 114 | 6 | */ |
|
| 115 | 6 | protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
|
| 127 | 30 | ||
| 128 | /** |
||
| 129 | 30 | * Sets the storagePage constraint to the given constraints array |
|
| 130 | 30 | * |
|
| 131 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 132 | 30 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 133 | 30 | * @param array $constraints Constraints |
|
| 134 | * |
||
| 135 | * @return void |
||
| 136 | */ |
||
| 137 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
||
| 144 | 30 | ||
| 145 | /** |
||
| 146 | 30 | * Sets the displayMode constraint to the given constraints array |
|
| 147 | 30 | * |
|
| 148 | 1 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 149 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 150 | 29 | * @param array $constraints Constraints |
|
| 151 | 1 | * |
|
| 152 | 1 | * @return void |
|
| 153 | 28 | */ |
|
| 154 | 30 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
|
| 175 | |||
| 176 | 5 | /** |
|
| 177 | 5 | * Sets the category constraint to the given constraints array |
|
| 178 | 5 | * |
|
| 179 | 5 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 180 | 5 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 181 | 5 | * @param array $constraints Constraints |
|
| 182 | 5 | * |
|
| 183 | 30 | * @return void |
|
| 184 | */ |
||
| 185 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
||
| 208 | |||
| 209 | /** |
||
| 210 | 30 | * Returns the category constraint depending on the category conjunction configured in eventDemand |
|
| 211 | * |
||
| 212 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
|
| 213 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
|
| 214 | 2 | * @param array $categoryConstraints |
|
| 215 | 30 | * @return mixed |
|
| 216 | */ |
||
| 217 | public function getCategoryConstraint($query, $eventDemand, $categoryConstraints) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Sets the location constraint to the given constraints array |
||
| 239 | * |
||
| 240 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 241 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 242 | 30 | * @param array $constraints Constraints |
|
| 243 | * |
||
| 244 | * @return void |
||
| 245 | 30 | */ |
|
| 246 | 1 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
|
| 252 | 1 | ||
| 253 | 30 | /** |
|
| 254 | * Sets the location.city constraint to the given constraints array |
||
| 255 | * |
||
| 256 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 257 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 258 | * @param array $constraints Constraints |
||
| 259 | * |
||
| 260 | * @return void |
||
| 261 | */ |
||
| 262 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
||
| 268 | 3 | ||
| 269 | 30 | /** |
|
| 270 | 1 | * Sets the location.country constraint to the given constraints array |
|
| 271 | 1 | * |
|
| 272 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 273 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 274 | * @param array $constraints Constraints |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | 1 | */ |
|
| 278 | 1 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
|
| 284 | 1 | ||
| 285 | 1 | /** |
|
| 286 | 1 | * Sets the speaker constraint to the given constraints array |
|
| 287 | 1 | * |
|
| 288 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 289 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 290 | * @param array $constraints Constraints |
||
| 291 | * |
||
| 292 | * @return void |
||
| 293 | */ |
||
| 294 | protected function setSpeakerConstraint($query, $eventDemand, &$constraints) |
||
| 300 | |||
| 301 | 30 | /** |
|
| 302 | 2 | * Sets the organisator constraint to the given constraints array |
|
| 303 | 2 | * |
|
| 304 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 305 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 306 | * @param array $constraints Constraints |
||
| 307 | * |
||
| 308 | * @return void |
||
| 309 | */ |
||
| 310 | protected function setOrganisatorConstraint($query, $eventDemand, &$constraints) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Sets the start- and enddate constraint to the given constraints array |
||
| 319 | * |
||
| 320 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 321 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 322 | * @param array $constraints Constraints |
||
| 323 | * |
||
| 324 | * @return void |
||
| 325 | */ |
||
| 326 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Sets the search constraint to the given constraints array |
||
| 341 | * |
||
| 342 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 343 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 344 | * @param array $constraints Constraints |
||
| 345 | * |
||
| 346 | * @return void |
||
| 347 | */ |
||
| 348 | protected function setSearchConstraint($query, $eventDemand, &$constraints) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Sets the topEvent constraint to the given constraints array |
||
| 376 | * |
||
| 377 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 378 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 379 | * @param array $constraints Constraints |
||
| 380 | * |
||
| 381 | * @return void |
||
| 382 | */ |
||
| 383 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Sets the restriction for year, year/month or year/month/day to the given constraints array |
||
| 392 | * |
||
| 393 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
| 394 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
| 395 | * @param array $constraints |
||
| 396 | * |
||
| 397 | * @return void |
||
| 398 | */ |
||
| 399 | protected function setYearMonthDayRestriction($query, $eventDemand, &$constraints) |
||
| 424 | } |
||
| 425 |