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) |
||
43 | |||
44 | /** |
||
45 | * @param array $properties |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function updateUser(array $properties) |
||
53 | |||
54 | /** |
||
55 | * @param string $field |
||
56 | * @param integer|string $value |
||
57 | * @return Struct\Info |
||
58 | */ |
||
59 | public function get($field, $value) |
||
64 | |||
65 | /** |
||
66 | * @param string $field |
||
67 | * @param integer|string $value |
||
68 | * @return Struct\UserInfo |
||
69 | */ |
||
70 | public function getUser($field, $value) |
||
75 | |||
76 | /** |
||
77 | * @param string $field |
||
78 | * @param integer|string $value |
||
79 | * @return Struct\Info[] |
||
80 | */ |
||
81 | View Code Duplication | public function getAll($field, $value) |
|
90 | |||
91 | /** |
||
92 | * @param string $field |
||
93 | * @param integer|string $value |
||
94 | * @return Struct\UserInfo[] |
||
95 | */ |
||
96 | View Code Duplication | public function getAllUsers($field, $value) |
|
105 | |||
106 | /** |
||
107 | * @param $command |
||
108 | * @param $field |
||
109 | * @param $value |
||
110 | * @return \PleskX\Api\XmlResponse |
||
111 | */ |
||
112 | private function _get($command, $field, $value) |
||
125 | |||
126 | /** |
||
127 | * @param string $field |
||
128 | * @param integer|string $value |
||
129 | * @return bool |
||
130 | */ |
||
131 | public function delete($field, $value) |
||
135 | |||
136 | /** |
||
137 | * @param string $field |
||
138 | * @param integer|string $value |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function deleteUser($field, $value) |
||
145 | } |
||
146 |