Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EntryType 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 EntryType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | View Code Duplication | class EntryType |
|
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @property string $base |
||
16 | */ |
||
17 | private $base = null; |
||
18 | |||
19 | /** |
||
20 | * @property string $lang |
||
21 | */ |
||
22 | private $lang = null; |
||
23 | |||
24 | /** |
||
25 | * @property \AlgoWeb\ODataMetadata\Atom\Author[] $author |
||
26 | */ |
||
27 | private $author = array( |
||
28 | |||
29 | ); |
||
30 | |||
31 | /** |
||
32 | * @property \AlgoWeb\ODataMetadata\Atom\Category[] $category |
||
33 | */ |
||
34 | private $category = array( |
||
35 | |||
36 | ); |
||
37 | |||
38 | /** |
||
39 | * @property \AlgoWeb\ODataMetadata\Atom\Content[] $content |
||
40 | */ |
||
41 | private $content = array( |
||
42 | |||
43 | ); |
||
44 | |||
45 | /** |
||
46 | * @property \AlgoWeb\ODataMetadata\Atom\Contributor[] $contributor |
||
47 | */ |
||
48 | private $contributor = array( |
||
49 | |||
50 | ); |
||
51 | |||
52 | /** |
||
53 | * @property \AlgoWeb\ODataMetadata\Atom\Id[] $id |
||
54 | */ |
||
55 | private $id = array( |
||
56 | |||
57 | ); |
||
58 | |||
59 | /** |
||
60 | * @property \AlgoWeb\ODataMetadata\Atom\Link[] $link |
||
61 | */ |
||
62 | private $link = array( |
||
63 | |||
64 | ); |
||
65 | |||
66 | /** |
||
67 | * @property \AlgoWeb\ODataMetadata\Atom\Published[] $published |
||
68 | */ |
||
69 | private $published = array( |
||
70 | |||
71 | ); |
||
72 | |||
73 | /** |
||
74 | * @property \AlgoWeb\ODataMetadata\Atom\Rights[] $rights |
||
75 | */ |
||
76 | private $rights = array( |
||
77 | |||
78 | ); |
||
79 | |||
80 | /** |
||
81 | * @property \AlgoWeb\ODataMetadata\Atom\Source[] $source |
||
82 | */ |
||
83 | private $source = array( |
||
84 | |||
85 | ); |
||
86 | |||
87 | /** |
||
88 | * @property \AlgoWeb\ODataMetadata\Atom\Summary[] $summary |
||
89 | */ |
||
90 | private $summary = array( |
||
91 | |||
92 | ); |
||
93 | |||
94 | /** |
||
95 | * @property \AlgoWeb\ODataMetadata\Atom\Title[] $title |
||
96 | */ |
||
97 | private $title = array( |
||
98 | |||
99 | ); |
||
100 | |||
101 | /** |
||
102 | * @property \AlgoWeb\ODataMetadata\Atom\Updated[] $updated |
||
103 | */ |
||
104 | private $updated = array( |
||
105 | |||
106 | ); |
||
107 | |||
108 | /** |
||
109 | * Gets as base |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getBase() |
||
117 | |||
118 | /** |
||
119 | * Sets a new base |
||
120 | * |
||
121 | * @param string $base |
||
122 | * @return self |
||
123 | */ |
||
124 | public function setBase($base) |
||
129 | |||
130 | /** |
||
131 | * Gets as lang |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getLang() |
||
139 | |||
140 | /** |
||
141 | * Sets a new lang |
||
142 | * |
||
143 | * @param string $lang |
||
144 | * @return self |
||
145 | */ |
||
146 | public function setLang($lang) |
||
151 | |||
152 | /** |
||
153 | * Adds as author |
||
154 | * |
||
155 | * @return self |
||
156 | * @param \AlgoWeb\ODataMetadata\Atom\Author $author |
||
157 | */ |
||
158 | public function addToAuthor(\AlgoWeb\ODataMetadata\Atom\Author $author) |
||
163 | |||
164 | /** |
||
165 | * isset author |
||
166 | * |
||
167 | * @param scalar $index |
||
168 | * @return boolean |
||
169 | */ |
||
170 | public function issetAuthor($index) |
||
174 | |||
175 | /** |
||
176 | * unset author |
||
177 | * |
||
178 | * @param scalar $index |
||
179 | * @return void |
||
180 | */ |
||
181 | public function unsetAuthor($index) |
||
185 | |||
186 | /** |
||
187 | * Gets as author |
||
188 | * |
||
189 | * @return \AlgoWeb\ODataMetadata\Atom\Author[] |
||
190 | */ |
||
191 | public function getAuthor() |
||
195 | |||
196 | /** |
||
197 | * Sets a new author |
||
198 | * |
||
199 | * @param \AlgoWeb\ODataMetadata\Atom\Author[] $author |
||
200 | * @return self |
||
201 | */ |
||
202 | public function setAuthor(array $author) |
||
207 | |||
208 | /** |
||
209 | * Adds as category |
||
210 | * |
||
211 | * @return self |
||
212 | * @param \AlgoWeb\ODataMetadata\Atom\Category $category |
||
213 | */ |
||
214 | public function addToCategory(\AlgoWeb\ODataMetadata\Atom\Category $category) |
||
219 | |||
220 | /** |
||
221 | * isset category |
||
222 | * |
||
223 | * @param scalar $index |
||
224 | * @return boolean |
||
225 | */ |
||
226 | public function issetCategory($index) |
||
230 | |||
231 | /** |
||
232 | * unset category |
||
233 | * |
||
234 | * @param scalar $index |
||
235 | * @return void |
||
236 | */ |
||
237 | public function unsetCategory($index) |
||
241 | |||
242 | /** |
||
243 | * Gets as category |
||
244 | * |
||
245 | * @return \AlgoWeb\ODataMetadata\Atom\Category[] |
||
246 | */ |
||
247 | public function getCategory() |
||
251 | |||
252 | /** |
||
253 | * Sets a new category |
||
254 | * |
||
255 | * @param \AlgoWeb\ODataMetadata\Atom\Category[] $category |
||
256 | * @return self |
||
257 | */ |
||
258 | public function setCategory(array $category) |
||
263 | |||
264 | /** |
||
265 | * Adds as content |
||
266 | * |
||
267 | * @return self |
||
268 | * @param \AlgoWeb\ODataMetadata\Atom\Content $content |
||
269 | */ |
||
270 | public function addToContent(\AlgoWeb\ODataMetadata\Atom\Content $content) |
||
275 | |||
276 | /** |
||
277 | * isset content |
||
278 | * |
||
279 | * @param scalar $index |
||
280 | * @return boolean |
||
281 | */ |
||
282 | public function issetContent($index) |
||
286 | |||
287 | /** |
||
288 | * unset content |
||
289 | * |
||
290 | * @param scalar $index |
||
291 | * @return void |
||
292 | */ |
||
293 | public function unsetContent($index) |
||
297 | |||
298 | /** |
||
299 | * Gets as content |
||
300 | * |
||
301 | * @return \AlgoWeb\ODataMetadata\Atom\Content[] |
||
302 | */ |
||
303 | public function getContent() |
||
307 | |||
308 | /** |
||
309 | * Sets a new content |
||
310 | * |
||
311 | * @param \AlgoWeb\ODataMetadata\Atom\Content[] $content |
||
312 | * @return self |
||
313 | */ |
||
314 | public function setContent(array $content) |
||
319 | |||
320 | /** |
||
321 | * Adds as contributor |
||
322 | * |
||
323 | * @return self |
||
324 | * @param \AlgoWeb\ODataMetadata\Atom\Contributor $contributor |
||
325 | */ |
||
326 | public function addToContributor(\AlgoWeb\ODataMetadata\Atom\Contributor $contributor) |
||
331 | |||
332 | /** |
||
333 | * isset contributor |
||
334 | * |
||
335 | * @param scalar $index |
||
336 | * @return boolean |
||
337 | */ |
||
338 | public function issetContributor($index) |
||
342 | |||
343 | /** |
||
344 | * unset contributor |
||
345 | * |
||
346 | * @param scalar $index |
||
347 | * @return void |
||
348 | */ |
||
349 | public function unsetContributor($index) |
||
353 | |||
354 | /** |
||
355 | * Gets as contributor |
||
356 | * |
||
357 | * @return \AlgoWeb\ODataMetadata\Atom\Contributor[] |
||
358 | */ |
||
359 | public function getContributor() |
||
363 | |||
364 | /** |
||
365 | * Sets a new contributor |
||
366 | * |
||
367 | * @param \AlgoWeb\ODataMetadata\Atom\Contributor[] $contributor |
||
368 | * @return self |
||
369 | */ |
||
370 | public function setContributor(array $contributor) |
||
375 | |||
376 | /** |
||
377 | * Adds as id |
||
378 | * |
||
379 | * @return self |
||
380 | * @param \AlgoWeb\ODataMetadata\Atom\Id $id |
||
381 | */ |
||
382 | public function addToId(\AlgoWeb\ODataMetadata\Atom\Id $id) |
||
387 | |||
388 | /** |
||
389 | * isset id |
||
390 | * |
||
391 | * @param scalar $index |
||
392 | * @return boolean |
||
393 | */ |
||
394 | public function issetId($index) |
||
398 | |||
399 | /** |
||
400 | * unset id |
||
401 | * |
||
402 | * @param scalar $index |
||
403 | * @return void |
||
404 | */ |
||
405 | public function unsetId($index) |
||
409 | |||
410 | /** |
||
411 | * Gets as id |
||
412 | * |
||
413 | * @return \AlgoWeb\ODataMetadata\Atom\Id[] |
||
414 | */ |
||
415 | public function getId() |
||
419 | |||
420 | /** |
||
421 | * Sets a new id |
||
422 | * |
||
423 | * @param \AlgoWeb\ODataMetadata\Atom\Id[] $id |
||
424 | * @return self |
||
425 | */ |
||
426 | public function setId(array $id) |
||
431 | |||
432 | /** |
||
433 | * Adds as link |
||
434 | * |
||
435 | * @return self |
||
436 | * @param \AlgoWeb\ODataMetadata\Atom\Link $link |
||
437 | */ |
||
438 | public function addToLink(\AlgoWeb\ODataMetadata\Atom\Link $link) |
||
443 | |||
444 | /** |
||
445 | * isset link |
||
446 | * |
||
447 | * @param scalar $index |
||
448 | * @return boolean |
||
449 | */ |
||
450 | public function issetLink($index) |
||
454 | |||
455 | /** |
||
456 | * unset link |
||
457 | * |
||
458 | * @param scalar $index |
||
459 | * @return void |
||
460 | */ |
||
461 | public function unsetLink($index) |
||
465 | |||
466 | /** |
||
467 | * Gets as link |
||
468 | * |
||
469 | * @return \AlgoWeb\ODataMetadata\Atom\Link[] |
||
470 | */ |
||
471 | public function getLink() |
||
475 | |||
476 | /** |
||
477 | * Sets a new link |
||
478 | * |
||
479 | * @param \AlgoWeb\ODataMetadata\Atom\Link[] $link |
||
480 | * @return self |
||
481 | */ |
||
482 | public function setLink(array $link) |
||
487 | |||
488 | /** |
||
489 | * Adds as published |
||
490 | * |
||
491 | * @return self |
||
492 | * @param \AlgoWeb\ODataMetadata\Atom\Published $published |
||
493 | */ |
||
494 | public function addToPublished(\AlgoWeb\ODataMetadata\Atom\Published $published) |
||
499 | |||
500 | /** |
||
501 | * isset published |
||
502 | * |
||
503 | * @param scalar $index |
||
504 | * @return boolean |
||
505 | */ |
||
506 | public function issetPublished($index) |
||
510 | |||
511 | /** |
||
512 | * unset published |
||
513 | * |
||
514 | * @param scalar $index |
||
515 | * @return void |
||
516 | */ |
||
517 | public function unsetPublished($index) |
||
521 | |||
522 | /** |
||
523 | * Gets as published |
||
524 | * |
||
525 | * @return \AlgoWeb\ODataMetadata\Atom\Published[] |
||
526 | */ |
||
527 | public function getPublished() |
||
531 | |||
532 | /** |
||
533 | * Sets a new published |
||
534 | * |
||
535 | * @param \AlgoWeb\ODataMetadata\Atom\Published[] $published |
||
536 | * @return self |
||
537 | */ |
||
538 | public function setPublished(array $published) |
||
543 | |||
544 | /** |
||
545 | * Adds as rights |
||
546 | * |
||
547 | * @return self |
||
548 | * @param \AlgoWeb\ODataMetadata\Atom\Rights $rights |
||
549 | */ |
||
550 | public function addToRights(\AlgoWeb\ODataMetadata\Atom\Rights $rights) |
||
555 | |||
556 | /** |
||
557 | * isset rights |
||
558 | * |
||
559 | * @param scalar $index |
||
560 | * @return boolean |
||
561 | */ |
||
562 | public function issetRights($index) |
||
566 | |||
567 | /** |
||
568 | * unset rights |
||
569 | * |
||
570 | * @param scalar $index |
||
571 | * @return void |
||
572 | */ |
||
573 | public function unsetRights($index) |
||
577 | |||
578 | /** |
||
579 | * Gets as rights |
||
580 | * |
||
581 | * @return \AlgoWeb\ODataMetadata\Atom\Rights[] |
||
582 | */ |
||
583 | public function getRights() |
||
587 | |||
588 | /** |
||
589 | * Sets a new rights |
||
590 | * |
||
591 | * @param \AlgoWeb\ODataMetadata\Atom\Rights[] $rights |
||
592 | * @return self |
||
593 | */ |
||
594 | public function setRights(array $rights) |
||
599 | |||
600 | /** |
||
601 | * Adds as source |
||
602 | * |
||
603 | * @return self |
||
604 | * @param \AlgoWeb\ODataMetadata\Atom\Source $source |
||
605 | */ |
||
606 | public function addToSource(\AlgoWeb\ODataMetadata\Atom\Source $source) |
||
611 | |||
612 | /** |
||
613 | * isset source |
||
614 | * |
||
615 | * @param scalar $index |
||
616 | * @return boolean |
||
617 | */ |
||
618 | public function issetSource($index) |
||
622 | |||
623 | /** |
||
624 | * unset source |
||
625 | * |
||
626 | * @param scalar $index |
||
627 | * @return void |
||
628 | */ |
||
629 | public function unsetSource($index) |
||
633 | |||
634 | /** |
||
635 | * Gets as source |
||
636 | * |
||
637 | * @return \AlgoWeb\ODataMetadata\Atom\Source[] |
||
638 | */ |
||
639 | public function getSource() |
||
643 | |||
644 | /** |
||
645 | * Sets a new source |
||
646 | * |
||
647 | * @param \AlgoWeb\ODataMetadata\Atom\Source[] $source |
||
648 | * @return self |
||
649 | */ |
||
650 | public function setSource(array $source) |
||
655 | |||
656 | /** |
||
657 | * Adds as summary |
||
658 | * |
||
659 | * @return self |
||
660 | * @param \AlgoWeb\ODataMetadata\Atom\Summary $summary |
||
661 | */ |
||
662 | public function addToSummary(\AlgoWeb\ODataMetadata\Atom\Summary $summary) |
||
667 | |||
668 | /** |
||
669 | * isset summary |
||
670 | * |
||
671 | * @param scalar $index |
||
672 | * @return boolean |
||
673 | */ |
||
674 | public function issetSummary($index) |
||
678 | |||
679 | /** |
||
680 | * unset summary |
||
681 | * |
||
682 | * @param scalar $index |
||
683 | * @return void |
||
684 | */ |
||
685 | public function unsetSummary($index) |
||
689 | |||
690 | /** |
||
691 | * Gets as summary |
||
692 | * |
||
693 | * @return \AlgoWeb\ODataMetadata\Atom\Summary[] |
||
694 | */ |
||
695 | public function getSummary() |
||
699 | |||
700 | /** |
||
701 | * Sets a new summary |
||
702 | * |
||
703 | * @param \AlgoWeb\ODataMetadata\Atom\Summary[] $summary |
||
704 | * @return self |
||
705 | */ |
||
706 | public function setSummary(array $summary) |
||
711 | |||
712 | /** |
||
713 | * Adds as title |
||
714 | * |
||
715 | * @return self |
||
716 | * @param \AlgoWeb\ODataMetadata\Atom\Title $title |
||
717 | */ |
||
718 | public function addToTitle(\AlgoWeb\ODataMetadata\Atom\Title $title) |
||
723 | |||
724 | /** |
||
725 | * isset title |
||
726 | * |
||
727 | * @param scalar $index |
||
728 | * @return boolean |
||
729 | */ |
||
730 | public function issetTitle($index) |
||
734 | |||
735 | /** |
||
736 | * unset title |
||
737 | * |
||
738 | * @param scalar $index |
||
739 | * @return void |
||
740 | */ |
||
741 | public function unsetTitle($index) |
||
745 | |||
746 | /** |
||
747 | * Gets as title |
||
748 | * |
||
749 | * @return \AlgoWeb\ODataMetadata\Atom\Title[] |
||
750 | */ |
||
751 | public function getTitle() |
||
755 | |||
756 | /** |
||
757 | * Sets a new title |
||
758 | * |
||
759 | * @param \AlgoWeb\ODataMetadata\Atom\Title[] $title |
||
760 | * @return self |
||
761 | */ |
||
762 | public function setTitle(array $title) |
||
767 | |||
768 | /** |
||
769 | * Adds as updated |
||
770 | * |
||
771 | * @return self |
||
772 | * @param \AlgoWeb\ODataMetadata\Atom\Updated $updated |
||
773 | */ |
||
774 | public function addToUpdated(\AlgoWeb\ODataMetadata\Atom\Updated $updated) |
||
779 | |||
780 | /** |
||
781 | * isset updated |
||
782 | * |
||
783 | * @param scalar $index |
||
784 | * @return boolean |
||
785 | */ |
||
786 | public function issetUpdated($index) |
||
790 | |||
791 | /** |
||
792 | * unset updated |
||
793 | * |
||
794 | * @param scalar $index |
||
795 | * @return void |
||
796 | */ |
||
797 | public function unsetUpdated($index) |
||
801 | |||
802 | /** |
||
803 | * Gets as updated |
||
804 | * |
||
805 | * @return \AlgoWeb\ODataMetadata\Atom\Updated[] |
||
806 | */ |
||
807 | public function getUpdated() |
||
811 | |||
812 | /** |
||
813 | * Sets a new updated |
||
814 | * |
||
815 | * @param \AlgoWeb\ODataMetadata\Atom\Updated[] $updated |
||
816 | * @return self |
||
817 | */ |
||
818 | public function setUpdated(array $updated) |
||
823 | } |
||
824 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.