Complex classes like Event 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 Event, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class Event extends AbstractModel implements FeedInterface, SpeakingUrlInterface, KeSearchIndexInterface |
||
23 | { |
||
24 | /** |
||
25 | * Title. |
||
26 | * |
||
27 | * @var string |
||
28 | * @db |
||
29 | */ |
||
30 | protected $title; |
||
31 | |||
32 | /** |
||
33 | * Abstract / Teaser. |
||
34 | * |
||
35 | * @var string |
||
36 | * @db |
||
37 | */ |
||
38 | protected $abstract; |
||
39 | |||
40 | /** |
||
41 | * Description. |
||
42 | * |
||
43 | * @var string |
||
44 | * @db |
||
45 | * @enableRichText |
||
46 | */ |
||
47 | protected $description; |
||
48 | |||
49 | /** |
||
50 | * Location. |
||
51 | * |
||
52 | * @var string |
||
53 | * @db |
||
54 | */ |
||
55 | protected $location; |
||
56 | |||
57 | /** |
||
58 | * Location link. |
||
59 | * |
||
60 | * @var string |
||
61 | * @db |
||
62 | */ |
||
63 | protected $locationLink; |
||
64 | |||
65 | /** |
||
66 | * Organizer. |
||
67 | * |
||
68 | * @var string |
||
69 | * @db |
||
70 | */ |
||
71 | protected $organizer; |
||
72 | |||
73 | /** |
||
74 | * Organizer link. |
||
75 | * |
||
76 | * @var string |
||
77 | * @db |
||
78 | */ |
||
79 | protected $organizerLink; |
||
80 | |||
81 | /** |
||
82 | * Import ID if the item is based on an ICS structure. |
||
83 | * |
||
84 | * @var string |
||
85 | * @db |
||
86 | */ |
||
87 | protected $importId; |
||
88 | |||
89 | /** |
||
90 | * Images. |
||
91 | * |
||
92 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
93 | * @db |
||
94 | */ |
||
95 | protected $images; |
||
96 | |||
97 | /** |
||
98 | * Downloads. |
||
99 | * |
||
100 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
101 | * @db |
||
102 | */ |
||
103 | protected $downloads; |
||
104 | |||
105 | /** |
||
106 | * Relation field. It is just used by the importer of the default events. |
||
107 | * You do not need this field, if you don't use the default Event. |
||
108 | * |
||
109 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\HDNET\Calendarize\Domain\Model\Configuration> |
||
110 | */ |
||
111 | protected $calendarize; |
||
112 | |||
113 | /** |
||
114 | * Categories. |
||
115 | * |
||
116 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> |
||
117 | */ |
||
118 | protected $categories; |
||
119 | |||
120 | /** |
||
121 | * @var bool |
||
122 | */ |
||
123 | protected $hidden = false; |
||
124 | |||
125 | /** |
||
126 | * Build up the object. |
||
127 | */ |
||
128 | public function __construct() |
||
135 | |||
136 | /** |
||
137 | * Get title. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getTitle() |
||
145 | |||
146 | /** |
||
147 | * Set title. |
||
148 | * |
||
149 | * @param string $title |
||
150 | */ |
||
151 | public function setTitle($title) |
||
155 | |||
156 | /** |
||
157 | * Get abstract. |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getAbstract() |
||
165 | |||
166 | /** |
||
167 | * Set abstract. |
||
168 | * |
||
169 | * @param string $abstract |
||
170 | */ |
||
171 | public function setAbstract($abstract) |
||
175 | |||
176 | /** |
||
177 | * Get description. |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function getDescription() |
||
185 | |||
186 | /** |
||
187 | * Set description. |
||
188 | * |
||
189 | * @param string $description |
||
190 | */ |
||
191 | public function setDescription($description) |
||
195 | |||
196 | /** |
||
197 | * Get downloads. |
||
198 | * |
||
199 | * @return ObjectStorage |
||
200 | */ |
||
201 | public function getDownloads() |
||
205 | |||
206 | /** |
||
207 | * Set downloads. |
||
208 | * |
||
209 | * @param ObjectStorage $downloads |
||
210 | */ |
||
211 | public function setDownloads($downloads) |
||
215 | |||
216 | /** |
||
217 | * Get images. |
||
218 | * |
||
219 | * @return ObjectStorage |
||
220 | */ |
||
221 | public function getImages() |
||
225 | |||
226 | /** |
||
227 | * Set images. |
||
228 | * |
||
229 | * @param ObjectStorage $images |
||
230 | */ |
||
231 | public function setImages($images) |
||
235 | |||
236 | /** |
||
237 | * Get Import ID. |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | public function getImportId() |
||
245 | |||
246 | /** |
||
247 | * Set import ID. |
||
248 | * |
||
249 | * @param string $importId |
||
250 | */ |
||
251 | public function setImportId($importId) |
||
255 | |||
256 | /** |
||
257 | * Get calendarize. |
||
258 | * |
||
259 | * @return ObjectStorage |
||
260 | */ |
||
261 | public function getCalendarize() |
||
265 | |||
266 | /** |
||
267 | * Set calendarize. |
||
268 | * |
||
269 | * @param ObjectStorage $calendarize |
||
270 | */ |
||
271 | public function setCalendarize($calendarize) |
||
275 | |||
276 | /** |
||
277 | * Add one calendarize configuration. |
||
278 | * |
||
279 | * @param Configuration $calendarize |
||
280 | */ |
||
281 | public function addCalendarize($calendarize) |
||
285 | |||
286 | /** |
||
287 | * Get the feed title. |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | public function getFeedTitle(): string |
||
295 | |||
296 | /** |
||
297 | * Get the feed abstract. |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | public function getFeedAbstract(): string |
||
305 | |||
306 | /** |
||
307 | * Get the feed content. |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | public function getFeedContent(): string |
||
315 | |||
316 | /** |
||
317 | * Get the feed location. |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getFeedLocation(): string |
||
325 | |||
326 | /** |
||
327 | * Get the base for the realurl alias. |
||
328 | * |
||
329 | * @return string |
||
330 | */ |
||
331 | public function getRealUrlAliasBase(): string |
||
335 | |||
336 | /** |
||
337 | * Adds a Category. |
||
338 | * |
||
339 | * @param Category $category |
||
340 | */ |
||
341 | public function addCategory(Category $category) |
||
345 | |||
346 | /** |
||
347 | * Removes a Category. |
||
348 | * |
||
349 | * @param Category $categoryToRemove The Category to be removed |
||
350 | */ |
||
351 | public function removeCategory(Category $categoryToRemove) |
||
355 | |||
356 | /** |
||
357 | * Returns the categories. |
||
358 | * |
||
359 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories |
||
360 | */ |
||
361 | public function getCategories() |
||
365 | |||
366 | /** |
||
367 | * Sets the categories. |
||
368 | * |
||
369 | * @param ObjectStorage $categories |
||
370 | */ |
||
371 | public function setCategories(ObjectStorage $categories) |
||
375 | |||
376 | /** |
||
377 | * Get the title. |
||
378 | * |
||
379 | * @param Index $index |
||
380 | * |
||
381 | * @return string |
||
382 | */ |
||
383 | public function getKeSearchTitle(Index $index): string |
||
388 | |||
389 | /** |
||
390 | * Get the abstract. |
||
391 | * |
||
392 | * @param Index $index |
||
393 | * |
||
394 | * @return string |
||
395 | */ |
||
396 | public function getKeSearchAbstract(Index $index): string |
||
400 | |||
401 | /** |
||
402 | * Get the content. |
||
403 | * |
||
404 | * @param Index $index |
||
405 | * |
||
406 | * @return string |
||
407 | */ |
||
408 | public function getKeSearchContent(Index $index): string |
||
412 | |||
413 | /** |
||
414 | * Get the tags. |
||
415 | * |
||
416 | * @param Index $index |
||
417 | * |
||
418 | * @return string Comma separated list of tags, e.g. '#syscat1#,#syscat2#' |
||
419 | */ |
||
420 | public function getKeSearchTags(Index $index): string |
||
431 | |||
432 | /** |
||
433 | * Get location. |
||
434 | * |
||
435 | * @return string |
||
436 | */ |
||
437 | public function getLocation() |
||
441 | |||
442 | /** |
||
443 | * Set location. |
||
444 | * |
||
445 | * @param string $location |
||
446 | */ |
||
447 | public function setLocation($location) |
||
451 | |||
452 | /** |
||
453 | * Get orginzer. |
||
454 | * |
||
455 | * @return string |
||
456 | */ |
||
457 | public function getOrganizer() |
||
461 | |||
462 | /** |
||
463 | * Set organizer. |
||
464 | * |
||
465 | * @param string $organizer |
||
466 | */ |
||
467 | public function setOrganizer($organizer) |
||
471 | |||
472 | /** |
||
473 | * @return bool |
||
474 | */ |
||
475 | public function isHidden() |
||
479 | |||
480 | /** |
||
481 | * @param bool $hidden |
||
482 | */ |
||
483 | public function setHidden($hidden) |
||
487 | |||
488 | /** |
||
489 | * @return string |
||
490 | */ |
||
491 | public function getLocationLink() |
||
495 | |||
496 | /** |
||
497 | * @param string $locationLink |
||
498 | */ |
||
499 | public function setLocationLink($locationLink) |
||
503 | |||
504 | /** |
||
505 | * @return string |
||
506 | */ |
||
507 | public function getOrganizerLink() |
||
511 | |||
512 | /** |
||
513 | * @param string $organizerLink |
||
514 | */ |
||
515 | public function setOrganizerLink($organizerLink) |
||
519 | |||
520 | |||
521 | } |
||
522 |