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 | class Builder extends Version |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Removes the build metadata identifiers. |
||
| 17 | * |
||
| 18 | * @return Builder The Version builder. |
||
| 19 | */ |
||
| 20 | public function clearBuild() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Removes the pre-release version identifiers. |
||
| 27 | * |
||
| 28 | * @return Builder The Version builder. |
||
| 29 | */ |
||
| 30 | public function clearPreRelease() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Creates a new Version builder. |
||
| 37 | * |
||
| 38 | * @return Builder The Version builder. |
||
| 39 | */ |
||
| 40 | public static function create() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Returns a readonly Version instance. |
||
| 47 | * |
||
| 48 | * @return Version The readonly Version instance. |
||
| 49 | */ |
||
| 50 | public function getVersion() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Imports the version components. |
||
| 63 | * |
||
| 64 | * @param array $components The components. |
||
| 65 | * |
||
| 66 | * @return Builder The Version builder. |
||
| 67 | */ |
||
| 68 | public function importComponents(array $components) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Imports the version string representation. |
||
| 105 | * |
||
| 106 | * @param string $version The string representation. |
||
| 107 | * |
||
| 108 | * @return Builder The Version builder. |
||
| 109 | */ |
||
| 110 | public function importString($version) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Imports an existing Version instance. |
||
| 117 | * |
||
| 118 | * @param Version $version A Version instance. |
||
| 119 | * |
||
| 120 | * @return Builder The Version builder. |
||
| 121 | */ |
||
| 122 | public function importVersion($version) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Increments the major version number and resets the minor and patch |
||
| 134 | * version numbers to zero. |
||
| 135 | * |
||
| 136 | * @param integer $amount Increment by what amount? |
||
| 137 | * |
||
| 138 | * @return Builder The Version builder. |
||
| 139 | */ |
||
| 140 | public function incrementMajor($amount = 1) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Increments the minor version number and resets the patch version number |
||
| 151 | * to zero. |
||
| 152 | * |
||
| 153 | * @param integer $amount Increment by what amount? |
||
| 154 | * |
||
| 155 | * @return Builder The Version builder. |
||
| 156 | */ |
||
| 157 | public function incrementMinor($amount = 1) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Increments the patch version number. |
||
| 167 | * |
||
| 168 | * @param integer $amount Increment by what amount? |
||
| 169 | * |
||
| 170 | * @return Builder The Version builder. |
||
| 171 | */ |
||
| 172 | public function incrementPatch($amount = 1) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Sets the build metadata identifiers. |
||
| 181 | * |
||
| 182 | * @param array $identifiers The build metadata identifiers. |
||
| 183 | * |
||
| 184 | * @return Builder The Version builder. |
||
| 185 | * |
||
| 186 | * @throws InvalidIdentifierException If an identifier is invalid. |
||
| 187 | */ |
||
| 188 | View Code Duplication | public function setBuild(array $identifiers) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Sets the major version number. |
||
| 203 | * |
||
| 204 | * @param integer $number The major version number. |
||
| 205 | * |
||
| 206 | * @return Builder The Version builder. |
||
| 207 | * |
||
| 208 | * @throws InvalidNumberException If the number is invalid. |
||
| 209 | */ |
||
| 210 | View Code Duplication | public function setMajor($number) |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Sets the minor version number. |
||
| 223 | * |
||
| 224 | * @param integer $number The minor version number. |
||
| 225 | * |
||
| 226 | * @return Builder The Version builder. |
||
| 227 | * |
||
| 228 | * @throws InvalidNumberException If the number is invalid. |
||
| 229 | */ |
||
| 230 | View Code Duplication | public function setMinor($number) |
|
| 240 | |||
| 241 | /** |
||
| 242 | * Sets the patch version number. |
||
| 243 | * |
||
| 244 | * @param integer $number The patch version number. |
||
| 245 | * |
||
| 246 | * @return Builder The Version builder. |
||
| 247 | * |
||
| 248 | * @throws InvalidNumberException If the number is invalid. |
||
| 249 | */ |
||
| 250 | View Code Duplication | public function setPatch($number) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * Sets the pre-release version identifiers. |
||
| 263 | * |
||
| 264 | * @param array $identifiers The pre-release version identifiers. |
||
| 265 | * |
||
| 266 | * @return Builder The Version builder. |
||
| 267 | * |
||
| 268 | * @throws InvalidIdentifierException If an identifier is invalid. |
||
| 269 | */ |
||
| 270 | View Code Duplication | public function setPreRelease(array $identifiers) |
|
| 282 | } |
||
| 283 |