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 |
||
22 | class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
||
23 | { |
||
24 | /** |
||
25 | * Set default sorting |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $defaultOrderings = [ |
||
30 | 'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Disable the use of storage records, because the StoragePage can be set |
||
35 | * in the plugin |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | public function initializeObject() |
||
44 | |||
45 | 31 | /** |
|
46 | * Returns the objects of this repository matching the given demand |
||
47 | 31 | * |
|
48 | 31 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
49 | 31 | * |
|
50 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
||
51 | */ |
||
52 | public function findDemanded(EventDemand $eventDemand) |
||
77 | 30 | ||
78 | 30 | /** |
|
79 | * Sets a query limit to the given query for the given demand |
||
80 | * |
||
81 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
82 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
||
95 | 1 | ||
96 | 1 | /** |
|
97 | 30 | * Sets the ordering to the given query for the given demand |
|
98 | * |
||
99 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
100 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
||
116 | 30 | ||
117 | /** |
||
118 | * Sets the storagePage constraint to the given constraints array |
||
119 | * |
||
120 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
121 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
122 | * @param array $constraints Constraints |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
||
133 | 30 | ||
134 | /** |
||
135 | * Sets the displayMode constraint to the given constraints array |
||
136 | * |
||
137 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
138 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
139 | * @param array $constraints Constraints |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
||
164 | |||
165 | /** |
||
166 | 30 | * Sets the category constraint to the given constraints array |
|
167 | * |
||
168 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
169 | 5 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
170 | 5 | * @param array $constraints Constraints |
|
171 | 1 | * |
|
172 | 1 | * @return void |
|
173 | 1 | */ |
|
174 | 4 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
|
197 | 3 | ||
198 | 3 | /** |
|
199 | 30 | * Returns the category constraint depending on the category conjunction configured in eventDemand |
|
200 | * |
||
201 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
202 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
203 | * @param array $categoryConstraints |
||
204 | * @return mixed |
||
205 | */ |
||
206 | public function getCategoryConstraint($query, $eventDemand, $categoryConstraints) |
||
225 | |||
226 | 30 | /** |
|
227 | * Sets the location constraint to the given constraints array |
||
228 | 30 | * |
|
229 | 2 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
230 | 2 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
231 | 30 | * @param array $constraints Constraints |
|
232 | * |
||
233 | * @return void |
||
234 | */ |
||
235 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
||
241 | |||
242 | 30 | /** |
|
243 | * Sets the location.city constraint to the given constraints array |
||
244 | * |
||
245 | 30 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
246 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
247 | 1 | * @param array $constraints Constraints |
|
248 | * |
||
249 | * @return void |
||
250 | 30 | */ |
|
251 | 1 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
|
257 | |||
258 | /** |
||
259 | * Sets the location.country constraint to the given constraints array |
||
260 | * |
||
261 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
262 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
263 | * @param array $constraints Constraints |
||
264 | 30 | * |
|
265 | * @return void |
||
266 | 30 | */ |
|
267 | 30 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
|
273 | 1 | ||
274 | /** |
||
275 | * Sets the organisator constraint to the given constraints array |
||
276 | * |
||
277 | 1 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
|
278 | 1 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
|
279 | 1 | * @param array $constraints Constraints |
|
280 | 1 | * |
|
281 | 1 | * @return void |
|
282 | 1 | */ |
|
283 | protected function setOrganisatorConstraint($query, $eventDemand, &$constraints) |
||
289 | |||
290 | /** |
||
291 | * Sets the start- and enddate constraint to the given constraints array |
||
292 | * |
||
293 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
294 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
295 | * @param array $constraints Constraints |
||
296 | * |
||
297 | * @return void |
||
298 | */ |
||
299 | 30 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
|
311 | |||
312 | /** |
||
313 | * Sets the search constraint to the given constraints array |
||
314 | * |
||
315 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
316 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
317 | * @param array $constraints Constraints |
||
318 | * |
||
319 | * @return void |
||
320 | */ |
||
321 | protected function setSearchConstraint($query, $eventDemand, &$constraints) |
||
346 | |||
347 | /** |
||
348 | * Sets the topEvent constraint to the given constraints array |
||
349 | * |
||
350 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
351 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
352 | * @param array $constraints Constraints |
||
353 | * |
||
354 | * @return void |
||
355 | */ |
||
356 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
||
362 | |||
363 | /** |
||
364 | * Sets the restriction for year, year/month or year/month/day to the given constraints array |
||
365 | * |
||
366 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
367 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
368 | * @param array $constraints |
||
369 | * |
||
370 | * @return void |
||
371 | */ |
||
372 | protected function setYearMonthDayRestriction($query, $eventDemand, &$constraints) |
||
397 | } |
||
398 |