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 |
||
| 28 | class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Set default sorting |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $defaultOrderings = [ |
||
| 37 | 'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
||
| 38 | ]; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Disable the use of storage records, because the StoragePage can be set |
||
| 42 | * in the plugin |
||
| 43 | * |
||
| 44 | * @return void |
||
| 45 | 31 | */ |
|
| 46 | public function initializeObject() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Returns the objects of this repository matching the given demand |
||
| 54 | * |
||
| 55 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 56 | * |
||
| 57 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
||
| 58 | 30 | */ |
|
| 59 | public function findDemanded(EventDemand $eventDemand) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Sets a query limit to the given query for the given demand |
||
| 86 | * |
||
| 87 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 88 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 89 | 30 | * |
|
| 90 | * @return void |
||
| 91 | 30 | */ |
|
| 92 | 30 | protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Sets the ordering to the given query for the given demand |
||
| 104 | * |
||
| 105 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 106 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 107 | 30 | * |
|
| 108 | * @return void |
||
| 109 | 30 | */ |
|
| 110 | 30 | protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
|
| 122 | |||
| 123 | /** |
||
| 124 | * Sets the storagePage constraint to the given constraints array |
||
| 125 | * |
||
| 126 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 127 | 30 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 128 | * @param array $constraints Constraints |
||
| 129 | 30 | * |
|
| 130 | 30 | * @return void |
|
| 131 | 30 | */ |
|
| 132 | 30 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
|
| 139 | |||
| 140 | /** |
||
| 141 | * Sets the displayMode constraint to the given constraints array |
||
| 142 | * |
||
| 143 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 144 | 30 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 145 | * @param array $constraints Constraints |
||
| 146 | 30 | * |
|
| 147 | 30 | * @return void |
|
| 148 | 1 | */ |
|
| 149 | 1 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
|
| 170 | 5 | ||
| 171 | 1 | /** |
|
| 172 | 1 | * Sets the category constraint to the given constraints array |
|
| 173 | 1 | * |
|
| 174 | 4 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 175 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 176 | 5 | * @param array $constraints Constraints |
|
| 177 | 5 | * |
|
| 178 | 5 | * @return void |
|
| 179 | 5 | */ |
|
| 180 | 5 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Returns the category constraint depending on the category conjunction configured in eventDemand |
||
| 206 | * |
||
| 207 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
| 208 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
| 209 | * @param array $categoryConstraints |
||
| 210 | 30 | * @return mixed |
|
| 211 | */ |
||
| 212 | 30 | public function getCategoryConstraint($query, $eventDemand, $categoryConstraints) |
|
| 230 | 2 | ||
| 231 | 30 | /** |
|
| 232 | * Sets the location constraint to the given constraints array |
||
| 233 | * |
||
| 234 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 235 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 236 | * @param array $constraints Constraints |
||
| 237 | * |
||
| 238 | * @return void |
||
| 239 | */ |
||
| 240 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
||
| 246 | 1 | ||
| 247 | 1 | /** |
|
| 248 | * Sets the location.city constraint to the given constraints array |
||
| 249 | * |
||
| 250 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 251 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 252 | 1 | * @param array $constraints Constraints |
|
| 253 | 30 | * |
|
| 254 | * @return void |
||
| 255 | */ |
||
| 256 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
||
| 262 | |||
| 263 | /** |
||
| 264 | 30 | * Sets the location.country constraint to the given constraints array |
|
| 265 | * |
||
| 266 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 267 | 30 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 268 | 3 | * @param array $constraints Constraints |
|
| 269 | 30 | * |
|
| 270 | 1 | * @return void |
|
| 271 | 1 | */ |
|
| 272 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
||
| 278 | 1 | ||
| 279 | 1 | /** |
|
| 280 | 1 | * Sets the organisator constraint to the given constraints array |
|
| 281 | 1 | * |
|
| 282 | 1 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
| 283 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 284 | 1 | * @param array $constraints Constraints |
|
| 285 | 1 | * |
|
| 286 | 1 | * @return void |
|
| 287 | 1 | */ |
|
| 288 | 30 | protected function setOrganisatorConstraint($query, $eventDemand, &$constraints) |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Sets the start- and enddate constraint to the given constraints array |
||
| 297 | * |
||
| 298 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 299 | 30 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
| 300 | * @param array $constraints Constraints |
||
| 301 | 30 | * |
|
| 302 | 2 | * @return void |
|
| 303 | 2 | */ |
|
| 304 | 30 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
|
| 316 | |||
| 317 | /** |
||
| 318 | * Sets the search 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 setSearchConstraint($query, $eventDemand, &$constraints) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Sets the topEvent constraint to the given constraints array |
||
| 354 | * |
||
| 355 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
| 356 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
| 357 | * @param array $constraints Constraints |
||
| 358 | * |
||
| 359 | * @return void |
||
| 360 | */ |
||
| 361 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Sets the restriction for year, year/month or year/month/day to the given constraints array |
||
| 370 | * |
||
| 371 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
| 372 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
| 373 | * @param array $constraints |
||
| 374 | * |
||
| 375 | * @return void |
||
| 376 | */ |
||
| 377 | protected function setYearMonthDayRestriction($query, $eventDemand, &$constraints) |
||
| 402 | } |
||
| 403 |