Complex classes like EventDemand 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 EventDemand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class EventDemand extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity |
||
18 | { |
||
19 | /** |
||
20 | * Display mode |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $displayMode = 'all'; |
||
25 | |||
26 | /** |
||
27 | * Storage page |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $storagePage = ''; |
||
32 | |||
33 | /** |
||
34 | * Current DateTime |
||
35 | * |
||
36 | * @var \DateTime |
||
37 | */ |
||
38 | protected $currentDateTime; |
||
39 | |||
40 | /** |
||
41 | * Category |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $category; |
||
46 | |||
47 | /** |
||
48 | * Include subcategories |
||
49 | * |
||
50 | * @var bool |
||
51 | */ |
||
52 | protected $includeSubcategories = false; |
||
53 | |||
54 | /** |
||
55 | * Category Conjunction |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $categoryConjunction = ''; |
||
60 | |||
61 | /** |
||
62 | * Top event |
||
63 | * |
||
64 | * @var int |
||
65 | */ |
||
66 | protected $topEventRestriction = 0; |
||
67 | |||
68 | /** |
||
69 | * Order field |
||
70 | * |
||
71 | * @var string |
||
72 | */ |
||
73 | protected $orderField = ''; |
||
74 | |||
75 | /** |
||
76 | * Allowed order fields |
||
77 | * |
||
78 | * @var string |
||
79 | */ |
||
80 | protected $orderFieldAllowed = ''; |
||
81 | |||
82 | /** |
||
83 | * Order direction |
||
84 | * |
||
85 | * @var string |
||
86 | */ |
||
87 | protected $orderDirection = ''; |
||
88 | |||
89 | /** |
||
90 | * Query limit |
||
91 | * |
||
92 | * @var int |
||
93 | */ |
||
94 | protected $queryLimit; |
||
95 | |||
96 | /** |
||
97 | * Location |
||
98 | * |
||
99 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Location |
||
100 | */ |
||
101 | protected $location; |
||
102 | |||
103 | /** |
||
104 | * Speaker |
||
105 | * |
||
106 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Speaker |
||
107 | */ |
||
108 | protected $speaker; |
||
109 | |||
110 | /** |
||
111 | * City for location |
||
112 | * |
||
113 | * @var string |
||
114 | */ |
||
115 | protected $locationCity = ''; |
||
116 | |||
117 | /** |
||
118 | * Country for location |
||
119 | * |
||
120 | * @var string |
||
121 | */ |
||
122 | protected $locationCountry = ''; |
||
123 | |||
124 | /** |
||
125 | * Year |
||
126 | * |
||
127 | * @var int |
||
128 | */ |
||
129 | protected $year; |
||
130 | 13 | ||
131 | /** |
||
132 | 13 | * Month |
|
133 | 13 | * |
|
134 | * @var int |
||
135 | */ |
||
136 | protected $month; |
||
137 | |||
138 | /** |
||
139 | * Day |
||
140 | 32 | * |
|
141 | * @var int |
||
142 | 32 | */ |
|
143 | protected $day; |
||
144 | |||
145 | /** |
||
146 | * Search Demand |
||
147 | * |
||
148 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand |
||
149 | */ |
||
150 | protected $searchDemand; |
||
151 | |||
152 | 34 | /** |
|
153 | * Organisator |
||
154 | 34 | * |
|
155 | 34 | * @var \DERHANSEN\SfEventMgt\Domain\Model\Organisator |
|
156 | */ |
||
157 | protected $organisator; |
||
158 | |||
159 | /** |
||
160 | * @var bool |
||
161 | */ |
||
162 | 34 | protected $ignoreEnableFields = false; |
|
163 | |||
164 | 34 | /** |
|
165 | * Sets the displayMode |
||
166 | * |
||
167 | * @param string $displayMode Displaymode |
||
168 | */ |
||
169 | public function setDisplayMode($displayMode) |
||
170 | { |
||
171 | $this->displayMode = $displayMode; |
||
172 | } |
||
173 | |||
174 | 4 | /** |
|
175 | * Returns the displayMode |
||
176 | 4 | * |
|
177 | 4 | * @return string |
|
178 | */ |
||
179 | public function getDisplayMode() |
||
180 | { |
||
181 | return $this->displayMode; |
||
182 | } |
||
183 | |||
184 | 6 | /** |
|
185 | * Sets the storage page |
||
186 | 6 | * |
|
187 | 4 | * @param string $storagePage Storagepage |
|
188 | */ |
||
189 | 2 | public function setStoragePage($storagePage) |
|
190 | { |
||
191 | $this->storagePage = $storagePage; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Returns the storage page |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | 11 | public function getStoragePage() |
|
200 | { |
||
201 | 11 | return $this->storagePage; |
|
202 | 11 | } |
|
203 | |||
204 | /** |
||
205 | * Sets the current DateTime |
||
206 | * |
||
207 | * @param \DateTime $currentDateTime CurrentDateTime |
||
208 | */ |
||
209 | 34 | public function setCurrentDateTime(\DateTime $currentDateTime) |
|
213 | |||
214 | /** |
||
215 | * Returns the current datetime |
||
216 | * |
||
217 | * @return \DateTime |
||
218 | */ |
||
219 | 7 | public function getCurrentDateTime() |
|
227 | |||
228 | /** |
||
229 | * Sets the category (seperated by comma) |
||
230 | 5 | * |
|
231 | * @param string $category Category |
||
232 | 5 | */ |
|
233 | 5 | public function setCategory($category) |
|
237 | |||
238 | /** |
||
239 | * Returns the category (seperated by comma) |
||
240 | 34 | * |
|
241 | * @return string |
||
242 | 34 | */ |
|
243 | public function getCategory() |
||
247 | |||
248 | /** |
||
249 | * Returns includeSubcategories |
||
250 | * |
||
251 | * @return bool |
||
252 | 5 | */ |
|
253 | public function getIncludeSubcategories() |
||
257 | |||
258 | /** |
||
259 | * Sets includeSubcategories |
||
260 | * |
||
261 | * @param bool $includeSubcategories |
||
262 | 10 | */ |
|
263 | public function setIncludeSubcategories($includeSubcategories) |
||
267 | |||
268 | /** |
||
269 | * Returns topEventRestriction |
||
270 | * |
||
271 | * @return int |
||
272 | */ |
||
273 | public function getTopEventRestriction() |
||
277 | 9 | ||
278 | /** |
||
279 | * Sets topEventRestriction |
||
280 | * |
||
281 | * @param int $topEventRestriction TopEventRestriction |
||
282 | */ |
||
283 | public function setTopEventRestriction($topEventRestriction) |
||
287 | |||
288 | /** |
||
289 | * Returns the order direction |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | public function getOrderDirection() |
||
297 | |||
298 | 9 | /** |
|
299 | 9 | * Sets the order direction |
|
300 | * |
||
301 | * @param string $orderDirection OrderDirection |
||
302 | */ |
||
303 | public function setOrderDirection($orderDirection) |
||
307 | |||
308 | 30 | /** |
|
309 | * Returns the order field |
||
310 | * |
||
311 | * @return string |
||
312 | */ |
||
313 | public function getOrderField() |
||
317 | |||
318 | /** |
||
319 | * Sets the order field |
||
320 | * |
||
321 | * @param string $orderField OrderField |
||
322 | */ |
||
323 | public function setOrderField($orderField) |
||
327 | 34 | ||
328 | /** |
||
329 | 34 | * Returns orderFieldAllowed |
|
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | public function getOrderFieldAllowed() |
||
337 | |||
338 | /** |
||
339 | 3 | * Sets orderFieldAllowed |
|
340 | * |
||
341 | 3 | * @param string $orderFieldAllowed |
|
342 | 3 | */ |
|
343 | public function setOrderFieldAllowed($orderFieldAllowed) |
||
347 | |||
348 | /** |
||
349 | 34 | * Returns the query limit |
|
350 | * |
||
351 | 34 | * @return int |
|
352 | */ |
||
353 | public function getQueryLimit() |
||
357 | |||
358 | /** |
||
359 | * Sets the query limit |
||
360 | * |
||
361 | 5 | * @param int $queryLimit QueryLimit |
|
362 | */ |
||
363 | 5 | public function setQueryLimit($queryLimit) |
|
367 | |||
368 | /** |
||
369 | * Returns the location |
||
370 | * |
||
371 | 34 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Location |
|
372 | */ |
||
373 | 34 | public function getLocation() |
|
377 | |||
378 | /** |
||
379 | * Sets the location |
||
380 | * |
||
381 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Location $location Location |
||
382 | */ |
||
383 | 4 | public function setLocation($location) |
|
387 | |||
388 | /** |
||
389 | * Returns locationCity |
||
390 | * |
||
391 | * @return string |
||
392 | */ |
||
393 | 34 | public function getLocationCity() |
|
397 | |||
398 | /** |
||
399 | * Sets locationCity |
||
400 | * |
||
401 | * @param string $locationCity LocationCity |
||
402 | */ |
||
403 | public function setLocationCity($locationCity) |
||
407 | 4 | ||
408 | 4 | /** |
|
409 | * Returns locationCountry |
||
410 | * |
||
411 | * @return string |
||
412 | */ |
||
413 | public function getLocationCountry() |
||
417 | 30 | ||
418 | /** |
||
419 | * Sets locationCountry |
||
420 | * |
||
421 | * @param string $locationCountry LocationCountry |
||
422 | */ |
||
423 | public function setLocationCountry($locationCountry) |
||
427 | |||
428 | 5 | /** |
|
429 | 5 | * Returns year |
|
430 | * |
||
431 | * @return int |
||
432 | */ |
||
433 | public function getYear() |
||
437 | |||
438 | /** |
||
439 | * Sets year |
||
440 | * |
||
441 | * @param int $year |
||
442 | */ |
||
443 | public function setYear($year) |
||
447 | |||
448 | /** |
||
449 | * Returns month |
||
450 | * |
||
451 | * @return int |
||
452 | */ |
||
453 | public function getMonth() |
||
457 | |||
458 | /** |
||
459 | * Sets month |
||
460 | * |
||
461 | * @param int $month |
||
462 | */ |
||
463 | public function setMonth($month) |
||
467 | |||
468 | /** |
||
469 | * Returns day |
||
470 | * |
||
471 | * @return int |
||
472 | */ |
||
473 | public function getDay() |
||
477 | |||
478 | /** |
||
479 | * @param int $day |
||
480 | */ |
||
481 | public function setDay($day) |
||
485 | |||
486 | /** |
||
487 | * Returns the searchDemand |
||
488 | * |
||
489 | * @return SearchDemand |
||
490 | */ |
||
491 | public function getSearchDemand() |
||
495 | |||
496 | /** |
||
497 | * Sets the searchDemand |
||
498 | * |
||
499 | * @param SearchDemand $searchDemand |
||
500 | */ |
||
501 | public function setSearchDemand($searchDemand) |
||
505 | |||
506 | /** |
||
507 | * Returns organisator |
||
508 | * |
||
509 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Organisator |
||
510 | */ |
||
511 | public function getOrganisator() |
||
515 | |||
516 | /** |
||
517 | * Sets organisator |
||
518 | * |
||
519 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Organisator $organisator |
||
520 | */ |
||
521 | public function setOrganisator($organisator) |
||
525 | |||
526 | /** |
||
527 | * Returns categoryConjuction |
||
528 | * |
||
529 | * @return string |
||
530 | */ |
||
531 | public function getCategoryConjunction() |
||
535 | |||
536 | /** |
||
537 | * Sets categoryConjuction |
||
538 | * |
||
539 | * @param string $categoryConjunction |
||
540 | */ |
||
541 | public function setCategoryConjunction($categoryConjunction) |
||
545 | |||
546 | /** |
||
547 | * Returns speaker |
||
548 | * |
||
549 | * @return \DERHANSEN\SfEventMgt\Domain\Model\Speaker |
||
550 | */ |
||
551 | public function getSpeaker() |
||
555 | |||
556 | /** |
||
557 | * Sets speaker |
||
558 | * |
||
559 | * @param \DERHANSEN\SfEventMgt\Domain\Model\Speaker $speaker |
||
560 | */ |
||
561 | public function setSpeaker($speaker) |
||
565 | |||
566 | /** |
||
567 | * @return bool |
||
568 | */ |
||
569 | public function getIgnoreEnableFields(): bool |
||
573 | |||
574 | /** |
||
575 | * @param bool $ignoreEnableFields |
||
576 | */ |
||
577 | public function setIgnoreEnableFields(bool $ignoreEnableFields): void |
||
581 | } |
||
582 |