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 |
||
| 25 | class Banner extends AbstractEntity |
||
| 26 | { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Title |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | * @validate NotEmpty |
||
| 33 | */ |
||
| 34 | protected $title; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Description |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $description; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Type |
||
| 45 | * |
||
| 46 | * @var integer |
||
| 47 | * @validate NotEmpty |
||
| 48 | */ |
||
| 49 | protected $type; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Category |
||
| 53 | * |
||
| 54 | * @lazy |
||
| 55 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<DERHANSEN\SfBanners\Domain\Model\Category> |
||
| 56 | */ |
||
| 57 | protected $category; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Image |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $image; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Margin top |
||
| 68 | * |
||
| 69 | * @var integer |
||
| 70 | */ |
||
| 71 | protected $marginTop; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Margin right |
||
| 75 | * |
||
| 76 | * @var integer |
||
| 77 | */ |
||
| 78 | protected $marginRight; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Margin bottom |
||
| 82 | * |
||
| 83 | * @var integer |
||
| 84 | */ |
||
| 85 | protected $marginBottom; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Margin top |
||
| 89 | * |
||
| 90 | * @var integer |
||
| 91 | */ |
||
| 92 | protected $marginLeft; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Alttext |
||
| 96 | * |
||
| 97 | * @var string |
||
| 98 | */ |
||
| 99 | protected $alttext; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Link |
||
| 103 | * |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | protected $link; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * HTML |
||
| 110 | * |
||
| 111 | * @var string |
||
| 112 | */ |
||
| 113 | protected $html; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Flash |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | protected $flash; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Flash width |
||
| 124 | * |
||
| 125 | * @var integer |
||
| 126 | */ |
||
| 127 | protected $flashWidth; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Flash height |
||
| 131 | * |
||
| 132 | * @var integer |
||
| 133 | */ |
||
| 134 | protected $flashHeight; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Max impressions |
||
| 138 | * |
||
| 139 | * @var integer |
||
| 140 | */ |
||
| 141 | protected $impressionsMax; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Max clicks |
||
| 145 | * |
||
| 146 | * @var integer |
||
| 147 | */ |
||
| 148 | protected $clicksMax; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Total impressions |
||
| 152 | * |
||
| 153 | * @var integer |
||
| 154 | */ |
||
| 155 | protected $impressions; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Total clicks |
||
| 159 | * |
||
| 160 | * @var integer |
||
| 161 | */ |
||
| 162 | protected $clicks; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Do not display on pages |
||
| 166 | * @lazy |
||
| 167 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfBanners\Domain\Model\Page> |
||
| 168 | */ |
||
| 169 | protected $excludepages; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Do not display on pages |
||
| 173 | * @lazy |
||
| 174 | * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfBanners\Domain\Model\Page> |
||
| 175 | */ |
||
| 176 | protected $includepages; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Recursively use excludepages |
||
| 180 | * @var bool |
||
| 181 | */ |
||
| 182 | protected $recursive; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Recursively use includepages |
||
| 186 | * @var bool |
||
| 187 | */ |
||
| 188 | protected $includeRecursive; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * AllowScriptAccess for flash banners |
||
| 192 | * |
||
| 193 | * @var string |
||
| 194 | */ |
||
| 195 | protected $flashAllowScriptAccess; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Wmode for flash banners |
||
| 199 | * |
||
| 200 | * @var string |
||
| 201 | */ |
||
| 202 | protected $flashWmode; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * __construct |
||
| 206 | */ |
||
| 207 | public function __construct() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Initializes all ObjectStorage properties |
||
| 215 | * Do not modify this method! |
||
| 216 | * It will be rewritten on each save in the extension builder |
||
| 217 | * You may modify the constructor of this class instead |
||
| 218 | * |
||
| 219 | * @return void |
||
| 220 | */ |
||
| 221 | protected function initStorageObjects() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Sets allowScriptAccess |
||
| 230 | * |
||
| 231 | * @param string $flashAllowScriptAccess FlashAllowScriptAccess |
||
| 232 | * @return void |
||
| 233 | */ |
||
| 234 | public function setFlashAllowScriptAccess($flashAllowScriptAccess) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Getter for allowScriptAccess |
||
| 241 | * |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | public function getFlashAllowScriptAccess() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Sets Wmode |
||
| 251 | * |
||
| 252 | * @param string $flashWmode FlashWMode |
||
| 253 | * @return void |
||
| 254 | */ |
||
| 255 | public function setFlashWmode($flashWmode) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Getter for Wmode |
||
| 262 | * |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function getFlashWmode() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Returns the title |
||
| 272 | * |
||
| 273 | * @return string $title |
||
| 274 | */ |
||
| 275 | public function getTitle() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Sets the title |
||
| 282 | * |
||
| 283 | * @param string $title The title |
||
| 284 | * @return void |
||
| 285 | */ |
||
| 286 | public function setTitle($title) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Returns the description |
||
| 293 | * |
||
| 294 | * @return string $description |
||
| 295 | */ |
||
| 296 | public function getDescription() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Sets the description |
||
| 303 | * |
||
| 304 | * @param string $description The description |
||
| 305 | * @return void |
||
| 306 | */ |
||
| 307 | public function setDescription($description) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Returns the type |
||
| 314 | * |
||
| 315 | * @return integer $type |
||
| 316 | */ |
||
| 317 | public function getType() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Sets the type |
||
| 324 | * |
||
| 325 | * @param integer $type The type |
||
| 326 | * @return void |
||
| 327 | */ |
||
| 328 | public function setType($type) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Adds a category |
||
| 335 | * |
||
| 336 | * @param \DERHANSEN\SfBanners\Domain\Model\Category $category |
||
| 337 | * @return void |
||
| 338 | */ |
||
| 339 | public function addCategory(\DERHANSEN\SfBanners\Domain\Model\Category $category) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Removes a category |
||
| 346 | * |
||
| 347 | * @param \DERHANSEN\SfBanners\Domain\Model\Category $categoryToRemove |
||
| 348 | * @return void |
||
| 349 | */ |
||
| 350 | public function removeCategory(\DERHANSEN\SfBanners\Domain\Model\Category $categoryToRemove) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Returns the category |
||
| 357 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category |
||
| 358 | */ |
||
| 359 | public function getCategory() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Sets the category |
||
| 366 | * |
||
| 367 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category One or multiple categories |
||
| 368 | * @return void |
||
| 369 | */ |
||
| 370 | public function setCategory($category) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Setter for alttext |
||
| 377 | * |
||
| 378 | * @param string $alttext Alttext |
||
| 379 | * @return void |
||
| 380 | */ |
||
| 381 | public function setAlttext($alttext) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Getter for alttext |
||
| 388 | * |
||
| 389 | * @return string |
||
| 390 | */ |
||
| 391 | public function getAlttext() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Setter for clicks |
||
| 398 | 2 | * |
|
| 399 | * @param int $clicks Clicks |
||
| 400 | 2 | * @return void |
|
| 401 | */ |
||
| 402 | public function setClicks($clicks) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * getter for clicks |
||
| 409 | * |
||
| 410 | * @return int |
||
| 411 | */ |
||
| 412 | public function getClicks() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Setter for clicksmax |
||
| 419 | 8 | * |
|
| 420 | * @param int $clicksMax MaxClicks |
||
| 421 | 8 | * @return void |
|
| 422 | */ |
||
| 423 | public function setClicksMax($clicksMax) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Getter for clicksmax |
||
| 430 | * |
||
| 431 | * @return int |
||
| 432 | */ |
||
| 433 | public function getClicksMax() |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Adds a page |
||
| 440 | * |
||
| 441 | * @param \DERHANSEN\SfBanners\Domain\Model\Page $page |
||
| 442 | * @return void |
||
| 443 | */ |
||
| 444 | public function addExcludepages(\DERHANSEN\SfBanners\Domain\Model\Page $page) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Removes a page |
||
| 451 | * |
||
| 452 | * @param \DERHANSEN\SfBanners\Domain\Model\page $pageToRemove |
||
| 453 | * @return void |
||
| 454 | */ |
||
| 455 | public function removeExcludepages(\DERHANSEN\SfBanners\Domain\Model\page $pageToRemove) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Setter for excludepages |
||
| 462 | 8 | * |
|
| 463 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $excludepages Excludepages |
||
| 464 | 8 | * @return void |
|
| 465 | */ |
||
| 466 | public function setExcludepages($excludepages) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Getter for excludepages |
||
| 473 | * |
||
| 474 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage |
||
| 475 | */ |
||
| 476 | public function getExcludepages() |
||
| 480 | |||
| 481 | |||
| 482 | /** |
||
| 483 | * Adds a page |
||
| 484 | * |
||
| 485 | * @param \DERHANSEN\SfBanners\Domain\Model\Page $page |
||
| 486 | * @return void |
||
| 487 | */ |
||
| 488 | public function addIncludepages(\DERHANSEN\SfBanners\Domain\Model\Page $page) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Removes a page |
||
| 495 | * |
||
| 496 | * @param \DERHANSEN\SfBanners\Domain\Model\page $pageToRemove |
||
| 497 | * @return void |
||
| 498 | */ |
||
| 499 | public function removeIncludepages(\DERHANSEN\SfBanners\Domain\Model\page $pageToRemove) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Setter for includepages |
||
| 506 | * |
||
| 507 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $includepages Includepages |
||
| 508 | * @return void |
||
| 509 | */ |
||
| 510 | public function setIncludepages($includepages) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Getter for includepages |
||
| 517 | * |
||
| 518 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage |
||
| 519 | */ |
||
| 520 | public function getIncludepages() |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Setter for flash |
||
| 527 | * |
||
| 528 | * @param string $flash Flashfile |
||
| 529 | * @return void |
||
| 530 | */ |
||
| 531 | public function setFlash($flash) |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Getter for flash |
||
| 538 | * |
||
| 539 | * @return string |
||
| 540 | */ |
||
| 541 | public function getFlash() |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Setter for flashheight |
||
| 548 | * |
||
| 549 | * @param int $flashHeight Flashheight |
||
| 550 | * @return void |
||
| 551 | */ |
||
| 552 | public function setFlashHeight($flashHeight) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Getter for flash |
||
| 559 | * |
||
| 560 | * @return int |
||
| 561 | */ |
||
| 562 | public function getFlashHeight() |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Setter for flashwidth |
||
| 569 | * |
||
| 570 | * @param int $flashWidth Flashwidth |
||
| 571 | * @return void |
||
| 572 | */ |
||
| 573 | public function setFlashWidth($flashWidth) |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Getter for flashwidth |
||
| 580 | * |
||
| 581 | * @return int |
||
| 582 | */ |
||
| 583 | public function getFlashWidth() |
||
| 587 | |||
| 588 | 2 | /** |
|
| 589 | * Setter for HTML |
||
| 590 | 2 | * |
|
| 591 | * @param string $html HTML |
||
| 592 | * @return void |
||
| 593 | */ |
||
| 594 | public function setHtml($html) |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Getter for HTML |
||
| 601 | * |
||
| 602 | * @return string |
||
| 603 | */ |
||
| 604 | public function getHtml() |
||
| 608 | |||
| 609 | 8 | /** |
|
| 610 | * Setter for Image |
||
| 611 | 8 | * |
|
| 612 | * @param string $image Image |
||
| 613 | * @return void |
||
| 614 | */ |
||
| 615 | public function setImage($image) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Getter for image |
||
| 622 | * |
||
| 623 | * @return string |
||
| 624 | */ |
||
| 625 | public function getImage() |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Setter for impressions |
||
| 632 | * |
||
| 633 | * @param int $impressions Impressions |
||
| 634 | * @return void |
||
| 635 | */ |
||
| 636 | public function setImpressions($impressions) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Getter for impressions |
||
| 643 | * |
||
| 644 | * @return int |
||
| 645 | */ |
||
| 646 | public function getImpressions() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Setter for max impressions |
||
| 653 | * |
||
| 654 | * @param int $impressionsMax Max impressions |
||
| 655 | * @return void |
||
| 656 | */ |
||
| 657 | public function setImpressionsMax($impressionsMax) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * Getter for max impressions |
||
| 664 | * |
||
| 665 | * @return int |
||
| 666 | */ |
||
| 667 | public function getImpressionsMax() |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Setter for link |
||
| 674 | * |
||
| 675 | * @param string $link Link |
||
| 676 | * @return void |
||
| 677 | */ |
||
| 678 | public function setLink($link) |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Getter for link |
||
| 685 | * |
||
| 686 | * @return string |
||
| 687 | */ |
||
| 688 | public function getLink() |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Setter for margin bottom |
||
| 695 | * |
||
| 696 | * @param int $marginBottom Margin bottom |
||
| 697 | * @return void |
||
| 698 | */ |
||
| 699 | public function setMarginBottom($marginBottom) |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Getter for margin bottom |
||
| 706 | * |
||
| 707 | * @return int |
||
| 708 | */ |
||
| 709 | public function getMarginBottom() |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Setter for margin left |
||
| 716 | * |
||
| 717 | * @param int $marginLeft Margin left |
||
| 718 | * @return void |
||
| 719 | */ |
||
| 720 | public function setMarginLeft($marginLeft) |
||
| 724 | |||
| 725 | /** |
||
| 726 | * Getter for margin left |
||
| 727 | * |
||
| 728 | * @return int |
||
| 729 | */ |
||
| 730 | public function getMarginLeft() |
||
| 734 | |||
| 735 | 2 | /** |
|
| 736 | * Setter for margin right |
||
| 737 | 2 | * |
|
| 738 | * @param int $marginRight Margin right |
||
| 739 | * @return void |
||
| 740 | */ |
||
| 741 | public function setMarginRight($marginRight) |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Getter for margin right |
||
| 748 | * |
||
| 749 | * @return int |
||
| 750 | */ |
||
| 751 | public function getMarginRight() |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Setter for margin top |
||
| 758 | * |
||
| 759 | * @param int $marginTop Margin top |
||
| 760 | * @return void |
||
| 761 | */ |
||
| 762 | public function setMarginTop($marginTop) |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Getter for margin top |
||
| 769 | * |
||
| 770 | * @return int |
||
| 771 | */ |
||
| 772 | public function getMarginTop() |
||
| 776 | |||
| 777 | /** |
||
| 778 | * Sets the recursive flag |
||
| 779 | * |
||
| 780 | * @param boolean $recursive |
||
| 781 | * @return void |
||
| 782 | */ |
||
| 783 | public function setRecursive($recursive) |
||
| 787 | |||
| 788 | /** |
||
| 789 | * Returns the recursive flag |
||
| 790 | * |
||
| 791 | * @return boolean |
||
| 792 | */ |
||
| 793 | public function getRecursive() |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Sets the include recursive flag |
||
| 800 | * |
||
| 801 | * @param boolean $includeRecursive |
||
| 802 | * @return void |
||
| 803 | */ |
||
| 804 | public function setIncludeRecursive($includeRecursive) |
||
| 808 | |||
| 809 | /** |
||
| 810 | * Returns the include recursive flag |
||
| 811 | * |
||
| 812 | * @return boolean |
||
| 813 | */ |
||
| 814 | public function getIncludeRecursive() |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Updates the Impressions by 1 |
||
| 821 | * |
||
| 822 | * @return void |
||
| 823 | */ |
||
| 824 | public function increaseImpressions() |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Updates the Impressions by 1 |
||
| 831 | * |
||
| 832 | * @return void |
||
| 833 | */ |
||
| 834 | public function increaseClicks() |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Returns the uri of the link |
||
| 841 | * |
||
| 842 | * @return mixed |
||
| 843 | */ |
||
| 844 | public function getLinkUrl() |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Returns the target of the link |
||
| 852 | * |
||
| 853 | * @return string |
||
| 854 | */ |
||
| 855 | public function getLinkTarget() |
||
| 864 | } |
||
| 865 |