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 |
||
| 23 | class InputValidation |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | public static function displayName($displayName) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | public static function commonName($commonName) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | public static function serverCommonName($serverCommonName) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public static function profileId($profileId) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public static function languageCode($languageCode) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public static function totpSecret($totpSecret) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public static function totpKey($totpKey) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | public static function clientId($clientId) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return string |
||
| 126 | */ |
||
| 127 | public static function userId($userId) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return string |
||
| 138 | */ |
||
| 139 | public static function motdMessage($motdMessage) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return int |
||
| 147 | */ |
||
| 148 | public static function dateTime($dateTime) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | View Code Duplication | public static function ipAddress($ipAddress) |
|
| 176 | |||
| 177 | /** |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | public static function vootToken($vootToken) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | public static function ip4($ip4) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | View Code Duplication | public static function ip6($ip6) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * @return int |
||
| 216 | */ |
||
| 217 | public static function connectedAt($connectedAt) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return int |
||
| 228 | */ |
||
| 229 | public static function disconnectedAt($disconnectedAt) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @return int |
||
| 240 | */ |
||
| 241 | public static function bytesTransferred($bytesTransferred) |
||
| 249 | } |
||
| 250 |
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.