Complex classes like TeamModel 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 TeamModel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class TeamModel extends AbstractModel |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | public static $endpoint = '/teams'; |
||
32 | |||
33 | /** |
||
34 | * @param array $requestOptions |
||
35 | * @return ResponseInterface |
||
36 | */ |
||
37 | public function createTeam(array $requestOptions) |
||
41 | |||
42 | /** |
||
43 | * @param array $requestOptions |
||
44 | * @return ResponseInterface |
||
45 | */ |
||
46 | public function getTeams(array $requestOptions) |
||
50 | |||
51 | /** |
||
52 | * @param $teamId |
||
53 | * @return ResponseInterface |
||
54 | */ |
||
55 | public function getTeam($teamId) |
||
59 | |||
60 | /** |
||
61 | * @param $teamId |
||
62 | * @param array $requestOptions |
||
63 | * @return ResponseInterface |
||
64 | */ |
||
65 | public function updateTeam($teamId, array $requestOptions) |
||
69 | |||
70 | /** |
||
71 | * @param $teamId |
||
72 | * @return ResponseInterface |
||
73 | */ |
||
74 | public function deleteTeam($teamId) |
||
78 | |||
79 | /** |
||
80 | * @param $teamId |
||
81 | * @param array $requestOptions |
||
82 | * @return ResponseInterface |
||
83 | */ |
||
84 | public function patchTeam($teamId, array $requestOptions) |
||
88 | |||
89 | /** |
||
90 | * @param $teamId |
||
91 | * @param array $requestOptions |
||
92 | * @return ResponseInterface |
||
93 | */ |
||
94 | public function updateTeamPrivacy($teamId, array $requestOptions) |
||
98 | |||
99 | /** |
||
100 | * @param $teamId |
||
101 | * @return ResponseInterface |
||
102 | */ |
||
103 | public function restoreTeam($teamId) |
||
107 | |||
108 | /** |
||
109 | * @param $teamName |
||
110 | * @return ResponseInterface |
||
111 | */ |
||
112 | public function getTeamByName($teamName) |
||
116 | |||
117 | /** |
||
118 | * @param array $requestOptions |
||
119 | * @return ResponseInterface |
||
120 | */ |
||
121 | public function searchTeams(array $requestOptions) |
||
125 | |||
126 | /** |
||
127 | * @param $teamName |
||
128 | * @return ResponseInterface |
||
129 | */ |
||
130 | public function checkTeamExists($teamName) |
||
134 | |||
135 | /** |
||
136 | * @param $userId |
||
137 | * @return ResponseInterface |
||
138 | */ |
||
139 | public function getUserTeams($userId) |
||
143 | |||
144 | /** |
||
145 | * @param $teamId |
||
146 | * @param array $requestOptions |
||
147 | * @return ResponseInterface |
||
148 | */ |
||
149 | public function getTeamMembers($teamId, array $requestOptions) |
||
153 | |||
154 | /** |
||
155 | * @param $teamId |
||
156 | * @param array $requestOptions |
||
157 | * @return ResponseInterface |
||
158 | */ |
||
159 | public function addUser($teamId, array $requestOptions) |
||
163 | |||
164 | /** |
||
165 | * @param array $requestOptions |
||
166 | * @return ResponseInterface |
||
167 | */ |
||
168 | public function addUserFromInvite(array $requestOptions) |
||
172 | |||
173 | /** |
||
174 | * @param $teamId |
||
175 | * @param array $requestOptions |
||
176 | * @return ResponseInterface |
||
177 | */ |
||
178 | public function addMultipleUsers($teamId, array $requestOptions) |
||
182 | |||
183 | /** |
||
184 | * @param $userId |
||
185 | * @param array $requestOptions |
||
186 | * @return ResponseInterface |
||
187 | */ |
||
188 | public function getTeamMembersForUser($userId, array $requestOptions) |
||
192 | |||
193 | /** |
||
194 | * @param $teamId |
||
195 | * @param $userId |
||
196 | * @return ResponseInterface |
||
197 | */ |
||
198 | public function getTeamMember($teamId, $userId) |
||
202 | |||
203 | /** |
||
204 | * @param $teamId |
||
205 | * @param $userId |
||
206 | * @return ResponseInterface |
||
207 | */ |
||
208 | public function removeUser($teamId, $userId) |
||
212 | |||
213 | /** |
||
214 | * @param $teamId |
||
215 | * @param array $requestOptions |
||
216 | * @return ResponseInterface |
||
217 | */ |
||
218 | public function getTeamMembersByIds($teamId, array $requestOptions) |
||
222 | |||
223 | /** |
||
224 | * @param $teamId |
||
225 | * @return ResponseInterface |
||
226 | */ |
||
227 | public function getTeamStats($teamId) |
||
231 | |||
232 | /** |
||
233 | * @param $teamId |
||
234 | * @return ResponseInterface |
||
235 | */ |
||
236 | public function regenerateInviteID($teamId) |
||
240 | |||
241 | /** |
||
242 | * @param $teamId |
||
243 | * @return ResponseInterface |
||
244 | */ |
||
245 | public function getTeamIcon($teamId) |
||
249 | |||
250 | /** |
||
251 | * @param $teamId |
||
252 | * @param array $requestOptions |
||
253 | * @return ResponseInterface |
||
254 | */ |
||
255 | public function setTeamIcon($teamId, array $requestOptions) |
||
261 | |||
262 | /** |
||
263 | * @param $teamId |
||
264 | * @return ResponseInterface |
||
265 | */ |
||
266 | public function removeTeamIcon($teamId) |
||
270 | |||
271 | /** |
||
272 | * @param $teamId |
||
273 | * @param $userId |
||
274 | * @param array $requestOptions |
||
275 | * @return ResponseInterface |
||
276 | */ |
||
277 | public function updateTeamMemberRoles($teamId, $userId, array $requestOptions) |
||
281 | |||
282 | /** |
||
283 | * @param $teamId |
||
284 | * @param $userId |
||
285 | * @param array $requestOptions |
||
286 | * @return ResponseInterface |
||
287 | */ |
||
288 | public function updateSchemeDerivedRolesOfMember($teamId, $userId, array $requestOptions) |
||
292 | |||
293 | /** |
||
294 | * @param $userId |
||
295 | * @param array $requestOptions |
||
296 | * @return ResponseInterface |
||
297 | */ |
||
298 | public function getUserTotalUnreadMessagesFromTeams($userId, array $requestOptions = []) |
||
302 | |||
303 | /** |
||
304 | * @param $userId |
||
305 | * @param $teamId |
||
306 | * @return ResponseInterface |
||
307 | */ |
||
308 | public function getUserTotalUnreadMessagesFromTeam($userId, $teamId) |
||
312 | |||
313 | /** |
||
314 | * @param $teamId |
||
315 | * @param array $requestOptions |
||
316 | * @return ResponseInterface |
||
317 | */ |
||
318 | public function inviteUsersByEmail($teamId, array $requestOptions) |
||
322 | |||
323 | /** |
||
324 | * @param $teamId |
||
325 | * @param array $requestOptions |
||
326 | * @return ResponseInterface |
||
327 | */ |
||
328 | public function inviteGuestsByEmail($teamId, array $requestOptions) |
||
332 | |||
333 | /** |
||
334 | * @return ResponseInterface |
||
335 | */ |
||
336 | public function invalidateActiveEmailInvitations() |
||
340 | |||
341 | /** |
||
342 | * @param $teamId |
||
343 | * @param array $requestOptions |
||
344 | * @return ResponseInterface |
||
345 | */ |
||
346 | public function importTeamFromOtherApplication($teamId, array $requestOptions) |
||
352 | |||
353 | /** |
||
354 | * @param $inviteId |
||
355 | * @return ResponseInterface |
||
356 | */ |
||
357 | public function getInviteInfoForTeam($inviteId) |
||
361 | |||
362 | /** |
||
363 | * @param $teamId |
||
364 | * @param array $requestOptions |
||
365 | * @return ResponseInterface |
||
366 | */ |
||
367 | public function setTeamScheme($teamId, array $requestOptions) |
||
371 | |||
372 | /** |
||
373 | * @param $teamId |
||
374 | * @param array $requestOptions |
||
375 | * @return ResponseInterface |
||
376 | */ |
||
377 | public function getTeamMembersMinusGroupMembers($teamId, array $requestOptions) |
||
381 | |||
382 | /** |
||
383 | * @param $teamId |
||
384 | * @param array $requestOptions |
||
385 | * @return ResponseInterface |
||
386 | */ |
||
387 | public function getPublicChannels($teamId, array $requestOptions) |
||
391 | |||
392 | /** |
||
393 | * @param $teamId |
||
394 | * @param array $requestOptions |
||
395 | * @return ResponseInterface |
||
396 | */ |
||
397 | public function getDeletedChannels($teamId, array $requestOptions) |
||
401 | |||
402 | /** |
||
403 | * @param $teamId |
||
404 | * @param array $requestOptions |
||
405 | * @return ResponseInterface |
||
406 | */ |
||
407 | public function searchChannels($teamId, array $requestOptions) |
||
411 | |||
412 | /** |
||
413 | * @param $teamId |
||
414 | * @param array $requestOptions |
||
415 | * @return ResponseInterface |
||
416 | */ |
||
417 | public function listCommandsAutocompleteData($teamId, array $requestOptions) |
||
422 | |||
423 | /** |
||
424 | * @param $teamId |
||
425 | * @param array $requestOptions |
||
426 | * @return ResponseInterface |
||
427 | */ |
||
428 | public function getTeamGroupsByChannels($teamId, array $requestOptions) |
||
432 | } |
||
433 |