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  | 
            ||
| 21 | class ClientRemote extends BaseClientRemote  | 
            ||
| 22 | { | 
            ||
| 23 | /**  | 
            ||
| 24 | * @inheritdoc  | 
            ||
| 25 | */  | 
            ||
| 26 | 2 | public function getTables(array $params = [])  | 
            |
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * @inheritdoc  | 
            ||
| 33 | */  | 
            ||
| 34 | 4 | public function getTable($tableName)  | 
            |
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * @inheritdoc  | 
            ||
| 43 | */  | 
            ||
| 44 | 2 | public function getColumns($tableName, array $params = [])  | 
            |
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * @inheritdoc  | 
            ||
| 53 | */  | 
            ||
| 54 | 2 | public function getColumn($tableName, $columnName)  | 
            |
| 60 | |||
| 61 | /**  | 
            ||
| 62 | * @inheritdoc  | 
            ||
| 63 | */  | 
            ||
| 64 | 2 | public function getItems($tableName, array $options = [])  | 
            |
| 70 | |||
| 71 | /**  | 
            ||
| 72 | * @inheritdoc  | 
            ||
| 73 | */  | 
            ||
| 74 | 2 | public function getItem($tableName, $id, array $options = [])  | 
            |
| 80 | |||
| 81 | /**  | 
            ||
| 82 | * @inheritdoc  | 
            ||
| 83 | */  | 
            ||
| 84 | 2 | public function getUsers(array $params = [])  | 
            |
| 88 | |||
| 89 | /**  | 
            ||
| 90 | * @inheritdoc  | 
            ||
| 91 | */  | 
            ||
| 92 | 2 | public function getUser($id, array $params = [])  | 
            |
| 96 | |||
| 97 | /**  | 
            ||
| 98 | * @inheritdoc  | 
            ||
| 99 | */  | 
            ||
| 100 | 2 | public function getGroups()  | 
            |
| 104 | |||
| 105 | /**  | 
            ||
| 106 | * @inheritdoc  | 
            ||
| 107 | */  | 
            ||
| 108 | 2 | public function getGroup($groupID)  | 
            |
| 114 | |||
| 115 | /**  | 
            ||
| 116 | * @inheritdoc  | 
            ||
| 117 | */  | 
            ||
| 118 | 2 | public function getGroupPrivileges($groupID)  | 
            |
| 124 | |||
| 125 | /**  | 
            ||
| 126 | * @inheritdoc  | 
            ||
| 127 | */  | 
            ||
| 128 | 2 | public function getFiles()  | 
            |
| 132 | |||
| 133 | /**  | 
            ||
| 134 | * @inheritdoc  | 
            ||
| 135 | */  | 
            ||
| 136 | 2 | public function getFile($fileID)  | 
            |
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * @inheritdoc  | 
            ||
| 145 | */  | 
            ||
| 146 | 2 | public function getSettings()  | 
            |
| 150 | |||
| 151 | /**  | 
            ||
| 152 | * @inheritdoc  | 
            ||
| 153 | */  | 
            ||
| 154 | 2 | public function getSettingsByCollection($collectionName)  | 
            |
| 160 | |||
| 161 | /**  | 
            ||
| 162 | * @inheritdoc  | 
            ||
| 163 | */  | 
            ||
| 164 | public function updateSettings($collection, array $data)  | 
            ||
| 172 | |||
| 173 | /**  | 
            ||
| 174 | * @inheritdoc  | 
            ||
| 175 | */  | 
            ||
| 176 | public function getMessages($userId)  | 
            ||
| 182 | |||
| 183 | /**  | 
            ||
| 184 | * @inheritdoc  | 
            ||
| 185 | */  | 
            ||
| 186 | View Code Duplication | public function createItem($tableName, array $data)  | 
            |
| 193 | |||
| 194 | /**  | 
            ||
| 195 | * @inheritdoc  | 
            ||
| 196 | */  | 
            ||
| 197 | View Code Duplication | public function updateItem($tableName, $id, array $data)  | 
            |
| 204 | |||
| 205 | /**  | 
            ||
| 206 | * @inheritdoc  | 
            ||
| 207 | */  | 
            ||
| 208 | public function deleteItem($tableName, $id)  | 
            ||
| 214 | |||
| 215 | /**  | 
            ||
| 216 | * @inheritdoc  | 
            ||
| 217 | */  | 
            ||
| 218 | public function createUser(array $data)  | 
            ||
| 222 | |||
| 223 | /**  | 
            ||
| 224 | * @inheritdoc  | 
            ||
| 225 | */  | 
            ||
| 226 | public function updateUser($id, array $data)  | 
            ||
| 230 | |||
| 231 | /**  | 
            ||
| 232 | * @inheritdoc  | 
            ||
| 233 | */  | 
            ||
| 234 | public function deleteUser($ids)  | 
            ||
| 238 | |||
| 239 | /**  | 
            ||
| 240 | * @inheritdoc  | 
            ||
| 241 | */  | 
            ||
| 242 | public function createFile(File $file)  | 
            ||
| 248 | |||
| 249 | /**  | 
            ||
| 250 | * @inheritdoc  | 
            ||
| 251 | */  | 
            ||
| 252 | public function updateFile($id, $data)  | 
            ||
| 264 | |||
| 265 | /**  | 
            ||
| 266 | * @inheritdoc  | 
            ||
| 267 | */  | 
            ||
| 268 | public function deleteFile($id)  | 
            ||
| 272 | |||
| 273 | public function createPreferences($data)  | 
            ||
| 283 | |||
| 284 | /**  | 
            ||
| 285 | * @inheritdoc  | 
            ||
| 286 | */  | 
            ||
| 287 | public function createBookmark($data)  | 
            ||
| 306 | |||
| 307 | /**  | 
            ||
| 308 | * @inheritdoc  | 
            ||
| 309 | */  | 
            ||
| 310 | public function getBookmark($id)  | 
            ||
| 316 | |||
| 317 | /**  | 
            ||
| 318 | * @inheritdoc  | 
            ||
| 319 | */  | 
            ||
| 320 | public function getBookmarks($userId = null)  | 
            ||
| 330 | |||
| 331 | /**  | 
            ||
| 332 | * @inheritdoc  | 
            ||
| 333 | */  | 
            ||
| 334 | public function createColumn($data)  | 
            ||
| 342 | |||
| 343 | /**  | 
            ||
| 344 | * @inheritdoc  | 
            ||
| 345 | */  | 
            ||
| 346 | public function createGroup(array $data)  | 
            ||
| 352 | |||
| 353 | /**  | 
            ||
| 354 | * @inheritdoc  | 
            ||
| 355 | */  | 
            ||
| 356 | public function createMessage(array $data)  | 
            ||
| 368 | |||
| 369 | /**  | 
            ||
| 370 | * @inheritdoc  | 
            ||
| 371 | */  | 
            ||
| 372 | public function sendMessage(array $data)  | 
            ||
| 376 | |||
| 377 | /**  | 
            ||
| 378 | * @inheritdoc  | 
            ||
| 379 | */  | 
            ||
| 380 | public function createPrivileges(array $data)  | 
            ||
| 388 | |||
| 389 | public function createTable($name, array $params = [])  | 
            ||
| 400 | |||
| 401 | /**  | 
            ||
| 402 | * @inheritdoc  | 
            ||
| 403 | */  | 
            ||
| 404 | public function createColumnUIOptions(array $data)  | 
            ||
| 420 | |||
| 421 | /**  | 
            ||
| 422 | * @inheritdoc  | 
            ||
| 423 | */  | 
            ||
| 424 | public function getPreferences($table, $user = null)  | 
            ||
| 428 | |||
| 429 | /**  | 
            ||
| 430 | * @inheritdoc  | 
            ||
| 431 | */  | 
            ||
| 432 | public function deleteBookmark($id)  | 
            ||
| 436 | |||
| 437 | /**  | 
            ||
| 438 | * @inheritdoc  | 
            ||
| 439 | */  | 
            ||
| 440 | public function deleteColumn($name, $table)  | 
            ||
| 446 | |||
| 447 | /**  | 
            ||
| 448 | * @inheritdoc  | 
            ||
| 449 | */  | 
            ||
| 450 | public function deleteGroup($id)  | 
            ||
| 454 | |||
| 455 | /**  | 
            ||
| 456 | * @inheritdoc  | 
            ||
| 457 | */  | 
            ||
| 458 | public function deleteTable($name)  | 
            ||
| 464 | |||
| 465 | /**  | 
            ||
| 466 | * @inheritdoc  | 
            ||
| 467 | */  | 
            ||
| 468 | public function getActivity(array $params = [])  | 
            ||
| 480 | }  | 
            ||
| 481 |