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 |
||
| 8 | class Server extends \PleskX\Api\Operator |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @return array |
||
| 12 | */ |
||
| 13 | View Code Duplication | public function getProtos() |
|
| 21 | |||
| 22 | public function getGeneralInfo() |
||
| 26 | |||
| 27 | public function getPreferences() |
||
| 31 | |||
| 32 | public function getAdmin() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | public function getKeyInfo() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public function getComponents() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function getServiceStates() |
||
| 85 | |||
| 86 | public function getSessionPreferences() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | public function getShells() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | public function getNetworkInterfaces() |
||
| 115 | |||
| 116 | public function getStatistics() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | public function getSiteIsolationConfig() |
||
| 135 | |||
| 136 | public function getUpdatesInfo() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param string $login |
||
| 143 | * @param string $clientIp |
||
| 144 | * |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | public function createSession($login, $clientIp) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param string $operation |
||
| 162 | * |
||
| 163 | * @return \SimpleXMLElement |
||
| 164 | */ |
||
| 165 | View Code Duplication | private function _getInfo($operation) |
|
| 173 | } |
||
| 174 |
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.