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 | public function getTables(array $params = [])  | 
            ||
| 29 | |||
| 30 | /**  | 
            ||
| 31 | * @inheritdoc  | 
            ||
| 32 | */  | 
            ||
| 33 | public function getTable($tableName)  | 
            ||
| 39 | |||
| 40 | /**  | 
            ||
| 41 | * @inheritdoc  | 
            ||
| 42 | */  | 
            ||
| 43 | public function getColumns($tableName, array $params = [])  | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * @inheritdoc  | 
            ||
| 52 | */  | 
            ||
| 53 | public function getColumn($tableName, $columnName)  | 
            ||
| 59 | |||
| 60 | /**  | 
            ||
| 61 | * @inheritdoc  | 
            ||
| 62 | */  | 
            ||
| 63 | public function getItems($tableName, array $options = [])  | 
            ||
| 69 | |||
| 70 | /**  | 
            ||
| 71 | * @inheritdoc  | 
            ||
| 72 | */  | 
            ||
| 73 | public function getItem($tableName, $id, array $options = [])  | 
            ||
| 79 | |||
| 80 | /**  | 
            ||
| 81 | * @inheritdoc  | 
            ||
| 82 | */  | 
            ||
| 83 | public function getUsers(array $params = [])  | 
            ||
| 87 | |||
| 88 | /**  | 
            ||
| 89 | * @inheritdoc  | 
            ||
| 90 | */  | 
            ||
| 91 | public function getUser($id, array $params = [])  | 
            ||
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * @inheritdoc  | 
            ||
| 98 | */  | 
            ||
| 99 | public function getGroups()  | 
            ||
| 103 | |||
| 104 | /**  | 
            ||
| 105 | * @inheritdoc  | 
            ||
| 106 | */  | 
            ||
| 107 | public function getGroup($groupID)  | 
            ||
| 113 | |||
| 114 | /**  | 
            ||
| 115 | * @inheritdoc  | 
            ||
| 116 | */  | 
            ||
| 117 | public function getGroupPrivileges($groupID)  | 
            ||
| 123 | |||
| 124 | /**  | 
            ||
| 125 | * @inheritdoc  | 
            ||
| 126 | */  | 
            ||
| 127 | public function getFiles()  | 
            ||
| 131 | |||
| 132 | /**  | 
            ||
| 133 | * @inheritdoc  | 
            ||
| 134 | */  | 
            ||
| 135 | public function getFile($fileID)  | 
            ||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * @inheritdoc  | 
            ||
| 144 | */  | 
            ||
| 145 | public function getSettings()  | 
            ||
| 149 | |||
| 150 | /**  | 
            ||
| 151 | * @inheritdoc  | 
            ||
| 152 | */  | 
            ||
| 153 | public function getSettingsByCollection($collectionName)  | 
            ||
| 159 | |||
| 160 | /**  | 
            ||
| 161 | * @inheritdoc  | 
            ||
| 162 | */  | 
            ||
| 163 | public function updateSettings($collection, array $data)  | 
            ||
| 171 | |||
| 172 | /**  | 
            ||
| 173 | * @inheritdoc  | 
            ||
| 174 | */  | 
            ||
| 175 | View Code Duplication | public function getMessages($userId = null)  | 
            |
| 185 | |||
| 186 | /**  | 
            ||
| 187 | * @inheritdoc  | 
            ||
| 188 | */  | 
            ||
| 189 | public function getMessage($id)  | 
            ||
| 195 | |||
| 196 | /**  | 
            ||
| 197 | * @inheritdoc  | 
            ||
| 198 | */  | 
            ||
| 199 | View Code Duplication | public function createItem($tableName, array $data)  | 
            |
| 206 | |||
| 207 | /**  | 
            ||
| 208 | * @inheritdoc  | 
            ||
| 209 | */  | 
            ||
| 210 | View Code Duplication | public function updateItem($tableName, $id, array $data)  | 
            |
| 217 | |||
| 218 | /**  | 
            ||
| 219 | * @inheritdoc  | 
            ||
| 220 | */  | 
            ||
| 221 | public function deleteItem($tableName, $id)  | 
            ||
| 227 | |||
| 228 | /**  | 
            ||
| 229 | * @inheritdoc  | 
            ||
| 230 | */  | 
            ||
| 231 | public function createUser(array $data)  | 
            ||
