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 |
||
13 | trait TFacetAttributesTrait |
||
14 | { |
||
15 | use IsOKToolboxTrait, TMaxLengthFacetTrait, TIsFixedLengthFacetTrait, TPrecisionFacetTrait, TScaleFacetTrait, |
||
16 | TIsUnicodeFacetTrait, TSridFacetTrait; |
||
17 | /** |
||
18 | * @property boolean $nullable |
||
19 | */ |
||
20 | private $nullable = null; |
||
21 | |||
22 | /** |
||
23 | * @property string $defaultValue |
||
24 | */ |
||
25 | private $defaultValue = null; |
||
26 | |||
27 | /** |
||
28 | * @property string $maxLength |
||
29 | */ |
||
30 | private $maxLength = null; |
||
31 | |||
32 | /** |
||
33 | * @property boolean $fixedLength |
||
34 | */ |
||
35 | private $fixedLength = null; |
||
36 | |||
37 | /** |
||
38 | * @property integer $precision |
||
39 | */ |
||
40 | private $precision = null; |
||
41 | |||
42 | /** |
||
43 | * @property integer $scale |
||
44 | */ |
||
45 | private $scale = null; |
||
46 | |||
47 | /** |
||
48 | * @property boolean $unicode |
||
49 | */ |
||
50 | private $unicode = null; |
||
51 | |||
52 | /** |
||
53 | * @property string $collation |
||
54 | */ |
||
55 | private $collation = null; |
||
56 | |||
57 | /** |
||
58 | * @property string $sRID |
||
59 | */ |
||
60 | private $sRID = null; |
||
61 | |||
62 | /** |
||
63 | * Gets as nullable |
||
64 | * |
||
65 | * @return boolean |
||
66 | */ |
||
67 | public function getNullable() |
||
71 | |||
72 | /** |
||
73 | * Sets a new nullable |
||
74 | * |
||
75 | * @param boolean $nullable |
||
76 | * @return self |
||
77 | */ |
||
78 | public function setNullable($nullable) |
||
83 | |||
84 | /** |
||
85 | * Gets as defaultValue |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getDefaultValue() |
||
93 | |||
94 | /** |
||
95 | * Sets a new defaultValue |
||
96 | * |
||
97 | * @param string $defaultValue |
||
98 | * @return self |
||
99 | */ |
||
100 | public function setDefaultValue($defaultValue) |
||
105 | |||
106 | /** |
||
107 | * Gets as maxLength |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getMaxLength() |
||
115 | |||
116 | /** |
||
117 | * Sets a new maxLength |
||
118 | * |
||
119 | * @param string $maxLength |
||
120 | * @return self |
||
121 | */ |
||
122 | public function setMaxLength($maxLength) |
||
127 | |||
128 | /** |
||
129 | * Gets as fixedLength |
||
130 | * |
||
131 | * @return boolean |
||
132 | */ |
||
133 | public function getFixedLength() |
||
137 | |||
138 | /** |
||
139 | * Sets a new fixedLength |
||
140 | * |
||
141 | * @param boolean $fixedLength |
||
142 | * @return self |
||
143 | */ |
||
144 | public function setFixedLength($fixedLength) |
||
149 | |||
150 | /** |
||
151 | * Gets as precision |
||
152 | * |
||
153 | * @return integer |
||
154 | */ |
||
155 | public function getPrecision() |
||
159 | |||
160 | /** |
||
161 | * Sets a new precision |
||
162 | * |
||
163 | * @param integer $precision |
||
164 | * @return self |
||
165 | */ |
||
166 | public function setPrecision($precision) |
||
171 | |||
172 | /** |
||
173 | * Gets as scale |
||
174 | * |
||
175 | * @return integer |
||
176 | */ |
||
177 | public function getScale() |
||
181 | |||
182 | /** |
||
183 | * Sets a new scale |
||
184 | * |
||
185 | * @param integer $scale |
||
186 | * @return self |
||
187 | */ |
||
188 | public function setScale($scale) |
||
193 | |||
194 | /** |
||
195 | * Gets as unicode |
||
196 | * |
||
197 | * @return boolean |
||
198 | */ |
||
199 | public function getUnicode() |
||
203 | |||
204 | /** |
||
205 | * Sets a new unicode |
||
206 | * |
||
207 | * @param boolean $unicode |
||
208 | * @return self |
||
209 | */ |
||
210 | public function setUnicode($unicode) |
||
215 | |||
216 | /** |
||
217 | * Gets as collation |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | public function getCollation() |
||
225 | |||
226 | /** |
||
227 | * Sets a new collation |
||
228 | * |
||
229 | * @param string $collation |
||
230 | * @return self |
||
231 | */ |
||
232 | public function setCollation($collation) |
||
237 | |||
238 | /** |
||
239 | * Gets as sRID |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | public function getSRID() |
||
247 | |||
248 | /** |
||
249 | * Sets a new sRID |
||
250 | * |
||
251 | * @param string $sRID |
||
252 | * @return self |
||
253 | */ |
||
254 | public function setSRID($sRID) |
||
259 | |||
260 | public function isTFacetAttributesTraitValid(&$msg = null) |
||
297 | } |
||
298 |
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.