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 Settings extends AbstractRegistryWrapper |
||
| 24 | {
|
||
| 25 | /** |
||
| 26 | * Default Settings |
||
| 27 | * Edit this section to configure your client |
||
| 28 | */ |
||
| 29 | const PLUGIN_PATH = '/plugins/restapi/v1'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Settings |
||
| 33 | */ |
||
| 34 | private static $instance; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Settings constructor. |
||
| 38 | */ |
||
| 39 | private function __construct() {}
|
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return Settings |
||
| 43 | */ |
||
| 44 | public static function getInstance() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param $host |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function setHost($host) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @param $port |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function setPort($port) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param $plugin |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function setPlugin($plugin) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param $useSSL |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | public function setSSL($useSSL) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param $secretKey |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | public function setSecretKey($secretKey) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param $serverName |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function setServerName($serverName) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param $host |
||
| 123 | * @return string |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function setServerNameFromHost($host) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @param $bool |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function setDebug($bool) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param AuthenticationToken $authenticationToken |
||
| 149 | * @return mixed |
||
| 150 | */ |
||
| 151 | public function setAuthenticationToken(AuthenticationToken $authenticationToken) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return string |
||
| 158 | */ |
||
| 159 | public function getHost() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | public function getPort() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | public function getPlugin() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return bool |
||
| 182 | */ |
||
| 183 | public function isSSL() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | public function getServerName() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | public function isDebug() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return AuthenticationToken |
||
| 206 | */ |
||
| 207 | public function getAuthenticationToken() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Returns the URL under which query the webservice |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getBaseURL() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Returns the headers to be sent to web service |
||
| 224 | * @return array |
||
| 225 | * @throws \Exception |
||
| 226 | */ |
||
| 227 | public function getHeaders() |
||
| 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.