| 235 | |||
| 236 | /**  | 
            ||
| 237 | * @inheritdoc  | 
            ||
| 238 | */  | 
            ||
| 239 | public function updateUser($id, array $data)  | 
            ||
| 243 | |||
| 244 | /**  | 
            ||
| 245 | * @inheritdoc  | 
            ||
| 246 | */  | 
            ||
| 247 | public function deleteUser($ids)  | 
            ||
| 251 | |||
| 252 | /**  | 
            ||
| 253 | * @inheritdoc  | 
            ||
| 254 | */  | 
            ||
| 255 | public function createFile(File $file)  | 
            ||
| 261 | |||
| 262 | /**  | 
            ||
| 263 | * @inheritdoc  | 
            ||
| 264 | */  | 
            ||
| 265 | public function updateFile($id, $data)  | 
            ||
| 277 | |||
| 278 | /**  | 
            ||
| 279 | * @inheritdoc  | 
            ||
| 280 | */  | 
            ||
| 281 | public function deleteFile($id)  | 
            ||
| 285 | |||
| 286 | public function createPreferences($data)  | 
            ||
| 296 | |||
| 297 | /**  | 
            ||
| 298 | * @inheritdoc  | 
            ||
| 299 | */  | 
            ||
| 300 | public function createBookmark($data)  | 
            ||
| 319 | |||
| 320 | /**  | 
            ||
| 321 | * @inheritdoc  | 
            ||
| 322 | */  | 
            ||
| 323 | public function getBookmark($id)  | 
            ||
| 329 | |||
| 330 | /**  | 
            ||
| 331 | * @inheritdoc  | 
            ||
| 332 | */  | 
            ||
| 333 | View Code Duplication | public function getBookmarks($userId = null)  | 
            |
| 343 | |||
| 344 | /**  | 
            ||
| 345 | * @inheritdoc  | 
            ||
| 346 | */  | 
            ||
| 347 | public function createColumn($data)  | 
            ||
| 355 | |||
| 356 | /**  | 
            ||
| 357 | * @inheritdoc  | 
            ||
| 358 | */  | 
            ||
| 359 | public function createGroup(array $data)  | 
            ||
| 365 | |||
| 366 | /**  | 
            ||
| 367 | * @inheritdoc  | 
            ||
| 368 | */  | 
            ||
| 369 | public function createMessage(array $data)  | 
            ||
| 381 | |||
| 382 | /**  | 
            ||
| 383 | * @inheritdoc  | 
            ||
| 384 | */  | 
            ||
| 385 | public function sendMessage(array $data)  | 
            ||
| 389 | |||
| 390 | /**  | 
            ||
| 391 | * @inheritdoc  | 
            ||
| 392 | */  | 
            ||
| 393 | public function createPrivileges(array $data)  | 
            ||
| 401 | |||
| 402 | public function createTable($name, array $params = [])  | 
            ||
| 413 | |||
| 414 | /**  | 
            ||
| 415 | * @inheritdoc  | 
            ||
| 416 | */  | 
            ||
| 417 | public function createColumnUIOptions(array $data)  | 
            ||
| 433 | |||
| 434 | /**  | 
            ||
| 435 | * @inheritdoc  | 
            ||
| 436 | */  | 
            ||
| 437 | public function getPreferences($table, $user = null)  | 
            ||
| 441 | |||
| 442 | /**  | 
            ||
| 443 | * @inheritdoc  | 
            ||
| 444 | */  | 
            ||
| 445 | public function deleteBookmark($id)  | 
            ||
| 449 | |||
| 450 | /**  | 
            ||
| 451 | * @inheritdoc  | 
            ||
| 452 | */  | 
            ||
| 453 | public function deleteColumn($name, $table)  | 
            ||
| 459 | |||
| 460 | /**  | 
            ||
| 461 | * @inheritdoc  | 
            ||
| 462 | */  | 
            ||
| 463 | public function deleteGroup($id)  | 
            ||
| 467 | |||
| 468 | /**  | 
            ||
| 469 | * @inheritdoc  | 
            ||
| 470 | */  | 
            ||
| 471 | public function deleteTable($name)  | 
            ||
| 477 | |||
| 478 | /**  | 
            ||
| 479 | * @inheritdoc  | 
            ||
| 480 | */  | 
            ||
| 481 | public function getActivity(array $params = [])  | 
            ||
| 493 | }  | 
            ||
| 494 |