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 getMessages($userId) |
||
170 | |||
171 | /** |
||
172 | * @inheritdoc |
||
173 | */ |
||
174 | View Code Duplication | public function createItem($tableName, array $data) |
|
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | */ |
||
185 | View Code Duplication | public function updateItem($tableName, $id, array $data) |
|
192 | |||
193 | /** |
||
194 | * @inheritdoc |
||
195 | */ |
||
196 | public function deleteItem($tableName, $id) |
||
202 | |||
203 | /** |
||
204 | * @inheritdoc |
||
205 | */ |
||
206 | public function createUser(array $data) |
||
210 | |||
211 | /** |
||
212 | * @inheritdoc |
||
213 | */ |
||
214 | public function updateUser($id, array $data) |
||
218 | |||
219 | /** |
||
220 | * @inheritdoc |
||
221 | */ |
||
222 | public function deleteUser($ids) |
||
226 | |||
227 | /** |
||
228 | * @inheritdoc |
||
229 | */ |
||
230 | public function createFile(File $file) |
||
236 | |||
237 | /** |
||
238 | * @inheritdoc |
||
239 | */ |
||
240 | public function updateFile($id, $data) |
||
252 | |||
253 | /** |
||
254 | * @inheritdoc |
||
255 | */ |
||
256 | public function deleteFile($id) |
||
260 | |||
261 | public function createPreferences($data) |
||
271 | |||
272 | /** |
||
273 | * @inheritdoc |
||
274 | */ |
||
275 | public function createBookmark($data) |
||
294 | |||
295 | /** |
||
296 | * @inheritdoc |
||
297 | */ |
||
298 | public function getBookmark($id) |
||
304 | |||
305 | /** |
||
306 | * @inheritdoc |
||
307 | */ |
||
308 | public function getBookmarks($userId = null) |
||
318 | |||
319 | /** |
||
320 | * @inheritdoc |
||
321 | */ |
||
322 | public function createColumn($data) |
||
330 | |||
331 | /** |
||
332 | * @inheritdoc |
||
333 | */ |
||
334 | public function createGroup(array $data) |
||
340 | |||
341 | /** |
||
342 | * @inheritdoc |
||
343 | */ |
||
344 | public function createMessage(array $data) |
||
356 | |||
357 | /** |
||
358 | * @inheritdoc |
||
359 | */ |
||
360 | public function sendMessage(array $data) |
||
364 | |||
365 | /** |
||
366 | * @inheritdoc |
||
367 | */ |
||
368 | public function createPrivileges(array $data) |
||
376 | |||
377 | public function createTable($name, array $params = []) |
||
388 | |||
389 | /** |
||
390 | * @inheritdoc |
||
391 | */ |
||
392 | public function createColumnUIOptions(array $data) |
||
408 | |||
409 | /** |
||
410 | * @inheritdoc |
||
411 | */ |
||
412 | public function getPreferences($table, $user = null) |
||
416 | |||
417 | /** |
||
418 | * @inheritdoc |
||
419 | */ |
||
420 | public function deleteBookmark($id) |
||
424 | |||
425 | /** |
||
426 | * @inheritdoc |
||
427 | */ |
||
428 | public function deleteColumn($name, $table) |
||
434 | |||
435 | /** |
||
436 | * @inheritdoc |
||
437 | */ |
||
438 | public function deleteGroup($id) |
||
442 | |||
443 | /** |
||
444 | * @inheritdoc |
||
445 | */ |
||
446 | public function deleteTable($name) |
||
452 | |||
453 | /** |
||
454 | * @inheritdoc |
||
455 | */ |
||
456 | public function getActivity(array $params = []) |
||
468 | } |
||
469 |