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 |
||
27 | class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * Set default sorting |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $defaultOrderings = [ |
||
36 | 'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * Disable the use of storage records, because the StoragePage can be set |
||
41 | * in the plugin |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public function initializeObject() |
||
50 | |||
51 | /** |
||
52 | * Returns the objects of this repository matching the given demand |
||
53 | * |
||
54 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
55 | * |
||
56 | * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
||
57 | */ |
||
58 | public function findDemanded(EventDemand $eventDemand) |
||
80 | |||
81 | /** |
||
82 | * Sets a query limit to the given query for the given demand |
||
83 | * |
||
84 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
85 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
||
98 | |||
99 | /** |
||
100 | * Sets the ordering to the given query for the given demand |
||
101 | * |
||
102 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
103 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
||
117 | |||
118 | /** |
||
119 | * Sets the storagePage constraint to the given constraints array |
||
120 | * |
||
121 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
122 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
123 | * @param array $constraints Constraints |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
||
134 | |||
135 | /** |
||
136 | * Sets the displayMode constraint to the given constraints array |
||
137 | * |
||
138 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
139 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
140 | * @param array $constraints Constraints |
||
141 | * |
||
142 | * @return void |
||
143 | */ |
||
144 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
||
156 | |||
157 | /** |
||
158 | * Sets the category constraint to the given constraints array |
||
159 | * |
||
160 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
161 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
162 | * @param array $constraints Constraints |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
||
184 | |||
185 | /** |
||
186 | * Sets the location constraint to the given constraints array |
||
187 | * |
||
188 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
189 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
190 | * @param array $constraints Constraints |
||
191 | * |
||
192 | * @return void |
||
193 | */ |
||
194 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
||
200 | |||
201 | /** |
||
202 | * Sets the location.city constraint to the given constraints array |
||
203 | * |
||
204 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
205 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
206 | * @param array $constraints Constraints |
||
207 | * |
||
208 | * @return void |
||
209 | */ |
||
210 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
||
216 | |||
217 | /** |
||
218 | * Sets the location.country constraint to the given constraints array |
||
219 | * |
||
220 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
221 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
222 | * @param array $constraints Constraints |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
||
232 | |||
233 | /** |
||
234 | * Sets the start- and enddate constraint to the given constraints array |
||
235 | * |
||
236 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
237 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
238 | * @param array $constraints Constraints |
||
239 | * |
||
240 | * @return void |
||
241 | */ |
||
242 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
||
254 | |||
255 | /** |
||
256 | * Sets the search constraint to the given constraints array |
||
257 | * |
||
258 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
259 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
260 | * @param array $constraints Constraints |
||
261 | * |
||
262 | * @return void |
||
263 | */ |
||
264 | protected function setSearchConstraint($query, $eventDemand, &$constraints) |
||
289 | |||
290 | /** |
||
291 | * Sets the topEvent 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 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
||
305 | |||
306 | } |