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 |
||
| 7 | class Database extends \PleskX\Api\Operator |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param array $properties |
||
| 11 | * @return Struct\Info |
||
| 12 | */ |
||
| 13 | public function create($properties) |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param $properties |
||
| 20 | * @return Struct\UserInfo |
||
| 21 | */ |
||
| 22 | public function createUser($properties) |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param $command |
||
| 29 | * @param array $properties |
||
| 30 | * @return \PleskX\Api\XmlResponse |
||
| 31 | */ |
||
| 32 | private function _create($command, array $properties) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $field |
||
| 46 | * @param integer|string $value |
||
| 47 | * @return Struct\Info |
||
| 48 | */ |
||
| 49 | public function get($field, $value) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $field |
||
| 57 | * @param integer|string $value |
||
| 58 | * @return Struct\UserInfo |
||
| 59 | */ |
||
| 60 | public function getUser($field, $value) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param string $field |
||
| 68 | * @param integer|string $value |
||
| 69 | * @return Struct\Info[] |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function getAll($field, $value) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @param string $field |
||
| 83 | * @param integer|string $value |
||
| 84 | * @return Struct\UserInfo[] |
||
| 85 | */ |
||
| 86 | View Code Duplication | public function getAllUsers($field, $value) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @param $command |
||
| 98 | * @param $field |
||
| 99 | * @param $value |
||
| 100 | * @return \PleskX\Api\XmlResponse |
||
| 101 | */ |
||
| 102 | private function _get($command, $field, $value) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param string $field |
||
| 118 | * @param integer|string $value |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public function delete($field, $value) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $field |
||
| 128 | * @param integer|string $value |
||
| 129 | * @return bool |
||
| 130 | */ |
||
| 131 | public function deleteUser($field, $value) |
||
| 135 | } |
||
| 136 |