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 TTypeDefinitionType |
|
|
|
|||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @property string $name |
||
| 16 | */ |
||
| 17 | private $name = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @property string $underlyingType |
||
| 21 | */ |
||
| 22 | private $underlyingType = null; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @property string $maxLength |
||
| 26 | */ |
||
| 27 | private $maxLength = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @property integer $precision |
||
| 31 | */ |
||
| 32 | private $precision = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @property string $scale |
||
| 36 | */ |
||
| 37 | private $scale = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @property string $sRID |
||
| 41 | */ |
||
| 42 | private $sRID = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @property boolean $unicode |
||
| 46 | */ |
||
| 47 | private $unicode = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @property \MetadataV4\edm\Annotation[] $annotation |
||
| 51 | */ |
||
| 52 | private $annotation = array( |
||
| 53 | |||
| 54 | ); |
||
| 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 underlyingType |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function getUnderlyingType() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Sets a new underlyingType |
||
| 90 | * |
||
| 91 | * @param string $underlyingType |
||
| 92 | * @return self |
||
| 93 | */ |
||
| 94 | public function setUnderlyingType($underlyingType) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Gets as maxLength |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public function getMaxLength() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Sets a new maxLength |
||
| 112 | * |
||
| 113 | * @param string $maxLength |
||
| 114 | * @return self |
||
| 115 | */ |
||
| 116 | public function setMaxLength($maxLength) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Gets as precision |
||
| 124 | * |
||
| 125 | * @return integer |
||
| 126 | */ |
||
| 127 | public function getPrecision() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Sets a new precision |
||
| 134 | * |
||
| 135 | * @param integer $precision |
||
| 136 | * @return self |
||
| 137 | */ |
||
| 138 | public function setPrecision($precision) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Gets as scale |
||
| 146 | * |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | public function getScale() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Sets a new scale |
||
| 156 | * |
||
| 157 | * @param string $scale |
||
| 158 | * @return self |
||
| 159 | */ |
||
| 160 | public function setScale($scale) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Gets as sRID |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | public function getSRID() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Sets a new sRID |
||
| 178 | * |
||
| 179 | * @param string $sRID |
||
| 180 | * @return self |
||
| 181 | */ |
||
| 182 | public function setSRID($sRID) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Gets as unicode |
||
| 190 | * |
||
| 191 | * @return boolean |
||
| 192 | */ |
||
| 193 | public function getUnicode() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Sets a new unicode |
||
| 200 | * |
||
| 201 | * @param boolean $unicode |
||
| 202 | * @return self |
||
| 203 | */ |
||
| 204 | public function setUnicode($unicode) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Adds as annotation |
||
| 212 | * |
||
| 213 | * @return self |
||
| 214 | * @param \MetadataV4\edm\Annotation $annotation |
||
| 215 | */ |
||
| 216 | public function addToAnnotation(\MetadataV4\edm\Annotation $annotation) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * isset annotation |
||
| 224 | * |
||
| 225 | * @param scalar $index |
||
| 226 | * @return boolean |
||
| 227 | */ |
||
| 228 | public function issetAnnotation($index) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * unset annotation |
||
| 235 | * |
||
| 236 | * @param scalar $index |
||
| 237 | * @return void |
||
| 238 | */ |
||
| 239 | public function unsetAnnotation($index) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Gets as annotation |
||
| 246 | * |
||
| 247 | * @return \MetadataV4\edm\Annotation[] |
||
| 248 | */ |
||
| 249 | public function getAnnotation() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Sets a new annotation |
||
| 256 | * |
||
| 257 | * @param \MetadataV4\edm\Annotation[] $annotation |
||
| 258 | * @return self |
||
| 259 | */ |
||
| 260 | public function setAnnotation(array $annotation) |
||
| 265 | } |
||
| 266 |
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.