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 Source 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 Source, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | View Code Duplication | class Source |
|
|
|||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @property string $base |
||
13 | */ |
||
14 | private $base = null; |
||
15 | |||
16 | /** |
||
17 | * @property string $lang |
||
18 | */ |
||
19 | private $lang = null; |
||
20 | |||
21 | /** |
||
22 | * @property \AlgoWeb\ODataMetadata\Atom\Author[] $author |
||
23 | */ |
||
24 | private $author = array( |
||
25 | |||
26 | ); |
||
27 | |||
28 | /** |
||
29 | * @property \AlgoWeb\ODataMetadata\Atom\Category[] $category |
||
30 | */ |
||
31 | private $category = array( |
||
32 | |||
33 | ); |
||
34 | |||
35 | /** |
||
36 | * @property \AlgoWeb\ODataMetadata\Atom\Contributor[] $contributor |
||
37 | */ |
||
38 | private $contributor = array( |
||
39 | |||
40 | ); |
||
41 | |||
42 | /** |
||
43 | * @property \AlgoWeb\ODataMetadata\Atom\Generator[] $generator |
||
44 | */ |
||
45 | private $generator = array( |
||
46 | |||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * @property \AlgoWeb\ODataMetadata\Atom\Icon[] $icon |
||
51 | */ |
||
52 | private $icon = array( |
||
53 | |||
54 | ); |
||
55 | |||
56 | /** |
||
57 | * @property \AlgoWeb\ODataMetadata\Atom\Id[] $id |
||
58 | */ |
||
59 | private $id = array( |
||
60 | |||
61 | ); |
||
62 | |||
63 | /** |
||
64 | * @property \AlgoWeb\ODataMetadata\Atom\Link[] $link |
||
65 | */ |
||
66 | private $link = array( |
||
67 | |||
68 | ); |
||
69 | |||
70 | /** |
||
71 | * @property \AlgoWeb\ODataMetadata\Atom\Logo[] $logo |
||
72 | */ |
||
73 | private $logo = array( |
||
74 | |||
75 | ); |
||
76 | |||
77 | /** |
||
78 | * @property \AlgoWeb\ODataMetadata\Atom\Rights[] $rights |
||
79 | */ |
||
80 | private $rights = array( |
||
81 | |||
82 | ); |
||
83 | |||
84 | /** |
||
85 | * @property \AlgoWeb\ODataMetadata\Atom\Subtitle[] $subtitle |
||
86 | */ |
||
87 | private $subtitle = array( |
||
88 | |||
89 | ); |
||
90 | |||
91 | /** |
||
92 | * @property \AlgoWeb\ODataMetadata\Atom\Title[] $title |
||
93 | */ |
||
94 | private $title = array( |
||
95 | |||
96 | ); |
||
97 | |||
98 | /** |
||
99 | * @property \AlgoWeb\ODataMetadata\Atom\Updated[] $updated |
||
100 | */ |
||
101 | private $updated = array( |
||
102 | |||
103 | ); |
||
104 | |||
105 | /** |
||
106 | * Gets as base |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getBase() |
||
114 | |||
115 | /** |
||
116 | * Sets a new base |
||
117 | * |
||
118 | * @param string $base |
||
119 | * @return self |
||
120 | */ |
||
121 | public function setBase($base) |
||
126 | |||
127 | /** |
||
128 | * Gets as lang |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getLang() |
||
136 | |||
137 | /** |
||
138 | * Sets a new lang |
||
139 | * |
||
140 | * @param string $lang |
||
141 | * @return self |
||
142 | */ |
||
143 | public function setLang($lang) |
||
148 | |||
149 | /** |
||
150 | * Adds as author |
||
151 | * |
||
152 | * @return self |
||
153 | * @param \AlgoWeb\ODataMetadata\Atom\Author $author |
||
154 | */ |
||
155 | public function addToAuthor(\AlgoWeb\ODataMetadata\Atom\Author $author) |
||
160 | |||
161 | /** |
||
162 | * isset author |
||
163 | * |
||
164 | * @param scalar $index |
||
165 | * @return boolean |
||
166 | */ |
||
167 | public function issetAuthor($index) |
||
171 | |||
172 | /** |
||
173 | * unset author |
||
174 | * |
||
175 | * @param scalar $index |
||
176 | * @return void |
||
177 | */ |
||
178 | public function unsetAuthor($index) |
||
182 | |||
183 | /** |
||
184 | * Gets as author |
||
185 | * |
||
186 | * @return \AlgoWeb\ODataMetadata\Atom\Author[] |
||
187 | */ |
||
188 | public function getAuthor() |
||
192 | |||
193 | /** |
||
194 | * Sets a new author |
||
195 | * |
||
196 | * @param \AlgoWeb\ODataMetadata\Atom\Author[] $author |
||
197 | * @return self |
||
198 | */ |
||
199 | public function setAuthor(array $author) |
||
204 | |||
205 | /** |
||
206 | * Adds as category |
||
207 | * |
||
208 | * @return self |
||
209 | * @param \AlgoWeb\ODataMetadata\Atom\Category $category |
||
210 | */ |
||
211 | public function addToCategory(\AlgoWeb\ODataMetadata\Atom\Category $category) |
||
216 | |||
217 | /** |
||
218 | * isset category |
||
219 | * |
||
220 | * @param scalar $index |
||
221 | * @return boolean |
||
222 | */ |
||
223 | public function issetCategory($index) |
||
227 | |||
228 | /** |
||
229 | * unset category |
||
230 | * |
||
231 | * @param scalar $index |
||
232 | * @return void |
||
233 | */ |
||
234 | public function unsetCategory($index) |
||
238 | |||
239 | /** |
||
240 | * Gets as category |
||
241 | * |
||
242 | * @return \AlgoWeb\ODataMetadata\Atom\Category[] |
||
243 | */ |
||
244 | public function getCategory() |
||
248 | |||
249 | /** |
||
250 | * Sets a new category |
||
251 | * |
||
252 | * @param \AlgoWeb\ODataMetadata\Atom\Category[] $category |
||
253 | * @return self |
||
254 | */ |
||
255 | public function setCategory(array $category) |
||
260 | |||
261 | /** |
||
262 | * Adds as contributor |
||
263 | * |
||
264 | * @return self |
||
265 | * @param \AlgoWeb\ODataMetadata\Atom\Contributor $contributor |
||
266 | */ |
||
267 | public function addToContributor(\AlgoWeb\ODataMetadata\Atom\Contributor $contributor) |
||
272 | |||
273 | /** |
||
274 | * isset contributor |
||
275 | * |
||
276 | * @param scalar $index |
||
277 | * @return boolean |
||
278 | */ |
||
279 | public function issetContributor($index) |
||
283 | |||
284 | /** |
||
285 | * unset contributor |
||
286 | * |
||
287 | * @param scalar $index |
||
288 | * @return void |
||
289 | */ |
||
290 | public function unsetContributor($index) |
||
294 | |||
295 | /** |
||
296 | * Gets as contributor |
||
297 | * |
||
298 | * @return \AlgoWeb\ODataMetadata\Atom\Contributor[] |
||
299 | */ |
||
300 | public function getContributor() |
||
304 | |||
305 | /** |
||
306 | * Sets a new contributor |
||
307 | * |
||
308 | * @param \AlgoWeb\ODataMetadata\Atom\Contributor[] $contributor |
||
309 | * @return self |
||
310 | */ |
||
311 | public function setContributor(array $contributor) |
||
316 | |||
317 | /** |
||
318 | * Adds as generator |
||
319 | * |
||
320 | * @return self |
||
321 | * @param \AlgoWeb\ODataMetadata\Atom\Generator $generator |
||
322 | */ |
||
323 | public function addToGenerator(\AlgoWeb\ODataMetadata\Atom\Generator $generator) |
||
328 | |||
329 | /** |
||
330 | * isset generator |
||
331 | * |
||
332 | * @param scalar $index |
||
333 | * @return boolean |
||
334 | */ |
||
335 | public function issetGenerator($index) |
||
339 | |||
340 | /** |
||
341 | * unset generator |
||
342 | * |
||
343 | * @param scalar $index |
||
344 | * @return void |
||
345 | */ |
||
346 | public function unsetGenerator($index) |
||
350 | |||
351 | /** |
||
352 | * Gets as generator |
||
353 | * |
||
354 | * @return \AlgoWeb\ODataMetadata\Atom\Generator[] |
||
355 | */ |
||
356 | public function getGenerator() |
||
360 | |||
361 | /** |
||
362 | * Sets a new generator |
||
363 | * |
||
364 | * @param \AlgoWeb\ODataMetadata\Atom\Generator[] $generator |
||
365 | * @return self |
||
366 | */ |
||
367 | public function setGenerator(array $generator) |
||
372 | |||
373 | /** |
||
374 | * Adds as icon |
||
375 | * |
||
376 | * @return self |
||
377 | * @param \AlgoWeb\ODataMetadata\Atom\Icon $icon |
||
378 | */ |
||
379 | public function addToIcon(\AlgoWeb\ODataMetadata\Atom\Icon $icon) |
||
384 | |||
385 | /** |
||
386 | * isset icon |
||
387 | * |
||
388 | * @param scalar $index |
||
389 | * @return boolean |
||
390 | */ |
||
391 | public function issetIcon($index) |
||
395 | |||
396 | /** |
||
397 | * unset icon |
||
398 | * |
||
399 | * @param scalar $index |
||
400 | * @return void |
||
401 | */ |
||
402 | public function unsetIcon($index) |
||
406 | |||
407 | /** |
||
408 | * Gets as icon |
||
409 | * |
||
410 | * @return \AlgoWeb\ODataMetadata\Atom\Icon[] |
||
411 | */ |
||
412 | public function getIcon() |
||
416 | |||
417 | /** |
||
418 | * Sets a new icon |
||
419 | * |
||
420 | * @param \AlgoWeb\ODataMetadata\Atom\Icon[] $icon |
||
421 | * @return self |
||
422 | */ |
||
423 | public function setIcon(array $icon) |
||
428 | |||
429 | /** |
||
430 | * Adds as id |
||
431 | * |
||
432 | * @return self |
||
433 | * @param \AlgoWeb\ODataMetadata\Atom\Id $id |
||
434 | */ |
||
435 | public function addToId(\AlgoWeb\ODataMetadata\Atom\Id $id) |
||
440 | |||
441 | /** |
||
442 | * isset id |
||
443 | * |
||
444 | * @param scalar $index |
||
445 | * @return boolean |
||
446 | */ |
||
447 | public function issetId($index) |
||
451 | |||
452 | /** |
||
453 | * unset id |
||
454 | * |
||
455 | * @param scalar $index |
||
456 | * @return void |
||
457 | */ |
||
458 | public function unsetId($index) |
||
462 | |||
463 | /** |
||
464 | * Gets as id |
||
465 | * |
||
466 | * @return \AlgoWeb\ODataMetadata\Atom\Id[] |
||
467 | */ |
||
468 | public function getId() |
||
472 | |||
473 | /** |
||
474 | * Sets a new id |
||
475 | * |
||
476 | * @param \AlgoWeb\ODataMetadata\Atom\Id[] $id |
||
477 | * @return self |
||
478 | */ |
||
479 | public function setId(array $id) |
||
484 | |||
485 | /** |
||
486 | * Adds as link |
||
487 | * |
||
488 | * @return self |
||
489 | * @param \AlgoWeb\ODataMetadata\Atom\Link $link |
||
490 | */ |
||
491 | public function addToLink(\AlgoWeb\ODataMetadata\Atom\Link $link) |
||
496 | |||
497 | /** |
||
498 | * isset link |
||
499 | * |
||
500 | * @param scalar $index |
||
501 | * @return boolean |
||
502 | */ |
||
503 | public function issetLink($index) |
||
507 | |||
508 | /** |
||
509 | * unset link |
||
510 | * |
||
511 | * @param scalar $index |
||
512 | * @return void |
||
513 | */ |
||
514 | public function unsetLink($index) |
||
518 | |||
519 | /** |
||
520 | * Gets as link |
||
521 | * |
||
522 | * @return \AlgoWeb\ODataMetadata\Atom\Link[] |
||
523 | */ |
||
524 | public function getLink() |
||
528 | |||
529 | /** |
||
530 | * Sets a new link |
||
531 | * |
||
532 | * @param \AlgoWeb\ODataMetadata\Atom\Link[] $link |
||
533 | * @return self |
||
534 | */ |
||
535 | public function setLink(array $link) |
||
540 | |||
541 | /** |
||
542 | * Adds as logo |
||
543 | * |
||
544 | * @return self |
||
545 | * @param \AlgoWeb\ODataMetadata\Atom\Logo $logo |
||
546 | */ |
||
547 | public function addToLogo(\AlgoWeb\ODataMetadata\Atom\Logo $logo) |
||
552 | |||
553 | /** |
||
554 | * isset logo |
||
555 | * |
||
556 | * @param scalar $index |
||
557 | * @return boolean |
||
558 | */ |
||
559 | public function issetLogo($index) |
||
563 | |||
564 | /** |
||
565 | * unset logo |
||
566 | * |
||
567 | * @param scalar $index |
||
568 | * @return void |
||
569 | */ |
||
570 | public function unsetLogo($index) |
||
574 | |||
575 | /** |
||
576 | * Gets as logo |
||
577 | * |
||
578 | * @return \AlgoWeb\ODataMetadata\Atom\Logo[] |
||
579 | */ |
||
580 | public function getLogo() |
||
584 | |||
585 | /** |
||
586 | * Sets a new logo |
||
587 | * |
||
588 | * @param \AlgoWeb\ODataMetadata\Atom\Logo[] $logo |
||
589 | * @return self |
||
590 | */ |
||
591 | public function setLogo(array $logo) |
||
596 | |||
597 | /** |
||
598 | * Adds as rights |
||
599 | * |
||
600 | * @return self |
||
601 | * @param \AlgoWeb\ODataMetadata\Atom\Rights $rights |
||
602 | */ |
||
603 | public function addToRights(\AlgoWeb\ODataMetadata\Atom\Rights $rights) |
||
608 | |||
609 | /** |
||
610 | * isset rights |
||
611 | * |
||
612 | * @param scalar $index |
||
613 | * @return boolean |
||
614 | */ |
||
615 | public function issetRights($index) |
||
619 | |||
620 | /** |
||
621 | * unset rights |
||
622 | * |
||
623 | * @param scalar $index |
||
624 | * @return void |
||
625 | */ |
||
626 | public function unsetRights($index) |
||
630 | |||
631 | /** |
||
632 | * Gets as rights |
||
633 | * |
||
634 | * @return \AlgoWeb\ODataMetadata\Atom\Rights[] |
||
635 | */ |
||
636 | public function getRights() |
||
640 | |||
641 | /** |
||
642 | * Sets a new rights |
||
643 | * |
||
644 | * @param \AlgoWeb\ODataMetadata\Atom\Rights[] $rights |
||
645 | * @return self |
||
646 | */ |
||
647 | public function setRights(array $rights) |
||
652 | |||
653 | /** |
||
654 | * Adds as subtitle |
||
655 | * |
||
656 | * @return self |
||
657 | * @param \AlgoWeb\ODataMetadata\Atom\Subtitle $subtitle |
||
658 | */ |
||
659 | public function addToSubtitle(\AlgoWeb\ODataMetadata\Atom\Subtitle $subtitle) |
||
664 | |||
665 | /** |
||
666 | * isset subtitle |
||
667 | * |
||
668 | * @param scalar $index |
||
669 | * @return boolean |
||
670 | */ |
||
671 | public function issetSubtitle($index) |
||
675 | |||
676 | /** |
||
677 | * unset subtitle |
||
678 | * |
||
679 | * @param scalar $index |
||
680 | * @return void |
||
681 | */ |
||
682 | public function unsetSubtitle($index) |
||
686 | |||
687 | /** |
||
688 | * Gets as subtitle |
||
689 | * |
||
690 | * @return \AlgoWeb\ODataMetadata\Atom\Subtitle[] |
||
691 | */ |
||
692 | public function getSubtitle() |
||
696 | |||
697 | /** |
||
698 | * Sets a new subtitle |
||
699 | * |
||
700 | * @param \AlgoWeb\ODataMetadata\Atom\Subtitle[] $subtitle |
||
701 | * @return self |
||
702 | */ |
||
703 | public function setSubtitle(array $subtitle) |
||
708 | |||
709 | /** |
||
710 | * Adds as title |
||
711 | * |
||
712 | * @return self |
||
713 | * @param \AlgoWeb\ODataMetadata\Atom\Title $title |
||
714 | */ |
||
715 | public function addToTitle(\AlgoWeb\ODataMetadata\Atom\Title $title) |
||
720 | |||
721 | /** |
||
722 | * isset title |
||
723 | * |
||
724 | * @param scalar $index |
||
725 | * @return boolean |
||
726 | */ |
||
727 | public function issetTitle($index) |
||
731 | |||
732 | /** |
||
733 | * unset title |
||
734 | * |
||
735 | * @param scalar $index |
||
736 | * @return void |
||
737 | */ |
||
738 | public function unsetTitle($index) |
||
742 | |||
743 | /** |
||
744 | * Gets as title |
||
745 | * |
||
746 | * @return \AlgoWeb\ODataMetadata\Atom\Title[] |
||
747 | */ |
||
748 | public function getTitle() |
||
752 | |||
753 | /** |
||
754 | * Sets a new title |
||
755 | * |
||
756 | * @param \AlgoWeb\ODataMetadata\Atom\Title[] $title |
||
757 | * @return self |
||
758 | */ |
||
759 | public function setTitle(array $title) |
||
764 | |||
765 | /** |
||
766 | * Adds as updated |
||
767 | * |
||
768 | * @return self |
||
769 | * @param \AlgoWeb\ODataMetadata\Atom\Updated $updated |
||
770 | */ |
||
771 | public function addToUpdated(\AlgoWeb\ODataMetadata\Atom\Updated $updated) |
||
776 | |||
777 | /** |
||
778 | * isset updated |
||
779 | * |
||
780 | * @param scalar $index |
||
781 | * @return boolean |
||
782 | */ |
||
783 | public function issetUpdated($index) |
||
787 | |||
788 | /** |
||
789 | * unset updated |
||
790 | * |
||
791 | * @param scalar $index |
||
792 | * @return void |
||
793 | */ |
||
794 | public function unsetUpdated($index) |
||
798 | |||
799 | /** |
||
800 | * Gets as updated |
||
801 | * |
||
802 | * @return \AlgoWeb\ODataMetadata\Atom\Updated[] |
||
803 | */ |
||
804 | public function getUpdated() |
||
808 | |||
809 | /** |
||
810 | * Sets a new updated |
||
811 | * |
||
812 | * @param \AlgoWeb\ODataMetadata\Atom\Updated[] $updated |
||
813 | * @return self |
||
814 | */ |
||
815 | public function setUpdated(array $updated) |
||
820 | } |
||
821 |
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.