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:
Complex classes like ClientRemote often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ClientRemote, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class ClientRemote extends BaseClientRemote |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @inheritdoc |
||
| 24 | */ |
||
| 25 | 2 | public function getTables(array $params = []) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @inheritdoc |
||
| 32 | */ |
||
| 33 | 4 | public function getTable($tableName) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | 2 | public function getColumns($tableName, array $params = []) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @inheritdoc |
||
| 52 | */ |
||
| 53 | 2 | public function getColumn($tableName, $columnName) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritdoc |
||
| 62 | */ |
||
| 63 | 2 | public function getEntries($tableName, array $options = []) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @inheritdoc |
||
| 72 | */ |
||
| 73 | 2 | public function getEntry($tableName, $id, array $options = []) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @inheritdoc |
||
| 82 | */ |
||
| 83 | 2 | public function getUsers(array $params = []) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * @inheritdoc |
||
| 90 | */ |
||
| 91 | 2 | public function getUser($id, array $params = []) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @inheritdoc |
||
| 98 | */ |
||
| 99 | 2 | public function getGroups() |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @inheritdoc |
||
| 106 | */ |
||
| 107 | 2 | public function getGroup($groupID) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * @inheritdoc |
||
| 116 | */ |
||
| 117 | 2 | public function getGroupPrivileges($groupID) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @inheritdoc |
||
| 126 | */ |
||
| 127 | 2 | public function getFiles() |
|
| 131 | |||
| 132 | /** |
||
| 133 | * @inheritdoc |
||
| 134 | */ |
||
| 135 | 2 | public function getFile($fileID) |
|
| 141 | |||
| 142 | /** |
||
| 143 | * @inheritdoc |
||
| 144 | */ |
||
| 145 | 2 | public function getSettings() |
|
| 149 | |||
| 150 | /** |
||
| 151 | * @inheritdoc |
||
| 152 | */ |
||
| 153 | 2 | public function getSettingsByCollection($collectionName) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @inheritdoc |
||
| 162 | */ |
||
| 163 | public function getMessages($userId) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @inheritdoc |
||
| 172 | */ |
||
| 173 | View Code Duplication | public function createEntry($tableName, array $data) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @inheritdoc |
||
| 183 | */ |
||
| 184 | View Code Duplication | public function updateEntry($tableName, $id, array $data) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @inheritdoc |
||
| 194 | */ |
||
| 195 | public function deleteEntry($tableName, $id) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @inheritdoc |
||
| 204 | */ |
||
| 205 | public function createUser(array $data) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @inheritdoc |
||
| 212 | */ |
||
| 213 | public function updateUser($id, array $data) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @inheritdoc |
||
| 220 | */ |
||
| 221 | public function deleteUser($ids) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @inheritdoc |
||
| 228 | */ |
||
| 229 | public function createFile(File $file) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @inheritdoc |
||
| 238 | */ |
||
| 239 | public function updateFile($id, $data) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @inheritdoc |
||
| 254 | */ |
||
| 255 | public function deleteFile($id) |
||
| 259 | |||
| 260 | public function createPreferences($data) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @inheritdoc |
||
| 273 | */ |
||
| 274 | public function createBookmark($data) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @inheritdoc |
||
| 296 | */ |
||
| 297 | public function createColumn($data) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @inheritdoc |
||
| 308 | */ |
||
| 309 | public function createGroup(array $data) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @inheritdoc |
||
| 318 | */ |
||
| 319 | public function createMessage(array $data) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @inheritdoc |
||
| 334 | */ |
||
| 335 | public function sendMessage(array $data) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @inheritdoc |
||
| 342 | */ |
||
| 343 | public function createPrivileges(array $data) |
||
| 351 | |||
| 352 | public function createTable($name, array $params = []) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @inheritdoc |
||
| 366 | */ |
||
| 367 | public function createColumnUIOptions(array $data) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @inheritdoc |
||
| 386 | */ |
||
| 387 | public function getPreferences($table, $user = null) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @inheritdoc |
||
| 394 | */ |
||
| 395 | public function deleteBookmark($id) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @inheritdoc |
||
| 402 | */ |
||
| 403 | public function deleteColumn($name, $table) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @inheritdoc |
||
| 412 | */ |
||
| 413 | public function deleteGroup($id) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @inheritdoc |
||
| 420 | */ |
||
| 421 | public function deleteTable($name) |
||
| 427 | } |
||
| 428 |