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 | * Recursively use excludepages |
||
173 | * @var bool |
||
174 | */ |
||
175 | protected $recursive; |
||
176 | |||
177 | /** |
||
178 | * AllowScriptAccess for flash banners |
||
179 | * |
||
180 | * @var string |
||
181 | */ |
||
182 | protected $flashAllowScriptAccess; |
||
183 | |||
184 | /** |
||
185 | * Wmode for flash banners |
||
186 | * |
||
187 | * @var string |
||
188 | */ |
||
189 | protected $flashWmode; |
||
190 | |||
191 | /** |
||
192 | * __construct |
||
193 | */ |
||
194 | 33 | public function __construct() |
|
199 | |||
200 | /** |
||
201 | * Initializes all ObjectStorage properties |
||
202 | * Do not modify this method! |
||
203 | * It will be rewritten on each save in the extension builder |
||
204 | * You may modify the constructor of this class instead |
||
205 | * |
||
206 | * @return void |
||
207 | */ |
||
208 | 33 | protected function initStorageObjects() |
|
213 | |||
214 | /** |
||
215 | * Sets allowScriptAccess |
||
216 | * |
||
217 | * @param string $flashAllowScriptAccess FlashAllowScriptAccess |
||
218 | * @return void |
||
219 | */ |
||
220 | 2 | public function setFlashAllowScriptAccess($flashAllowScriptAccess) |
|
224 | |||
225 | /** |
||
226 | * Getter for allowScriptAccess |
||
227 | * |
||
228 | * @return string |
||
229 | */ |
||
230 | 3 | public function getFlashAllowScriptAccess() |
|
234 | |||
235 | /** |
||
236 | * Sets Wmode |
||
237 | * |
||
238 | * @param string $flashWmode FlashWMode |
||
239 | * @return void |
||
240 | */ |
||
241 | 2 | public function setFlashWmode($flashWmode) |
|
245 | |||
246 | /** |
||
247 | * Getter for Wmode |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | 3 | public function getFlashWmode() |
|
255 | |||
256 | /** |
||
257 | * Returns the title |
||
258 | * |
||
259 | * @return string $title |
||
260 | */ |
||
261 | 1 | public function getTitle() |
|
265 | |||
266 | /** |
||
267 | * Sets the title |
||
268 | * |
||
269 | * @param string $title The title |
||
270 | * @return void |
||
271 | */ |
||
272 | 1 | public function setTitle($title) |
|
276 | |||
277 | /** |
||
278 | * Returns the description |
||
279 | * |
||
280 | * @return string $description |
||
281 | */ |
||
282 | 1 | public function getDescription() |
|
286 | |||
287 | /** |
||
288 | * Sets the description |
||
289 | * |
||
290 | * @param string $description The description |
||
291 | * @return void |
||
292 | */ |
||
293 | 1 | public function setDescription($description) |
|
297 | |||
298 | /** |
||
299 | * Returns the type |
||
300 | * |
||
301 | * @return integer $type |
||
302 | */ |
||
303 | 1 | public function getType() |
|
307 | |||
308 | /** |
||
309 | * Sets the type |
||
310 | * |
||
311 | * @param integer $type The type |
||
312 | * @return void |
||
313 | */ |
||
314 | 1 | public function setType($type) |
|
318 | |||
319 | /** |
||
320 | * Adds a category |
||
321 | * |
||
322 | * @param \DERHANSEN\SfBanners\Domain\Model\Category $category |
||
323 | * @return void |
||
324 | */ |
||
325 | 1 | public function addCategory(\DERHANSEN\SfBanners\Domain\Model\Category $category) |
|
329 | |||
330 | /** |
||
331 | * Removes a category |
||
332 | * |
||
333 | * @param \DERHANSEN\SfBanners\Domain\Model\Category $categoryToRemove |
||
334 | * @return void |
||
335 | */ |
||
336 | 1 | public function removeCategory(\DERHANSEN\SfBanners\Domain\Model\Category $categoryToRemove) |
|
340 | |||
341 | /** |
||
342 | * Returns the category |
||
343 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category |
||
344 | */ |
||
345 | 1 | public function getCategory() |
|
349 | |||
350 | /** |
||
351 | * Sets the category |
||
352 | * |
||
353 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category One or multiple categories |
||
354 | * @return void |
||
355 | */ |
||
356 | 3 | public function setCategory($category) |
|
360 | |||
361 | /** |
||
362 | * Setter for alttext |
||
363 | * |
||
364 | * @param string $alttext Alttext |
||
365 | * @return void |
||
366 | */ |
||
367 | 1 | public function setAlttext($alttext) |
|
371 | |||
372 | /** |
||
373 | * Getter for alttext |
||
374 | * |
||
375 | * @return string |
||
376 | */ |
||
377 | 1 | public function getAlttext() |
|
381 | |||
382 | /** |
||
383 | * Setter for clicks |
||
384 | * |
||
385 | * @param int $clicks Clicks |
||
386 | * @return void |
||
387 | */ |
||
388 | 1 | public function setClicks($clicks) |
|
392 | |||
393 | /** |
||
394 | * getter for clicks |
||
395 | * |
||
396 | * @return int |
||
397 | */ |
||
398 | 1 | public function getClicks() |
|
402 | |||
403 | /** |
||
404 | * Setter for clicksmax |
||
405 | * |
||
406 | * @param int $clicksMax MaxClicks |
||
407 | * @return void |
||
408 | */ |
||
409 | 1 | public function setClicksMax($clicksMax) |
|
413 | |||
414 | /** |
||
415 | * Getter for clicksmax |
||
416 | * |
||
417 | * @return int |
||
418 | */ |
||
419 | 1 | public function getClicksMax() |
|
423 | |||
424 | /** |
||
425 | * Adds a page |
||
426 | * |
||
427 | * @param \DERHANSEN\SfBanners\Domain\Model\Page $page |
||
428 | * @return void |
||
429 | */ |
||
430 | 1 | public function addExcludepages(\DERHANSEN\SfBanners\Domain\Model\Page $page) |
|
434 | |||
435 | /** |
||
436 | * Removes a page |
||
437 | * |
||
438 | * @param \DERHANSEN\SfBanners\Domain\Model\page $pageToRemove |
||
439 | * @return void |
||
440 | */ |
||
441 | 1 | public function removeExcludepages(\DERHANSEN\SfBanners\Domain\Model\page $pageToRemove) |
|
445 | |||
446 | /** |
||
447 | * Setter for excludepages |
||
448 | * |
||
449 | * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $excludepages Excludepages |
||
450 | * @return void |
||
451 | */ |
||
452 | 3 | public function setExcludepages($excludepages) |
|
456 | |||
457 | /** |
||
458 | * Getter for excludepages |
||
459 | * |
||
460 | * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage |
||
461 | */ |
||
462 | 1 | public function getExcludepages() |
|
466 | |||
467 | /** |
||
468 | * Setter for flash |
||
469 | * |
||
470 | * @param string $flash Flashfile |
||
471 | * @return void |
||
472 | */ |
||
473 | 1 | public function setFlash($flash) |
|
477 | |||
478 | /** |
||
479 | * Getter for flash |
||
480 | * |
||
481 | * @return string |
||
482 | */ |
||
483 | 1 | public function getFlash() |
|
487 | |||
488 | /** |
||
489 | * Setter for flashheight |
||
490 | * |
||
491 | * @param int $flashHeight Flashheight |
||
492 | * @return void |
||
493 | */ |
||
494 | 1 | public function setFlashHeight($flashHeight) |
|
498 | |||
499 | /** |
||
500 | * Getter for flash |
||
501 | * |
||
502 | * @return int |
||
503 | */ |
||
504 | 1 | public function getFlashHeight() |
|
508 | |||
509 | /** |
||
510 | * Setter for flashwidth |
||
511 | * |
||
512 | * @param int $flashWidth Flashwidth |
||
513 | * @return void |
||
514 | */ |
||
515 | 1 | public function setFlashWidth($flashWidth) |
|
519 | |||
520 | /** |
||
521 | * Getter for flashwidth |
||
522 | * |
||
523 | * @return int |
||
524 | */ |
||
525 | 1 | public function getFlashWidth() |
|
529 | |||
530 | /** |
||
531 | * Setter for HTML |
||
532 | * |
||
533 | * @param string $html HTML |
||
534 | * @return void |
||
535 | */ |
||
536 | 1 | public function setHtml($html) |
|
540 | |||
541 | /** |
||
542 | * Getter for HTML |
||
543 | * |
||
544 | * @return string |
||
545 | */ |
||
546 | 1 | public function getHtml() |
|
550 | |||
551 | /** |
||
552 | * Setter for Image |
||
553 | * |
||
554 | * @param string $image Image |
||
555 | * @return void |
||
556 | */ |
||
557 | 1 | public function setImage($image) |
|
561 | |||
562 | /** |
||
563 | * Getter for image |
||
564 | * |
||
565 | * @return string |
||
566 | */ |
||
567 | 1 | public function getImage() |
|
571 | |||
572 | /** |
||
573 | * Setter for impressions |
||
574 | * |
||
575 | * @param int $impressions Impressions |
||
576 | * @return void |
||
577 | */ |
||
578 | 1 | public function setImpressions($impressions) |
|
582 | |||
583 | /** |
||
584 | * Getter for impressions |
||
585 | * |
||
586 | * @return int |
||
587 | */ |
||
588 | 1 | public function getImpressions() |
|
592 | |||
593 | /** |
||
594 | * Setter for max impressions |
||
595 | * |
||
596 | * @param int $impressionsMax Max impressions |
||
597 | * @return void |
||
598 | */ |
||
599 | 1 | public function setImpressionsMax($impressionsMax) |
|
603 | |||
604 | /** |
||
605 | * Getter for max impressions |
||
606 | * |
||
607 | * @return int |
||
608 | */ |
||
609 | 1 | public function getImpressionsMax() |
|
613 | |||
614 | /** |
||
615 | * Setter for link |
||
616 | * |
||
617 | * @param string $link Link |
||
618 | * @return void |
||
619 | */ |
||
620 | 1 | public function setLink($link) |
|
624 | |||
625 | /** |
||
626 | * Getter for link |
||
627 | * |
||
628 | * @return string |
||
629 | */ |
||
630 | 1 | public function getLink() |
|
634 | |||
635 | /** |
||
636 | * Setter for margin bottom |
||
637 | * |
||
638 | * @param int $marginBottom Margin bottom |
||
639 | * @return void |
||
640 | */ |
||
641 | 1 | public function setMarginBottom($marginBottom) |
|
645 | |||
646 | /** |
||
647 | * Getter for margin bottom |
||
648 | * |
||
649 | * @return int |
||
650 | */ |
||
651 | 1 | public function getMarginBottom() |
|
655 | |||
656 | /** |
||
657 | * Setter for margin left |
||
658 | * |
||
659 | * @param int $marginLeft Margin left |
||
660 | * @return void |
||
661 | */ |
||
662 | 1 | public function setMarginLeft($marginLeft) |
|
666 | |||
667 | /** |
||
668 | * Getter for margin left |
||
669 | * |
||
670 | * @return int |
||
671 | */ |
||
672 | 1 | public function getMarginLeft() |
|
676 | |||
677 | /** |
||
678 | * Setter for margin right |
||
679 | * |
||
680 | * @param int $marginRight Margin right |
||
681 | * @return void |
||
682 | */ |
||
683 | 1 | public function setMarginRight($marginRight) |
|
687 | |||
688 | /** |
||
689 | * Getter for margin right |
||
690 | * |
||
691 | * @return int |
||
692 | */ |
||
693 | 1 | public function getMarginRight() |
|
697 | |||
698 | /** |
||
699 | * Setter for margin top |
||
700 | * |
||
701 | * @param int $marginTop Margin top |
||
702 | * @return void |
||
703 | */ |
||
704 | 1 | public function setMarginTop($marginTop) |
|
708 | |||
709 | /** |
||
710 | * Getter for margin top |
||
711 | * |
||
712 | * @return int |
||
713 | */ |
||
714 | 1 | public function getMarginTop() |
|
718 | |||
719 | /** |
||
720 | * Sets the recursive flag |
||
721 | * |
||
722 | * @param boolean $recursive |
||
723 | * @return void |
||
724 | */ |
||
725 | 1 | public function setRecursive($recursive) |
|
729 | |||
730 | /** |
||
731 | * Returns the recursive flag |
||
732 | * |
||
733 | * @return boolean |
||
734 | */ |
||
735 | 1 | public function getRecursive() |
|
739 | |||
740 | /** |
||
741 | * Updates the Impressions by 1 |
||
742 | * |
||
743 | * @return void |
||
744 | */ |
||
745 | public function increaseImpressions() |
||
749 | |||
750 | /** |
||
751 | * Updates the Impressions by 1 |
||
752 | * |
||
753 | * @return void |
||
754 | */ |
||
755 | public function increaseClicks() |
||
759 | |||
760 | /** |
||
761 | * Returns the uri of the link |
||
762 | * |
||
763 | * @return mixed |
||
764 | */ |
||
765 | public function getLinkUrl() |
||
770 | |||
771 | /** |
||
772 | * Returns the target of the link |
||
773 | * |
||
774 | * @return string |
||
775 | */ |
||
776 | public function getLinkTarget() |
||
785 | } |
||
786 |