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:
1 | <?php |
||
15 | class TIncludeAnnotationsType extends IsOK |
||
16 | { |
||
17 | use TNamespaceNameTrait, TSimpleIdentifierTrait; |
||
18 | |||
19 | /** |
||
20 | * @property string $termNamespace |
||
21 | */ |
||
22 | private $termNamespace = null; |
||
23 | |||
24 | /** |
||
25 | * @property string $qualifier |
||
26 | */ |
||
27 | private $qualifier = null; |
||
28 | |||
29 | /** |
||
30 | * @property string $targetNamespace |
||
31 | */ |
||
32 | private $targetNamespace = null; |
||
33 | |||
34 | /** |
||
35 | * Gets as termNamespace |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | public function getTermNamespace() |
||
43 | |||
44 | /** |
||
45 | * Sets a new termNamespace |
||
46 | * |
||
47 | * @param string $termNamespace |
||
48 | * @return self |
||
49 | */ |
||
50 | public function setTermNamespace($termNamespace) |
||
55 | |||
56 | /** |
||
57 | * Gets as qualifier |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getQualifier() |
||
65 | |||
66 | /** |
||
67 | * Sets a new qualifier |
||
68 | * |
||
69 | * @param string $qualifier |
||
70 | * @return self |
||
71 | */ |
||
72 | public function setQualifier($qualifier) |
||
77 | |||
78 | /** |
||
79 | * Gets as targetNamespace |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getTargetNamespace() |
||
87 | |||
88 | /** |
||
89 | * Sets a new targetNamespace |
||
90 | * |
||
91 | * @param string $targetNamespace |
||
92 | * @return self |
||
93 | */ |
||
94 | public function setTargetNamespace($targetNamespace) |
||
99 | |||
100 | protected function isOK(&$msg) |
||
134 | } |
||
135 |
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.