Complex classes like ChannelModel 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 ChannelModel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class ChannelModel extends AbstractModel |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | public static $endpoint = '/channels'; |
||
31 | |||
32 | /** |
||
33 | * @param array $requestOptions |
||
34 | * @return ResponseInterface |
||
35 | */ |
||
36 | public function createChannel(array $requestOptions) |
||
40 | |||
41 | /** |
||
42 | * @param array $requestOptions |
||
43 | * @return ResponseInterface |
||
44 | */ |
||
45 | public function createDirectMessageChannel(array $requestOptions) |
||
49 | |||
50 | /** |
||
51 | * @param array $requestOptions |
||
52 | * @return ResponseInterface |
||
53 | */ |
||
54 | public function createGroupMessageChannel(array $requestOptions) |
||
58 | |||
59 | /** |
||
60 | * @param $teamId |
||
61 | * @param array $requestOptions |
||
62 | * @return ResponseInterface |
||
63 | */ |
||
64 | public function getChannelsListByIds($teamId, array $requestOptions) |
||
68 | |||
69 | /** |
||
70 | * @param array $requestOptions |
||
71 | * @return ResponseInterface |
||
72 | */ |
||
73 | public function getChannelsList(array $requestOptions = []) |
||
77 | |||
78 | /** |
||
79 | * @param $channelId |
||
80 | * @return ResponseInterface |
||
81 | */ |
||
82 | public function getChannel($channelId) |
||
86 | |||
87 | /** |
||
88 | * @param $channelId |
||
89 | * @return ResponseInterface |
||
90 | */ |
||
91 | public function getTimezone($channelId) |
||
95 | |||
96 | /** |
||
97 | * @param $channelId |
||
98 | * @param array $requestOptions |
||
99 | * @return ResponseInterface |
||
100 | */ |
||
101 | public function updateChannel($channelId, array $requestOptions) |
||
105 | |||
106 | /** |
||
107 | * @param $channelId |
||
108 | * @return ResponseInterface |
||
109 | */ |
||
110 | public function deleteChannel($channelId) |
||
114 | |||
115 | /** |
||
116 | * @param $channelId |
||
117 | * @param array $requestOptions |
||
118 | * @return ResponseInterface |
||
119 | */ |
||
120 | public function patchChannel($channelId, array $requestOptions) |
||
124 | |||
125 | /** |
||
126 | * @param $channelId |
||
127 | * @return ResponseInterface |
||
128 | */ |
||
129 | public function restoreChannel($channelId) |
||
133 | |||
134 | /** |
||
135 | * @param $channelId |
||
136 | * @return ResponseInterface |
||
137 | */ |
||
138 | public function getChannelStatistics($channelId) |
||
142 | |||
143 | /** |
||
144 | * @param $channelId |
||
145 | * @return ResponseInterface |
||
146 | */ |
||
147 | public function getChannelsPinnedPosts($channelId) |
||
151 | |||
152 | /** |
||
153 | * @param $teamId |
||
154 | * @param $channelName |
||
155 | * @return ResponseInterface |
||
156 | */ |
||
157 | public function getChannelByName($teamId, $channelName) |
||
161 | |||
162 | /** |
||
163 | * @param $teamName |
||
164 | * @param $channelName |
||
165 | * @return ResponseInterface |
||
166 | */ |
||
167 | public function getChannelByNameAndTeamName($teamName, $channelName) |
||
171 | |||
172 | /** |
||
173 | * @param $channelId |
||
174 | * @param array $requestOptions |
||
175 | * @return ResponseInterface |
||
176 | */ |
||
177 | public function getChannelMembers($channelId, array $requestOptions) |
||
181 | |||
182 | /** |
||
183 | * @param $channelId |
||
184 | * @param array $requestOptions |
||
185 | * @return ResponseInterface |
||
186 | */ |
||
187 | public function addUser($channelId, array $requestOptions) |
||
191 | |||
192 | /** |
||
193 | * @param $channelId |
||
194 | * @param array $requestOptions |
||
195 | * @return ResponseInterface |
||
196 | */ |
||
197 | public function getChannelMembersByIds($channelId, array $requestOptions) |
||
201 | |||
202 | /** |
||
203 | * @param $channelId |
||
204 | * @param $userId |
||
205 | * @return ResponseInterface |
||
206 | */ |
||
207 | public function getChannelMember($channelId, $userId) |
||
211 | |||
212 | /** |
||
213 | * @param $channelId |
||
214 | * @param $userId |
||
215 | * @return ResponseInterface |
||
216 | */ |
||
217 | public function removeUserFromChannel($channelId, $userId) |
||
221 | |||
222 | /** |
||
223 | * @param $channelId |
||
224 | * @param $userId |
||
225 | * @param array $requestOptions |
||
226 | * @return ResponseInterface |
||
227 | */ |
||
228 | public function updateChannelRoles($channelId, $userId, array $requestOptions) |
||
232 | |||
233 | /** |
||
234 | * @param $channelId |
||
235 | * @param $userId |
||
236 | * @param array $requestOptions |
||
237 | * @return ResponseInterface |
||
238 | */ |
||
239 | public function updateChannelNotifications($channelId, $userId, array $requestOptions) |
||
243 | |||
244 | /** |
||
245 | * @param $userId |
||
246 | * @param array $requestOptions |
||
247 | * @return ResponseInterface |
||
248 | */ |
||
249 | public function viewChannel($userId, array $requestOptions) |
||
253 | |||
254 | /** |
||
255 | * @param $userId |
||
256 | * @param $teamId |
||
257 | * @return ResponseInterface |
||
258 | */ |
||
259 | public function getChannelMembersForTheUser($userId, $teamId) |
||
263 | |||
264 | /** |
||
265 | * @param $userId |
||
266 | * @param $teamId |
||
267 | * @return ResponseInterface |
||
268 | */ |
||
269 | public function getChannelsForUser($userId, $teamId) |
||
273 | |||
274 | /** |
||
275 | * @param $userId |
||
276 | * @param $channelId |
||
277 | * @return ResponseInterface |
||
278 | */ |
||
279 | public function getUnreadMessages($userId, $channelId) |
||
283 | |||
284 | /** |
||
285 | * @param $channelId |
||
286 | * @return ResponseInterface |
||
287 | */ |
||
288 | public function convertChannelFromPublicToPrivate($channelId) |
||
292 | |||
293 | /** |
||
294 | * @param $teamId |
||
295 | * @param array $requestOptions |
||
296 | * @return ResponseInterface |
||
297 | */ |
||
298 | public function getPublicChannels($teamId, array $requestOptions) |
||
302 | |||
303 | /** |
||
304 | * @param $teamId |
||
305 | * @param array $requestOptions |
||
306 | * @return ResponseInterface |
||
307 | */ |
||
308 | public function getDeletedChannels($teamId, array $requestOptions) |
||
312 | |||
313 | /** |
||
314 | * @param $teamId |
||
315 | * @param array $requestOptions |
||
316 | * @return ResponseInterface |
||
317 | */ |
||
318 | public function autocompleteChannels($teamId, array $requestOptions) |
||
322 | |||
323 | /** |
||
324 | * @param $teamId |
||
325 | * @param array $requestOptions |
||
326 | * @return ResponseInterface |
||
327 | */ |
||
328 | public function autocompleteChannelsForSearch($teamId, array $requestOptions) |
||
332 | |||
333 | /** |
||
334 | * @param $teamId |
||
335 | * @param array $requestOptions |
||
336 | * @return ResponseInterface |
||
337 | */ |
||
338 | public function searchChannels($teamId, array $requestOptions) |
||
342 | |||
343 | /** |
||
344 | * @param $teamId |
||
345 | * @param array $requestOptions |
||
346 | * @return ResponseInterface |
||
347 | */ |
||
348 | public function searchArchivedChannels($teamId, array $requestOptions) |
||
352 | |||
353 | /** |
||
354 | * @param array $requestOptions |
||
355 | * @return ResponseInterface |
||
356 | */ |
||
357 | public function searchAllPrivateAndOpenTypeChannels(array $requestOptions) |
||
361 | |||
362 | /** |
||
363 | * @param array $requestOptions |
||
364 | * @return ResponseInterface |
||
365 | */ |
||
366 | public function searchGroupChannels(array $requestOptions) |
||
370 | |||
371 | /** |
||
372 | * @param $channelId |
||
373 | * @param array $requestOptions |
||
374 | * @return ResponseInterface |
||
375 | */ |
||
376 | public function getMembersMinusGroupMembers($channelId, array $requestOptions) |
||
380 | |||
381 | /** |
||
382 | * @param $channelId |
||
383 | * @param array $requestOptions |
||
384 | * @return ResponseInterface |
||
385 | */ |
||
386 | public function updateChannelPrivacy($channelId, array $requestOptions) |
||
390 | |||
391 | /** |
||
392 | * @param $channelId |
||
393 | * @return ResponseInterface |
||
394 | */ |
||
395 | public function getInformationAboutChannelModeration($channelId) |
||
399 | |||
400 | /** |
||
401 | * @param $channelId |
||
402 | * @param array $requestOptions |
||
403 | * @return ResponseInterface |
||
404 | */ |
||
405 | public function updateChannelModerationSettings($channelId, array $requestOptions) |
||
409 | |||
410 | /** |
||
411 | * @param $teamId |
||
412 | * @param $userId |
||
413 | * @return ResponseInterface |
||
414 | */ |
||
415 | public function getUserSidebarCategories($teamId, $userId) |
||
420 | |||
421 | /** |
||
422 | * @param $teamId |
||
423 | * @param $userId |
||
424 | * @param array $requestOptions |
||
425 | * @return ResponseInterface |
||
426 | */ |
||
427 | public function createUserSidebarCategory($teamId, $userId, array $requestOptions) |
||
432 | |||
433 | /** |
||
434 | * @param $teamId |
||
435 | * @param $userId |
||
436 | * @param array $requestOptions |
||
437 | * @return ResponseInterface |
||
438 | */ |
||
439 | public function updateUserSidebarCategories($teamId, $userId, array $requestOptions) |
||
444 | |||
445 | /** |
||
446 | * @param $teamId |
||
447 | * @param $userId |
||
448 | * @return ResponseInterface |
||
449 | */ |
||
450 | public function getUserSidebarCategoryOrder($teamId, $userId) |
||
455 | |||
456 | /** |
||
457 | * @param $teamId |
||
458 | * @param $userId |
||
459 | * @param array $requestOptions |
||
460 | * @return ResponseInterface |
||
461 | */ |
||
462 | public function updateUserSidebarCategoryOrder($teamId, $userId, array $requestOptions) |
||
467 | |||
468 | /** |
||
469 | * @param $teamId |
||
470 | * @param $userId |
||
471 | * @param $categoryId |
||
472 | * @return ResponseInterface |
||
473 | */ |
||
474 | public function getSidebarCategory($teamId, $userId, $categoryId) |
||
479 | |||
480 | /** |
||
481 | * @param $teamId |
||
482 | * @param $userId |
||
483 | * @param $categoryId |
||
484 | * @param array $requestOptions |
||
485 | * @return ResponseInterface |
||
486 | */ |
||
487 | public function updateSidebarCategory($teamId, $userId, $categoryId, array $requestOptions) |
||
492 | |||
493 | /** |
||
494 | * @param $teamId |
||
495 | * @param $userId |
||
496 | * @param $categoryId |
||
497 | * @return ResponseInterface |
||
498 | */ |
||
499 | public function deleteSidebarCategory($teamId, $userId, $categoryId) |
||
504 | |||
505 | /** |
||
506 | * @param $channelId |
||
507 | * @param array $requestOptions |
||
508 | * @return ResponseInterface |
||
509 | */ |
||
510 | public function getChannelMembersCountsForEachGroupThatHasAtLeastOneMember($channelId, array $requestOptions) |
||
514 | |||
515 | /** |
||
516 | * @param $teamId |
||
517 | * @param array $requestOptions |
||
518 | * @return ResponseInterface |
||
519 | */ |
||
520 | public function getPrivateChannels($teamId, array $requestOptions = []) |
||
524 | } |
||
525 |