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 |
||
| 11 | View Code Duplication | class TFunctionParameterType |
|
|
|
|||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @property string $name |
||
| 16 | */ |
||
| 17 | private $name = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @property string $type |
||
| 21 | */ |
||
| 22 | private $type = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @property boolean $nullable |
||
| 26 | */ |
||
| 27 | private $nullable = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @property string $defaultValue |
||
| 31 | */ |
||
| 32 | private $defaultValue = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @property string $maxLength |
||
| 36 | */ |
||
| 37 | private $maxLength = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @property boolean $fixedLength |
||
| 41 | */ |
||
| 42 | private $fixedLength = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @property integer $precision |
||
| 46 | */ |
||
| 47 | private $precision = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @property integer $scale |
||
| 51 | */ |
||
| 52 | private $scale = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @property boolean $unicode |
||
| 56 | */ |
||
| 57 | private $unicode = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @property string $collation |
||
| 61 | */ |
||
| 62 | private $collation = null; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @property string $sRID |
||
| 66 | */ |
||
| 67 | private $sRID = null; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @property \MetadataV3\edm\TCollectionTypeType $collectionType |
||
| 71 | */ |
||
| 72 | private $collectionType = null; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @property \MetadataV3\edm\TReferenceTypeType $referenceType |
||
| 76 | */ |
||
| 77 | private $referenceType = null; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @property \MetadataV3\edm\TPropertyType[] $rowType |
||
| 81 | */ |
||
| 82 | private $rowType = null; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Gets as name |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function getName() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Sets a new name |
||
| 96 | * |
||
| 97 | * @param string $name |
||
| 98 | * @return self |
||
| 99 | */ |
||
| 100 | public function setName($name) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Gets as type |
||
| 108 | * |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public function getType() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Sets a new type |
||
| 118 | * |
||
| 119 | * @param string $type |
||
| 120 | * @return self |
||
| 121 | */ |
||
| 122 | public function setType($type) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Gets as nullable |
||
| 130 | * |
||
| 131 | * @return boolean |
||
| 132 | */ |
||
| 133 | public function getNullable() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Sets a new nullable |
||
| 140 | * |
||
| 141 | * @param boolean $nullable |
||
| 142 | * @return self |
||
| 143 | */ |
||
| 144 | public function setNullable($nullable) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Gets as defaultValue |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | public function getDefaultValue() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Sets a new defaultValue |
||
| 162 | * |
||
| 163 | * @param string $defaultValue |
||
| 164 | * @return self |
||
| 165 | */ |
||
| 166 | public function setDefaultValue($defaultValue) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Gets as maxLength |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function getMaxLength() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Sets a new maxLength |
||
| 184 | * |
||
| 185 | * @param string $maxLength |
||
| 186 | * @return self |
||
| 187 | */ |
||
| 188 | public function setMaxLength($maxLength) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Gets as fixedLength |
||
| 196 | * |
||
| 197 | * @return boolean |
||
| 198 | */ |
||
| 199 | public function getFixedLength() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Sets a new fixedLength |
||
| 206 | * |
||
| 207 | * @param boolean $fixedLength |
||
| 208 | * @return self |
||
| 209 | */ |
||
| 210 | public function setFixedLength($fixedLength) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Gets as precision |
||
| 218 | * |
||
| 219 | * @return integer |
||
| 220 | */ |
||
| 221 | public function getPrecision() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Sets a new precision |
||
| 228 | * |
||
| 229 | * @param integer $precision |
||
| 230 | * @return self |
||
| 231 | */ |
||
| 232 | public function setPrecision($precision) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Gets as scale |
||
| 240 | * |
||
| 241 | * @return integer |
||
| 242 | */ |
||
| 243 | public function getScale() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Sets a new scale |
||
| 250 | * |
||
| 251 | * @param integer $scale |
||
| 252 | * @return self |
||
| 253 | */ |
||
| 254 | public function setScale($scale) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Gets as unicode |
||
| 262 | * |
||
| 263 | * @return boolean |
||
| 264 | */ |
||
| 265 | public function getUnicode() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Sets a new unicode |
||
| 272 | * |
||
| 273 | * @param boolean $unicode |
||
| 274 | * @return self |
||
| 275 | */ |
||
| 276 | public function setUnicode($unicode) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Gets as collation |
||
| 284 | * |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | public function getCollation() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Sets a new collation |
||
| 294 | * |
||
| 295 | * @param string $collation |
||
| 296 | * @return self |
||
| 297 | */ |
||
| 298 | public function setCollation($collation) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Gets as sRID |
||
| 306 | * |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public function getSRID() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Sets a new sRID |
||
| 316 | * |
||
| 317 | * @param string $sRID |
||
| 318 | * @return self |
||
| 319 | */ |
||
| 320 | public function setSRID($sRID) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Gets as collectionType |
||
| 328 | * |
||
| 329 | * @return \MetadataV3\edm\TCollectionTypeType |
||
| 330 | */ |
||
| 331 | public function getCollectionType() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Sets a new collectionType |
||
| 338 | * |
||
| 339 | * @param \MetadataV3\edm\TCollectionTypeType $collectionType |
||
| 340 | * @return self |
||
| 341 | */ |
||
| 342 | public function setCollectionType(\MetadataV3\edm\TCollectionTypeType $collectionType) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Gets as referenceType |
||
| 350 | * |
||
| 351 | * @return \MetadataV3\edm\TReferenceTypeType |
||
| 352 | */ |
||
| 353 | public function getReferenceType() |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Sets a new referenceType |
||
| 360 | * |
||
| 361 | * @param \MetadataV3\edm\TReferenceTypeType $referenceType |
||
| 362 | * @return self |
||
| 363 | */ |
||
| 364 | public function setReferenceType(\MetadataV3\edm\TReferenceTypeType $referenceType) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Adds as property |
||
| 372 | * |
||
| 373 | * @return self |
||
| 374 | * @param \MetadataV3\edm\TPropertyType $property |
||
| 375 | */ |
||
| 376 | public function addToRowType(\MetadataV3\edm\TPropertyType $property) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * isset rowType |
||
| 384 | * |
||
| 385 | * @param scalar $index |
||
| 386 | * @return boolean |
||
| 387 | */ |
||
| 388 | public function issetRowType($index) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * unset rowType |
||
| 395 | * |
||
| 396 | * @param scalar $index |
||
| 397 | * @return void |
||
| 398 | */ |
||
| 399 | public function unsetRowType($index) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Gets as rowType |
||
| 406 | * |
||
| 407 | * @return \MetadataV3\edm\TPropertyType[] |
||
| 408 | */ |
||
| 409 | public function getRowType() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Sets a new rowType |
||
| 416 | * |
||
| 417 | * @param \MetadataV3\edm\TPropertyType[] $rowType |
||
| 418 | * @return self |
||
| 419 | */ |
||
| 420 | public function setRowType(array $rowType) |
||
| 425 | } |
||
| 426 |
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.