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 |
||
23 | class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
||
24 | { |
||
25 | /** |
||
26 | * Set default sorting |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $defaultOrderings = [ |
||
31 | 'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * Disable the use of storage records, because the StoragePage can be set |
||
36 | * in the plugin |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | public function initializeObject() |
||
45 | |||
46 | /** |
||
47 | * Returns the objects of this repository matching the given demand |
||
48 | * |
||
49 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
50 | * |
||
51 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
||
52 | */ |
||
53 | public function findDemanded(EventDemand $eventDemand) |
||
90 | |||
91 | /** |
||
92 | * Returns the event with the given UID and also respects the hidden state |
||
93 | * |
||
94 | * @param int $uid |
||
95 | * @return object |
||
96 | */ |
||
97 | public function findByUidIncludeHidden(int $uid) |
||
104 | |||
105 | /** |
||
106 | * Sets a query limit to the given query for the given demand |
||
107 | * |
||
108 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
109 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
110 | * |
||
111 | * @return void |
||
112 | */ |
||
113 | protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
||
122 | |||
123 | /** |
||
124 | * Sets the ordering to the given query for the given demand |
||
125 | * |
||
126 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
127 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
||
143 | |||
144 | /** |
||
145 | * Sets the storagePage constraint to the given constraints array |
||
146 | * |
||
147 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
148 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
149 | * @param array $constraints Constraints |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
||
160 | |||
161 | /** |
||
162 | * Sets the displayMode constraint to the given constraints array |
||
163 | * |
||
164 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
165 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
166 | * @param array $constraints Constraints |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
||
191 | |||
192 | /** |
||
193 | * Sets the category constraint to the given constraints array |
||
194 | * |
||
195 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
196 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
197 | * @param array $constraints Constraints |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
||
224 | |||
225 | /** |
||
226 | * Returns the category constraint depending on the category conjunction configured in eventDemand |
||
227 | * |
||
228 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
229 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
230 | * @param array $categoryConstraints |
||
231 | * @return mixed |
||
232 | */ |
||
233 | public function getCategoryConstraint($query, $eventDemand, $categoryConstraints) |
||
252 | |||
253 | /** |
||
254 | * Sets the location constraint to the given constraints array |
||
255 | * |
||
256 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
257 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
258 | * @param array $constraints Constraints |
||
259 | * |
||
260 | * @return void |
||
261 | */ |
||
262 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
||
268 | |||
269 | /** |
||
270 | * Sets the location.city constraint to the given constraints array |
||
271 | * |
||
272 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
273 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
274 | * @param array $constraints Constraints |
||
275 | * |
||
276 | * @return void |
||
277 | */ |
||
278 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
||
284 | |||
285 | /** |
||
286 | * Sets the location.country constraint to the given constraints array |
||
287 | * |
||
288 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
289 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
290 | * @param array $constraints Constraints |
||
291 | * |
||
292 | * @return void |
||
293 | */ |
||
294 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
||
300 | |||
301 | /** |
||
302 | * Sets the speaker constraint to the given constraints array |
||
303 | * |
||
304 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
305 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
306 | * @param array $constraints Constraints |
||
307 | * |
||
308 | * @return void |
||
309 | */ |
||
310 | protected function setSpeakerConstraint($query, $eventDemand, &$constraints) |
||
316 | |||
317 | /** |
||
318 | * Sets the organisator 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 setOrganisatorConstraint($query, $eventDemand, &$constraints) |
||
332 | |||
333 | /** |
||
334 | * Sets the start- and enddate constraint to the given constraints array |
||
335 | * |
||
336 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
337 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
338 | * @param array $constraints Constraints |
||
339 | * |
||
340 | * @return void |
||
341 | */ |
||
342 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
||
366 | |||
367 | /** |
||
368 | * Sets the search constraint to the given constraints array |
||
369 | * |
||
370 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
371 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
372 | * @param array $constraints Constraints |
||
373 | * |
||
374 | * @return void |
||
375 | */ |
||
376 | protected function setSearchConstraint($query, $eventDemand, &$constraints) |
||
401 | |||
402 | /** |
||
403 | * Sets the topEvent constraint to the given constraints array |
||
404 | * |
||
405 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
406 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
407 | * @param array $constraints Constraints |
||
408 | * |
||
409 | * @return void |
||
410 | */ |
||
411 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
||
417 | |||
418 | /** |
||
419 | * Sets the restriction for year, year/month or year/month/day to the given constraints array |
||
420 | * |
||
421 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
||
422 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
||
423 | * @param array $constraints |
||
424 | * |
||
425 | * @return void |
||
426 | */ |
||
427 | protected function setYearMonthDayRestriction($query, $eventDemand, &$constraints) |
||
452 | } |
||
453 |