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 | 30 | public function initializeObject() |
|
46 | { |
||
47 | 30 | $this->defaultQuerySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings'); |
|
48 | 30 | $this->defaultQuerySettings->setRespectStoragePage(false); |
|
49 | 30 | } |
|
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 | 29 | 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 | 29 | 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 | 29 | 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 | 29 | protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
|
128 | { |
||
129 | 29 | if ($eventDemand->getStoragePage() != '') { |
|
130 | 29 | $pidList = GeneralUtility::intExplode(',', $eventDemand->getStoragePage(), true); |
|
131 | 29 | $constraints[] = $query->in('pid', $pidList); |
|
132 | 29 | } |
|
133 | 29 | } |
|
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 | 29 | protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
|
145 | { |
||
146 | 29 | switch ($eventDemand->getDisplayMode()) { |
|
147 | 29 | case 'future': |
|
148 | 1 | $constraints[] = $query->greaterThan('startdate', $eventDemand->getCurrentDateTime()); |
|
149 | 1 | break; |
|
150 | 28 | case 'past': |
|
151 | 1 | $constraints[] = $query->lessThanOrEqual('enddate', $eventDemand->getCurrentDateTime()); |
|
152 | 1 | break; |
|
153 | 27 | default: |
|
154 | 29 | } |
|
155 | 29 | } |
|
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 | 29 | protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
|
179 | |||
180 | /** |
||
181 | * Sets the location constraint to the given constraints array |
||
182 | * |
||
183 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
184 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
185 | * @param array $constraints Constraints |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | 29 | protected function setLocationConstraint($query, $eventDemand, &$constraints) |
|
195 | |||
196 | /** |
||
197 | * Sets the location.city constraint to the given constraints array |
||
198 | * |
||
199 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
200 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
201 | * @param array $constraints Constraints |
||
202 | * |
||
203 | * @return void |
||
204 | */ |
||
205 | 29 | protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
|
211 | |||
212 | /** |
||
213 | * Sets the location.country constraint to the given constraints array |
||
214 | * |
||
215 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
216 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
217 | * @param array $constraints Constraints |
||
218 | * |
||
219 | * @return void |
||
220 | */ |
||
221 | 29 | protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
|
227 | |||
228 | /** |
||
229 | * Sets the start- and enddate constraint to the given constraints array |
||
230 | * |
||
231 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
232 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
233 | * @param array $constraints Constraints |
||
234 | * |
||
235 | * @return void |
||
236 | */ |
||
237 | 29 | protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
|
249 | |||
250 | /** |
||
251 | * Sets the search constraint to the given constraints array |
||
252 | * |
||
253 | * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
||
254 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
||
255 | * @param array $constraints Constraints |
||
256 | * |
||
257 | * @return void |
||
258 | */ |
||
259 | 29 | protected function setSearchConstraint($query, $eventDemand, &$constraints) |
|
284 | |||
285 | /** |
||
286 | * Sets the topEvent 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 | 29 | protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
|
300 | |||
301 | } |