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 |
||
18 | class TNavigationPropertyType extends IsOK |
||
19 | { |
||
20 | use IsOKToolboxTrait, |
||
21 | GEmptyElementExtensibilityTrait, |
||
22 | TQualifiedNameTrait, |
||
23 | TSimpleIdentifierTrait, |
||
24 | AccessTypeTraits; |
||
25 | |||
26 | /** |
||
27 | * @property string $name |
||
28 | */ |
||
29 | private $name = null; |
||
30 | |||
31 | /** |
||
32 | * @property string $relationship |
||
33 | */ |
||
34 | private $relationship = null; |
||
35 | |||
36 | /** |
||
37 | * @property string $toRole |
||
38 | */ |
||
39 | private $toRole = null; |
||
40 | |||
41 | /** |
||
42 | * @property string $fromRole |
||
43 | */ |
||
44 | private $fromRole = null; |
||
45 | |||
46 | /** |
||
47 | * @property string $getterAccess |
||
48 | */ |
||
49 | private $getterAccess = null; |
||
50 | |||
51 | /** |
||
52 | * @property string $setterAccess |
||
53 | */ |
||
54 | private $setterAccess = null; |
||
55 | |||
56 | /** |
||
57 | * Gets as name |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getName() |
||
65 | |||
66 | /** |
||
67 | * Sets a new name |
||
68 | * |
||
69 | * @param string $name |
||
70 | * @return self |
||
71 | */ |
||
72 | public function setName($name) |
||
77 | |||
78 | /** |
||
79 | * Gets as relationship |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getRelationship() |
||
87 | |||
88 | /** |
||
89 | * Sets a new relationship |
||
90 | * |
||
91 | * @param string $relationship |
||
92 | * @return self |
||
93 | */ |
||
94 | public function setRelationship($relationship) |
||
99 | |||
100 | /** |
||
101 | * Gets as toRole |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getToRole() |
||
109 | |||
110 | /** |
||
111 | * Sets a new toRole |
||
112 | * |
||
113 | * @param string $toRole |
||
114 | * @return self |
||
115 | */ |
||
116 | public function setToRole($toRole) |
||
121 | |||
122 | /** |
||
123 | * Gets as fromRole |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | public function getFromRole() |
||
131 | |||
132 | /** |
||
133 | * Sets a new fromRole |
||
134 | * |
||
135 | * @param string $fromRole |
||
136 | * @return self |
||
137 | */ |
||
138 | public function setFromRole($fromRole) |
||
143 | |||
144 | /** |
||
145 | * Gets as getterAccess |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | public function getGetterAccess() |
||
153 | |||
154 | /** |
||
155 | * Sets a new getterAccess |
||
156 | * |
||
157 | * @param string $getterAccess |
||
158 | * @return self |
||
159 | */ |
||
160 | public function setGetterAccess($getterAccess) |
||
165 | |||
166 | /** |
||
167 | * Gets as setterAccess |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getSetterAccess() |
||
175 | |||
176 | /** |
||
177 | * Sets a new setterAccess |
||
178 | * |
||
179 | * @param string $setterAccess |
||
180 | * @return self |
||
181 | */ |
||
182 | public function setSetterAccess($setterAccess) |
||
187 | |||
188 | public function isOK(&$msg = null) |
||
219 | } |
||
220 |
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.