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 |
||
27 | class IndexRepository extends AbstractRepository |
||
28 | { |
||
29 | /** |
||
30 | * Default orderings for index records. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $defaultOrderings = [ |
||
35 | 'start_date' => QueryInterface::ORDER_ASCENDING, |
||
36 | 'start_time' => QueryInterface::ORDER_ASCENDING, |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Index types for selection. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $indexTypes = []; |
||
45 | |||
46 | /** |
||
47 | * Override page ids. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $overridePageIds = []; |
||
52 | |||
53 | /** |
||
54 | * Create query. |
||
55 | * |
||
56 | * @return QueryInterface |
||
57 | */ |
||
58 | public function createQuery() |
||
65 | |||
66 | /** |
||
67 | * Set the index types. |
||
68 | * |
||
69 | * @param array $types |
||
70 | */ |
||
71 | public function setIndexTypes(array $types) |
||
75 | |||
76 | /** |
||
77 | * Override page IDs. |
||
78 | * |
||
79 | * @param array $overridePageIds |
||
80 | */ |
||
81 | public function setOverridePageIds($overridePageIds) |
||
85 | |||
86 | /** |
||
87 | * Select indecies for Backend. |
||
88 | * |
||
89 | * @param OptionRequest $options |
||
90 | * |
||
91 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
92 | */ |
||
93 | public function findAllForBackend(OptionRequest $options) |
||
124 | |||
125 | /** |
||
126 | * Find List. |
||
127 | * |
||
128 | * @param int $limit |
||
129 | * @param int|string $listStartTime |
||
130 | * @param int $startOffsetHours |
||
131 | * @param int $overrideStartDate |
||
132 | * @param int $overrideEndDate |
||
133 | * |
||
134 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
135 | */ |
||
136 | public function findList( |
||
167 | |||
168 | /** |
||
169 | * Find by custom search. |
||
170 | * |
||
171 | * @param \DateTime $startDate |
||
172 | * @param \DateTime $endDate |
||
173 | * @param array $customSearch |
||
174 | * @param int $limit |
||
175 | * |
||
176 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
177 | */ |
||
178 | public function findBySearch(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [], int $limit = 0) |
||
218 | |||
219 | /** |
||
220 | * Find Past Events. |
||
221 | * |
||
222 | * @param int $limit |
||
223 | * @param string $sort |
||
224 | * |
||
225 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
226 | */ |
||
227 | public function findByPast( |
||
244 | |||
245 | /** |
||
246 | * Find by traversing information. |
||
247 | * |
||
248 | * @param Index $index |
||
249 | * @param bool|true $future |
||
250 | * @param bool|false $past |
||
251 | * @param int $limit |
||
252 | * @param string $sort |
||
253 | * @param bool $useIndexTime |
||
254 | * |
||
255 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
256 | */ |
||
257 | public function findByTraversing( |
||
293 | |||
294 | /** |
||
295 | * Find by traversing information. |
||
296 | * |
||
297 | * @param DomainObjectInterface $event |
||
298 | * @param bool|true $future |
||
299 | * @param bool|false $past |
||
300 | * @param int $limit |
||
301 | * @param string $sort |
||
302 | * |
||
303 | * @throws Exception |
||
304 | * |
||
305 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
306 | */ |
||
307 | public function findByEventTraversing( |
||
346 | |||
347 | /** |
||
348 | * find Year. |
||
349 | * |
||
350 | * @param int $year |
||
351 | * |
||
352 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
353 | */ |
||
354 | public function findYear(int $year) |
||
358 | |||
359 | /** |
||
360 | * find quarter. |
||
361 | * |
||
362 | * @param int $year |
||
363 | * @param int $quarter |
||
364 | * |
||
365 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
366 | */ |
||
367 | public function findQuarter(int $year, int $quarter) |
||
373 | |||
374 | /** |
||
375 | * find Month. |
||
376 | * |
||
377 | * @param int $year |
||
378 | * @param int $month |
||
379 | * |
||
380 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
381 | */ |
||
382 | public function findMonth(int $year, int $month) |
||
389 | |||
390 | /** |
||
391 | * find Week. |
||
392 | * |
||
393 | * @param int $year |
||
394 | * @param int $week |
||
395 | * @param int $weekStart See documentation for settings.weekStart |
||
396 | * |
||
397 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
398 | */ |
||
399 | public function findWeek($year, $week, $weekStart = 1) |
||
415 | |||
416 | /** |
||
417 | * Find different types and locations. |
||
418 | * |
||
419 | * @return array |
||
420 | */ |
||
421 | public function findDifferentTypesAndLocations(): array |
||
427 | |||
428 | /** |
||
429 | * find day. |
||
430 | * |
||
431 | * @param int $year |
||
432 | * @param int $month |
||
433 | * @param int $day |
||
434 | * |
||
435 | * @throws Exception |
||
436 | * |
||
437 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
438 | */ |
||
439 | public function findDay(int $year, int $month, int $day) |
||
449 | |||
450 | /** |
||
451 | * Set the default sorting direction. |
||
452 | * |
||
453 | * @param string $direction |
||
454 | * @param string $field |
||
455 | */ |
||
456 | public function setDefaultSortingDirection($direction, $field = '') |
||
460 | |||
461 | /** |
||
462 | * Find by time slot. |
||
463 | * |
||
464 | * @param int $startTime |
||
465 | * @param int|null $endTime null means open end |
||
466 | * |
||
467 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
468 | */ |
||
469 | public function findByTimeSlot($startTime, $endTime = null) |
||
477 | |||
478 | /** |
||
479 | * Find all indices by the given Event model. |
||
480 | * |
||
481 | * @param DomainObjectInterface $event |
||
482 | * |
||
483 | * @throws Exception |
||
484 | * |
||
485 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
486 | */ |
||
487 | public function findByEvent(DomainObjectInterface $event) |
||
500 | |||
501 | /** |
||
502 | * Get index language mode. |
||
503 | * |
||
504 | * @return string |
||
505 | */ |
||
506 | protected function getIndexLanguageMode() |
||
522 | |||
523 | /** |
||
524 | * storage page selection. |
||
525 | * |
||
526 | * @return array |
||
527 | */ |
||
528 | protected function getStoragePageIds() |
||
549 | |||
550 | /** |
||
551 | * Get the default constraint for the queries. |
||
552 | * |
||
553 | * @param QueryInterface $query |
||
554 | * |
||
555 | * @return array |
||
556 | */ |
||
557 | protected function getDefaultConstraints(QueryInterface $query) |
||
582 | |||
583 | /** |
||
584 | * Add time frame related queries. |
||
585 | * |
||
586 | * @param array $constraints |
||
587 | * @param QueryInterface $query |
||
588 | * @param int $startTime |
||
589 | * @param int|null $endTime |
||
590 | * |
||
591 | * @see IndexUtility::isIndexInRange |
||
592 | */ |
||
593 | protected function addTimeFrameConstraints(&$constraints, QueryInterface $query, $startTime = null, $endTime = null) |
||
620 | |||
621 | /** |
||
622 | * Adds time frame constraints which respect the actual index times. |
||
623 | * Do not call this method directly. Call IndexRepository::addTimeFrameConstraints instead. |
||
624 | * |
||
625 | * @param array $constraints |
||
626 | * @param QueryInterface $query |
||
627 | * @param array $arguments |
||
628 | * |
||
629 | * @see IndexRepository::addTimeFrameConstraints |
||
630 | */ |
||
631 | protected function addDateTimeFrameConstraints(&$constraints, QueryInterface $query, array $arguments) |
||
672 | |||
673 | /** |
||
674 | * Adds time frame constraints which respect only the index dates, not the actual index times. |
||
675 | * Do not call this method directly. Call IndexRepository::addTimeFrameConstraints instead. |
||
676 | * |
||
677 | * @param array $constraints |
||
678 | * @param QueryInterface $query |
||
679 | * @param array $arguments |
||
680 | * |
||
681 | * @see IndexRepository::addTimeFrameConstraints |
||
682 | */ |
||
683 | protected function addDateFrameConstraints(&$constraints, QueryInterface $query, array $arguments) |
||
720 | |||
721 | /** |
||
722 | * Get the sorting. |
||
723 | * |
||
724 | * @param string $direction |
||
725 | * @param string $field |
||
726 | * |
||
727 | * @return array |
||
728 | */ |
||
729 | protected function getSorting($direction, $field = '') |
||
747 | } |
||
748 |