Complex classes like Banner 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 Banner, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Banner extends AbstractEntity |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Title |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $title; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Description |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $description; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Type |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $type; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Category |
||
| 46 | * |
||
| 47 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category> |
||
| 48 | * @Extbase\ORM\Lazy |
||
| 49 | */ |
||
| 50 | protected $category; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Fal media items |
||
| 54 | * |
||
| 55 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
| 56 | */ |
||
| 57 | protected $assets; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Margin top |
||
| 61 | * |
||
| 62 | * @var int |
||
| 63 | */ |
||
| 64 | protected $marginTop; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Margin right |
||
| 68 | * |
||
| 69 | * @var int |
||
| 70 | */ |
||
| 71 | protected $marginRight; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Margin bottom |
||
| 75 | * |
||
| 76 | * @var int |
||
| 77 | */ |
||
| 78 | protected $marginBottom; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Margin top |
||
| 82 | * |
||
| 83 | * @var int |
||
| 84 | */ |
||
| 85 | protected $marginLeft; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * HTML |
||
| 89 | * |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $html; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Max impressions |
||
| 96 | * |
||
| 97 | * @var int |
||
| 98 | */ |
||
| 99 | protected $impressionsMax; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Max clicks |
||
| 103 | * |
||
| 104 | * @var int |
||
| 105 | */ |
||
| 106 | protected $clicksMax; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Total impressions |
||
| 110 | * |
||
| 111 | * @var int |
||
| 112 | */ |
||
| 113 | protected $impressions; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Total clicks |
||
| 117 | * |
||
| 118 | * @var int |
||
| 119 | */ |
||
| 120 | protected $clicks; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Do not display on pages |
||
| 124 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfBanners\Domain\Model\Page> |
||
| 125 | * @Extbase\ORM\Lazy |
||
| 126 | */ |
||
| 127 | protected $excludepages; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Recursively use excludepages |
||
| 131 | * @var bool |
||
| 132 | */ |
||
| 133 | protected $recursive; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * __construct |
||
| 137 | */ |
||
| 138 | public function __construct() |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Initializes all ObjectStorage properties |
||
| 146 | * Do not modify this method! |
||
| 147 | * It will be rewritten on each save in the extension builder |
||
| 148 | * You may modify the constructor of this class instead |
||
| 149 | * |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | protected function initStorageObjects() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Returns the title |
||
| 161 | * |
||
| 162 | * @return string $title |
||
| 163 | */ |
||
| 164 | public function getTitle() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Sets the title |
||
| 171 | * |
||
| 172 | * @param string $title The title |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | public function setTitle($title) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Returns the description |
||
| 182 | * |
||
| 183 | * @return string $description |
||
| 184 | */ |
||
| 185 | public function getDescription() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Sets the description |
||
| 192 | * |
||
| 193 | * @param string $description The description |
||
| 194 | * @return void |
||
| 195 | */ |
||
| 196 | public function setDescription($description) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Returns the type |
||
| 203 | * |
||
| 204 | * @return int $type |
||
| 205 | */ |
||
| 206 | public function getType() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Sets the type |
||
| 213 | * |
||
| 214 | * @param int $type The type |
||
| 215 | * @return void |
||
| 216 | */ |
||
| 217 | public function setType($type) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Adds a category |
||
| 224 | * |
||
| 225 | * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category |
||
| 226 | * @return void |
||
| 227 | */ |
||
| 228 | public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Removes a category |
||
| 235 | * |
||
| 236 | * @param \TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove |
||
| 237 | * @return void |
||
| 238 | */ |
||
| 239 | public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $categoryToRemove) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Returns the category |
||
| 246 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category |
||
| 247 | */ |
||
| 248 | public function getCategory() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Sets the category |
||
| 255 | * |
||
| 256 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category One or multiple categories |
||
| 257 | * @return void |
||
| 258 | */ |
||
| 259 | public function setCategory($category) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Setter for clicks |
||
| 266 | * |
||
| 267 | * @param int $clicks Clicks |
||
| 268 | * @return void |
||
| 269 | */ |
||
| 270 | public function setClicks($clicks) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * getter for clicks |
||
| 277 | * |
||
| 278 | * @return int |
||
| 279 | */ |
||
| 280 | public function getClicks() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Setter for clicksmax |
||
| 287 | * |
||
| 288 | * @param int $clicksMax MaxClicks |
||
| 289 | * @return void |
||
| 290 | */ |
||
| 291 | public function setClicksMax($clicksMax) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Getter for clicksmax |
||
| 298 | * |
||
| 299 | * @return int |
||
| 300 | */ |
||
| 301 | public function getClicksMax() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Adds a page |
||
| 308 | * |
||
| 309 | * @param \DERHANSEN\SfBanners\Domain\Model\Page $page |
||
| 310 | * @return void |
||
| 311 | */ |
||
| 312 | public function addExcludepages(\DERHANSEN\SfBanners\Domain\Model\Page $page) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Removes a page |
||
| 319 | * |
||
| 320 | * @param \DERHANSEN\SfBanners\Domain\Model\page $pageToRemove |
||
| 321 | * @return void |
||
| 322 | */ |
||
| 323 | public function removeExcludepages(\DERHANSEN\SfBanners\Domain\Model\page $pageToRemove) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Setter for excludepages |
||
| 330 | * |
||
| 331 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $excludepages Excludepages |
||
| 332 | * @return void |
||
| 333 | */ |
||
| 334 | public function setExcludepages($excludepages) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Getter for excludepages |
||
| 341 | * |
||
| 342 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage |
||
| 343 | */ |
||
| 344 | public function getExcludepages() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Setter for HTML |
||
| 351 | * |
||
| 352 | * @param string $html HTML |
||
| 353 | * @return void |
||
| 354 | */ |
||
| 355 | public function setHtml($html) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Getter for HTML |
||
| 362 | * |
||
| 363 | * @return string |
||
| 364 | */ |
||
| 365 | public function getHtml() |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Setter for impressions |
||
| 372 | * |
||
| 373 | * @param int $impressions Impressions |
||
| 374 | * @return void |
||
| 375 | */ |
||
| 376 | public function setImpressions($impressions) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Getter for impressions |
||
| 383 | * |
||
| 384 | * @return int |
||
| 385 | */ |
||
| 386 | public function getImpressions() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Setter for max impressions |
||
| 393 | * |
||
| 394 | * @param int $impressionsMax Max impressions |
||
| 395 | * @return void |
||
| 396 | */ |
||
| 397 | public function setImpressionsMax($impressionsMax) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Getter for max impressions |
||
| 404 | * |
||
| 405 | * @return int |
||
| 406 | */ |
||
| 407 | public function getImpressionsMax() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Getter for link |
||
| 414 | * |
||
| 415 | * @return string |
||
| 416 | */ |
||
| 417 | public function getLink() |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Setter for margin bottom |
||
| 435 | * |
||
| 436 | * @param int $marginBottom Margin bottom |
||
| 437 | * @return void |
||
| 438 | */ |
||
| 439 | public function setMarginBottom($marginBottom) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Getter for margin bottom |
||
| 446 | * |
||
| 447 | * @return int |
||
| 448 | */ |
||
| 449 | public function getMarginBottom() |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Setter for margin left |
||
| 456 | * |
||
| 457 | * @param int $marginLeft Margin left |
||
| 458 | * @return void |
||
| 459 | */ |
||
| 460 | public function setMarginLeft($marginLeft) |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Getter for margin left |
||
| 467 | * |
||
| 468 | * @return int |
||
| 469 | */ |
||
| 470 | public function getMarginLeft() |
||
| 474 | 8 | ||
| 475 | /** |
||
| 476 | * Setter for margin right |
||
| 477 | * |
||
| 478 | * @param int $marginRight Margin right |
||
| 479 | * @return void |
||
| 480 | */ |
||
| 481 | public function setMarginRight($marginRight) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Getter for margin right |
||
| 488 | * |
||
| 489 | * @return int |
||
| 490 | */ |
||
| 491 | public function getMarginRight() |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Setter for margin top |
||
| 498 | * |
||
| 499 | * @param int $marginTop Margin top |
||
| 500 | * @return void |
||
| 501 | */ |
||
| 502 | public function setMarginTop($marginTop) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Getter for margin top |
||
| 509 | * |
||
| 510 | * @return int |
||
| 511 | */ |
||
| 512 | public function getMarginTop() |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Sets the recursive flag |
||
| 519 | * |
||
| 520 | * @param bool $recursive |
||
| 521 | * @return void |
||
| 522 | */ |
||
| 523 | public function setRecursive($recursive) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Returns the recursive flag |
||
| 530 | * |
||
| 531 | * @return bool |
||
| 532 | */ |
||
| 533 | public function getRecursive() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Updates the Impressions by 1 |
||
| 540 | * |
||
| 541 | * @return void |
||
| 542 | */ |
||
| 543 | public function increaseImpressions() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Updates the Impressions by 1 |
||
| 550 | * |
||
| 551 | * @return void |
||
| 552 | */ |
||
| 553 | public function increaseClicks() |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Returns the uri of the link |
||
| 560 | * |
||
| 561 | * @return mixed |
||
| 562 | */ |
||
| 563 | public function getLinkUrl() |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Returns the target of the link |
||
| 571 | * |
||
| 572 | * @return string |
||
| 573 | */ |
||
| 574 | public function getLinkTarget() |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Get the Fal media items |
||
| 584 | * |
||
| 585 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> |
||
|
|
|||
| 586 | */ |
||
| 587 | public function getAssets() |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Set Fal media relation |
||
| 594 | * |
||
| 595 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $assets |
||
| 596 | * @return void |
||
| 597 | */ |
||
| 598 | 2 | public function setAssets(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $assets) |
|
| 602 | |||
| 603 | /** |
||
| 604 | * Add a Fal media file reference |
||
| 605 | * |
||
| 606 | * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $asset |
||
| 607 | */ |
||
| 608 | public function addAsset(\TYPO3\CMS\Extbase\Domain\Model\FileReference $asset) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Remove a Fal media file reference |
||
| 615 | * |
||
| 616 | * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $asset |
||
| 617 | */ |
||
| 618 | public function removeAsset(\TYPO3\CMS\Extbase\Domain\Model\FileReference $asset) |
||
| 622 | } |
||
| 623 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.