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() |
||
60 | |||
61 | /** |
||
62 | * Set the index types. |
||
63 | * |
||
64 | * @param array $types |
||
65 | */ |
||
66 | public function setIndexTypes(array $types) |
||
70 | |||
71 | /** |
||
72 | * Override page IDs. |
||
73 | * |
||
74 | * @param array $overridePageIds |
||
75 | */ |
||
76 | public function setOverridePageIds($overridePageIds) |
||
80 | |||
81 | /** |
||
82 | * Select indecies for Backend. |
||
83 | * |
||
84 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
85 | */ |
||
86 | public function findAllForBackend() |
||
93 | |||
94 | /** |
||
95 | * Find List. |
||
96 | * |
||
97 | * @param int $limit |
||
98 | * @param int|string $listStartTime |
||
99 | * @param int $startOffsetHours |
||
100 | * @param int $overrideStartDate |
||
101 | * @param int $overrideEndDate |
||
102 | * |
||
103 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
104 | */ |
||
105 | public function findList( |
||
136 | |||
137 | /** |
||
138 | * Find by custom search. |
||
139 | * |
||
140 | * @param \DateTime $startDate |
||
141 | * @param \DateTime $endDate |
||
142 | * @param array $customSearch |
||
143 | * @param int $limit |
||
144 | * |
||
145 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
146 | */ |
||
147 | public function findBySearch(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [], int $limit = 0) |
||
187 | |||
188 | /** |
||
189 | * Find Past Events. |
||
190 | * |
||
191 | * @param int $limit |
||
192 | * @param string $sort |
||
193 | * |
||
194 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
195 | */ |
||
196 | public function findByPast( |
||
213 | |||
214 | /** |
||
215 | * Find by traversing information. |
||
216 | * |
||
217 | * @param Index $index |
||
218 | * @param bool|true $future |
||
219 | * @param bool|false $past |
||
220 | * @param int $limit |
||
221 | * @param string $sort |
||
222 | * @param bool $useIndexTime |
||
223 | * |
||
224 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
225 | */ |
||
226 | public function findByTraversing( |
||
262 | |||
263 | /** |
||
264 | * Find by traversing information. |
||
265 | * |
||
266 | * @param DomainObjectInterface $event |
||
267 | * @param bool|true $future |
||
268 | * @param bool|false $past |
||
269 | * @param int $limit |
||
270 | * @param string $sort |
||
271 | * |
||
272 | * @throws Exception |
||
273 | * |
||
274 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
275 | */ |
||
276 | public function findByEventTraversing( |
||
312 | |||
313 | /** |
||
314 | * find Year. |
||
315 | * |
||
316 | * @param int $year |
||
317 | * |
||
318 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
319 | */ |
||
320 | public function findYear(int $year) |
||
324 | |||
325 | /** |
||
326 | * find quarter. |
||
327 | * |
||
328 | * @param int $year |
||
329 | * @param int $quarter |
||
330 | * |
||
331 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
332 | */ |
||
333 | public function findQuarter(int $year, int $quarter) |
||
339 | |||
340 | /** |
||
341 | * find Month. |
||
342 | * |
||
343 | * @param int $year |
||
344 | * @param int $month |
||
345 | * |
||
346 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
347 | */ |
||
348 | public function findMonth(int $year, int $month) |
||
355 | |||
356 | /** |
||
357 | * find Week. |
||
358 | * |
||
359 | * @param int $year |
||
360 | * @param int $week |
||
361 | * @param int $weekStart See documentation for settings.weekStart |
||
362 | * |
||
363 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
364 | */ |
||
365 | public function findWeek($year, $week, $weekStart = 1) |
||
381 | |||
382 | /** |
||
383 | * Find different types and locations. |
||
384 | * |
||
385 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
386 | */ |
||
387 | public function findDifferentTypesAndLocations() |
||
397 | |||
398 | /** |
||
399 | * find day. |
||
400 | * |
||
401 | * @param int $year |
||
402 | * @param int $month |
||
403 | * @param int $day |
||
404 | * |
||
405 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
406 | * @throws Exception |
||
407 | */ |
||
408 | public function findDay(int $year, int $month, int $day) |
||
418 | |||
419 | /** |
||
420 | * Set the default sorting direction. |
||
421 | * |
||
422 | * @param string $direction |
||
423 | * @param string $field |
||
424 | */ |
||
425 | public function setDefaultSortingDirection($direction, $field = '') |
||
429 | |||
430 | /** |
||
431 | * Find by time slot. |
||
432 | * |
||
433 | * @param int $startTime |
||
434 | * @param int|null $endTime null means open end |
||
435 | * |
||
436 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
437 | */ |
||
438 | public function findByTimeSlot($startTime, $endTime = null) |
||
446 | |||
447 | /** |
||
448 | * Find all indices by the given Event model. |
||
449 | * |
||
450 | * @param DomainObjectInterface $event |
||
451 | * |
||
452 | * @throws Exception |
||
453 | * |
||
454 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
||
455 | */ |
||
456 | public function findByEvent(DomainObjectInterface $event) |
||
469 | |||
470 | /** |
||
471 | * Get index language mode. |
||
472 | * |
||
473 | * @return string |
||
474 | */ |
||
475 | protected function getIndexLanguageMode() |
||
491 | |||
492 | /** |
||
493 | * storage page selection. |
||
494 | * |
||
495 | * @return array |
||
496 | */ |
||
497 | protected function getStoragePageIds() |
||
518 | |||
519 | /** |
||
520 | * Get the default constraint for the queries. |
||
521 | * |
||
522 | * @param QueryInterface $query |
||
523 | * |
||
524 | * @return array |
||
525 | */ |
||
526 | protected function getDefaultConstraints(QueryInterface $query) |
||
551 | |||
552 | /** |
||
553 | * Add time frame related queries. |
||
554 | * |
||
555 | * @param array $constraints |
||
556 | * @param QueryInterface $query |
||
557 | * @param int $startTime |
||
558 | * @param int|null $endTime |
||
559 | * |
||
560 | * @see IndexUtility::isIndexInRange |
||
561 | */ |
||
562 | protected function addTimeFrameConstraints(&$constraints, QueryInterface $query, $startTime = null, $endTime = null) |
||
618 | |||
619 | /** |
||
620 | * Get the sorting. |
||
621 | * |
||
622 | * @param string $direction |
||
623 | * @param string $field |
||
624 | * |
||
625 | * @return array |
||
626 | */ |
||
627 | protected function getSorting($direction, $field = '') |
||
645 | } |
||
646 |