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 _process($command, array $properties) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param array $properties |
||
| 50 | * @return bool |
||
| 51 | */ |
||
| 52 | public function updateUser(array $properties) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param string $field |
||
| 60 | * @param integer|string $value |
||
| 61 | * @return Struct\Info |
||
| 62 | */ |
||
| 63 | public function get($field, $value) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $field |
||
| 71 | * @param integer|string $value |
||
| 72 | * @return Struct\UserInfo |
||
| 73 | */ |
||
| 74 | public function getUser($field, $value) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $field |
||
| 82 | * @param integer|string $value |
||
| 83 | * @return Struct\Info[] |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function getAll($field, $value) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @param string $field |
||
| 97 | * @param integer|string $value |
||
| 98 | * @return Struct\UserInfo[] |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function getAllUsers($field, $value) |
|
| 109 | |||
| 110 | /** |
||
| 111 | * @param $command |
||
| 112 | * @param $field |
||
| 113 | * @param $value |
||
| 114 | * @return \PleskX\Api\XmlResponse |
||
| 115 | */ |
||
| 116 | private function _get($command, $field, $value) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param string $field |
||
| 132 | * @param integer|string $value |
||
| 133 | * @return bool |
||
| 134 | */ |
||
| 135 | public function delete($field, $value) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param string $field |
||
| 142 | * @param integer|string $value |
||
| 143 | * @return bool |
||
| 144 | */ |
||
| 145 | public function deleteUser($field, $value) |
||
| 149 | } |
||
| 150 |