Complex classes like IndexRepository 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 IndexRepository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class IndexRepository extends AbstractRepository |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * Default orderings for index records. |
||
| 28 | * |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected $defaultOrderings = [ |
||
| 32 | 'start_date' => QueryInterface::ORDER_ASCENDING, |
||
| 33 | 'start_time' => QueryInterface::ORDER_ASCENDING, |
||
| 34 | ]; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Index types for selection. |
||
| 38 | * |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | protected $indexTypes = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Override page ids. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | protected $overridePageIds = []; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return QueryInterface |
||
| 52 | */ |
||
| 53 | public function createQuery() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Get index language mode |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | protected function getIndexLanguageMode() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Set the index types. |
||
| 83 | * |
||
| 84 | * @param array $types |
||
| 85 | */ |
||
| 86 | public function setIndexTypes(array $types) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Override page IDs. |
||
| 93 | * |
||
| 94 | * @param array $overridePageIds |
||
| 95 | */ |
||
| 96 | public function setOverridePageIds($overridePageIds) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Find List. |
||
| 103 | * |
||
| 104 | * @param int $limit |
||
| 105 | * @param int|string $listStartTime |
||
| 106 | * @param int $startOffsetHours |
||
| 107 | * @param int $overrideStartDate |
||
| 108 | * @param int $overrideEndDate |
||
| 109 | * |
||
| 110 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 111 | */ |
||
| 112 | public function findList( |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Find by custom search. |
||
| 146 | * |
||
| 147 | * @param \DateTime $startDate |
||
| 148 | * @param \DateTime $endDate |
||
| 149 | * @param array $customSearch |
||
| 150 | * @param int $limit |
||
| 151 | * |
||
| 152 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 153 | */ |
||
| 154 | public function findBySearch(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [], int $limit = 0) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Find Past Events. |
||
| 197 | * |
||
| 198 | * @param int $limit |
||
| 199 | * @param string $sort |
||
| 200 | * |
||
| 201 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 202 | */ |
||
| 203 | public function findByPast( |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Find by traversing information. |
||
| 223 | * |
||
| 224 | * @param Index $index |
||
| 225 | * @param bool|true $future |
||
| 226 | * @param bool|false $past |
||
| 227 | * @param int $limit |
||
| 228 | * @param string $sort |
||
| 229 | * @param bool $useIndexTime |
||
| 230 | * |
||
| 231 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 232 | */ |
||
| 233 | public function findByTraversing( |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Find by traversing information. |
||
| 272 | * |
||
| 273 | * @param DomainObjectInterface $event |
||
| 274 | * @param bool|true $future |
||
| 275 | * @param bool|false $past |
||
| 276 | * @param int $limit |
||
| 277 | * @param string $sort |
||
| 278 | * |
||
| 279 | * @throws Exception |
||
| 280 | * |
||
| 281 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 282 | */ |
||
| 283 | public function findByEventTraversing( |
||
| 318 | |||
| 319 | /** |
||
| 320 | * find Year. |
||
| 321 | * |
||
| 322 | * @param int $year |
||
| 323 | * |
||
| 324 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 325 | */ |
||
| 326 | public function findYear(int $year) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * find Month. |
||
| 333 | * |
||
| 334 | * @param int $year |
||
| 335 | * @param int $month |
||
| 336 | * |
||
| 337 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 338 | */ |
||
| 339 | public function findMonth(int $year, int $month) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * find Week. |
||
| 349 | * |
||
| 350 | * @param int $year |
||
| 351 | * @param int $week |
||
| 352 | * @param int $weekStart See documentation for settings.weekStart |
||
| 353 | * |
||
| 354 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 355 | */ |
||
| 356 | public function findWeek($year, $week, $weekStart = 1) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Find different types and locations |
||
| 370 | * |
||
| 371 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 372 | */ |
||
| 373 | public function findDifferentTypesAndLocations() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * find day. |
||
| 385 | * |
||
| 386 | * @param int $year |
||
| 387 | * @param int $month |
||
| 388 | * @param int $day |
||
| 389 | * |
||
| 390 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 391 | */ |
||
| 392 | public function findDay(int $year, int $month, int $day) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Set the default sorting direction. |
||
| 401 | * |
||
| 402 | * @param string $direction |
||
| 403 | * @param string $field |
||
| 404 | */ |
||
| 405 | public function setDefaultSortingDirection($direction, $field = '') |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Find by time slot. |
||
| 412 | * |
||
| 413 | * @param int $startTime |
||
| 414 | * @param int|null $endTime null means open end |
||
| 415 | * |
||
| 416 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 417 | */ |
||
| 418 | public function findByTimeSlot($startTime, $endTime = null) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Find all indices by the given Event model. |
||
| 429 | * |
||
| 430 | * @param DomainObjectInterface $event |
||
| 431 | * |
||
| 432 | * @throws Exception |
||
| 433 | * |
||
| 434 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
| 435 | */ |
||
| 436 | public function findByEvent(DomainObjectInterface $event) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * storage page selection. |
||
| 452 | * |
||
| 453 | * @return array |
||
| 454 | */ |
||
| 455 | protected function getStoragePageIds() |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get the default constraint for the queries. |
||
| 479 | * |
||
| 480 | * @param QueryInterface $query |
||
| 481 | * |
||
| 482 | * @return array |
||
| 483 | */ |
||
| 484 | protected function getDefaultConstraints(QueryInterface $query) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Add time frame related queries. |
||
| 512 | * |
||
| 513 | * @param array $constraints |
||
| 514 | * @param QueryInterface $query |
||
| 515 | * @param int $startTime |
||
| 516 | * @param int|null $endTime |
||
| 517 | * |
||
| 518 | * @see IndexUtility::isIndexInRange |
||
| 519 | */ |
||
| 520 | protected function addTimeFrameConstraints(&$constraints, QueryInterface $query, $startTime = null, $endTime = null) |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Get the sorting. |
||
| 579 | * |
||
| 580 | * @param string $direction |
||
| 581 | * @param string $field |
||
| 582 | * |
||
| 583 | * @return array |
||
| 584 | */ |
||
| 585 | protected function getSorting($direction, $field = '') |
||
| 596 | } |
||
| 597 |