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 |
||
| 26 | class Event extends AbstractModel implements FeedInterface, SpeakingUrlInterface, KeSearchIndexInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Title. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | * @DatabaseField("string") |
||
| 33 | */ |
||
| 34 | protected $title; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Abstract / Teaser. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | * @DatabaseField("string") |
||
| 41 | */ |
||
| 42 | protected $abstract; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Description. |
||
| 46 | * |
||
| 47 | * @var string |
||
| 48 | * @DatabaseField("string") |
||
| 49 | * @EnableRichText |
||
| 50 | */ |
||
| 51 | protected $description; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Location. |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | * @DatabaseField("string") |
||
| 58 | */ |
||
| 59 | protected $location; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Location link. |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | * @DatabaseField("string") |
||
| 66 | */ |
||
| 67 | protected $locationLink; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Organizer. |
||
| 71 | * |
||
| 72 | * @var string |
||
| 73 | * @DatabaseField("string") |
||
| 74 | */ |
||
| 75 | protected $organizer; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Organizer link. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | * @DatabaseField("string") |
||
| 82 | */ |
||
| 83 | protected $organizerLink; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Import ID if the item is based on an ICS structure. |
||
| 87 | * |
||
| 88 | * @var string |
||
| 89 | * @DatabaseField("string") |
||
| 90 | */ |
||
| 91 | protected $importId; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Images. |
||
| 95 | * |
||
| 96 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
| 97 | * @DatabaseField("\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>") |
||
| 98 | * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy |
||
| 99 | */ |
||
| 100 | protected $images; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Downloads. |
||
| 104 | * |
||
| 105 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
| 106 | * @DatabaseField("\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>") |
||
| 107 | * @TYPO3\CMS\Extbase\Annotation\ORM\Lazy |
||
| 108 | */ |
||
| 109 | protected $downloads; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Relation field. It is just used by the importer of the default events. |
||
| 113 | * You do not need this field, if you don't use the default Event. |
||
| 114 | * |
||
| 115 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\HDNET\Calendarize\Domain\Model\Configuration> |
||
| 116 | * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove") |
||
| 117 | */ |
||
| 118 | protected $calendarize; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Categories. |
||
| 122 | * |
||
| 123 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> |
||
| 124 | */ |
||
| 125 | protected $categories; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Hidden. |
||
| 129 | * |
||
| 130 | * @var bool |
||
| 131 | */ |
||
| 132 | protected $hidden = false; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Slug. |
||
| 136 | * |
||
| 137 | * @var string |
||
| 138 | * @DatabaseField("string") |
||
| 139 | */ |
||
| 140 | protected $slug = ''; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Build up the object. |
||
| 144 | */ |
||
| 145 | public function __construct() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get title. |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | public function getTitle() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Set title. |
||
| 165 | * |
||
| 166 | * @param string $title |
||
| 167 | */ |
||
| 168 | public function setTitle($title) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Get abstract. |
||
| 175 | * |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | public function getAbstract() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Set abstract. |
||
| 185 | * |
||
| 186 | * @param string $abstract |
||
| 187 | */ |
||
| 188 | public function setAbstract($abstract) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Get description. |
||
| 195 | * |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function getDescription() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Set description. |
||
| 205 | * |
||
| 206 | * @param string $description |
||
| 207 | */ |
||
| 208 | public function setDescription($description) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Get downloads. |
||
| 215 | * |
||
| 216 | * @return ObjectStorage |
||
| 217 | */ |
||
| 218 | public function getDownloads() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set downloads. |
||
| 225 | * |
||
| 226 | * @param ObjectStorage $downloads |
||
| 227 | */ |
||
| 228 | public function setDownloads($downloads) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Get images. |
||
| 235 | * |
||
| 236 | * @return ObjectStorage |
||
| 237 | */ |
||
| 238 | public function getImages() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Set images. |
||
| 245 | * |
||
| 246 | * @param ObjectStorage $images |
||
| 247 | */ |
||
| 248 | public function setImages($images) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Get Import ID. |
||
| 255 | * |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getImportId() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Set import ID. |
||
| 265 | * |
||
| 266 | * @param string $importId |
||
| 267 | */ |
||
| 268 | public function setImportId($importId) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Get calendarize. |
||
| 275 | * |
||
| 276 | * @return ObjectStorage |
||
| 277 | */ |
||
| 278 | public function getCalendarize() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Set calendarize. |
||
| 285 | * |
||
| 286 | * @param ObjectStorage $calendarize |
||
| 287 | */ |
||
| 288 | public function setCalendarize($calendarize) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Add one calendarize configuration. |
||
| 295 | * |
||
| 296 | * @param Configuration $calendarize |
||
| 297 | */ |
||
| 298 | public function addCalendarize($calendarize) |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get the feed title. |
||
| 305 | * |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | public function getFeedTitle(): string |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get the feed abstract. |
||
| 315 | * |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getFeedAbstract(): string |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Get the feed content. |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function getFeedContent(): string |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get the feed location. |
||
| 335 | * |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | public function getFeedLocation(): string |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Get the base for the realurl alias. |
||
| 349 | * |
||
| 350 | * @return string |
||
| 351 | */ |
||
| 352 | public function getRealUrlAliasBase(): string |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Adds a Category. |
||
| 359 | * |
||
| 360 | * @param Category $category |
||
| 361 | */ |
||
| 362 | public function addCategory(Category $category) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Removes a Category. |
||
| 369 | * |
||
| 370 | * @param Category $categoryToRemove The Category to be removed |
||
| 371 | */ |
||
| 372 | public function removeCategory(Category $categoryToRemove) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Returns the categories. |
||
| 379 | * |
||
| 380 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories |
||
| 381 | */ |
||
| 382 | public function getCategories() |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Sets the categories. |
||
| 389 | * |
||
| 390 | * @param ObjectStorage $categories |
||
| 391 | */ |
||
| 392 | public function setCategories(ObjectStorage $categories) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Get the title. |
||
| 399 | * |
||
| 400 | * @param Index $index |
||
| 401 | * |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | public function getKeSearchTitle(Index $index): string |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get the abstract. |
||
| 412 | * |
||
| 413 | * @param Index $index |
||
| 414 | * |
||
| 415 | * @return string |
||
| 416 | */ |
||
| 417 | public function getKeSearchAbstract(Index $index): string |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get the content. |
||
| 424 | * |
||
| 425 | * @param Index $index |
||
| 426 | * |
||
| 427 | * @return string |
||
| 428 | */ |
||
| 429 | public function getKeSearchContent(Index $index): string |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Get the tags. |
||
| 436 | * |
||
| 437 | * @param Index $index |
||
| 438 | * |
||
| 439 | * @return string Comma separated list of tags, e.g. '#syscat1#,#syscat2#' |
||
| 440 | */ |
||
| 441 | public function getKeSearchTags(Index $index): string |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get location. |
||
| 455 | * |
||
| 456 | * @return string |
||
| 457 | */ |
||
| 458 | public function getLocation() |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Set location. |
||
| 465 | * |
||
| 466 | * @param string $location |
||
| 467 | */ |
||
| 468 | public function setLocation($location) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Get orginzer. |
||
| 475 | * |
||
| 476 | * @return string |
||
| 477 | */ |
||
| 478 | public function getOrganizer() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Set organizer. |
||
| 485 | * |
||
| 486 | * @param string $organizer |
||
| 487 | */ |
||
| 488 | public function setOrganizer($organizer) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Is hidden. |
||
| 495 | * |
||
| 496 | * @return bool |
||
| 497 | */ |
||
| 498 | public function isHidden() |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Set hidden. |
||
| 505 | * |
||
| 506 | * @param bool $hidden |
||
| 507 | */ |
||
| 508 | public function setHidden($hidden) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Get location link. |
||
| 515 | * |
||
| 516 | * @return string |
||
| 517 | */ |
||
| 518 | public function getLocationLink() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Set location link. |
||
| 525 | * |
||
| 526 | * @param string $locationLink |
||
| 527 | */ |
||
| 528 | public function setLocationLink($locationLink) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Get organizer link. |
||
| 535 | * |
||
| 536 | * @return string |
||
| 537 | */ |
||
| 538 | public function getOrganizerLink() |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Set organizer link. |
||
| 545 | * |
||
| 546 | * @param string $organizerLink |
||
| 547 | */ |
||
| 548 | public function setOrganizerLink($organizerLink) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @return string |
||
| 555 | */ |
||
| 556 | public function getSlug(): string |
||
| 560 | |||
| 561 | /** |
||
| 562 | * @param string $slug |
||
| 563 | */ |
||
| 564 | public function setSlug(string $slug): void |
||
| 568 | } |
||
| 569 |