Complex classes like DeprecatedMembersRequest 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 DeprecatedMembersRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class DeprecatedMembersRequest extends DeprecatedMembersRequestBuilder { |
||
41 | |||
42 | |||
43 | use TStringTools; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Returns information about a member. |
||
48 | * |
||
49 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
50 | * In case of interaction with users, Please use MembersService->getMember() instead. |
||
51 | * |
||
52 | * @param string $circleUniqueId |
||
53 | * @param string $userId |
||
54 | * @param $type |
||
55 | * |
||
56 | * @param string $instance |
||
57 | * |
||
58 | * @return DeprecatedMember |
||
59 | * @throws MemberDoesNotExistException |
||
60 | */ |
||
61 | public function forceGetMember($circleUniqueId, $userId, $type, string $instance = '') { |
||
83 | |||
84 | |||
85 | /** |
||
86 | * @param string $memberId |
||
87 | * |
||
88 | * @return DeprecatedMember |
||
89 | * @throws MemberDoesNotExistException |
||
90 | */ |
||
91 | public function forceGetMemberById(string $memberId): DeprecatedMember { |
||
106 | |||
107 | |||
108 | /** |
||
109 | * Returns members list of a circle, based on their level. |
||
110 | * |
||
111 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
112 | * In case of interaction with users, Please use getMembers() instead. |
||
113 | * |
||
114 | * @param string $circleUniqueId |
||
115 | * @param int $level |
||
116 | * @param int $type |
||
117 | * @param bool $incGroup |
||
118 | * |
||
119 | * @return DeprecatedMember[] |
||
120 | */ |
||
121 | public function forceGetMembers( |
||
150 | |||
151 | |||
152 | /** |
||
153 | * Returns all members. |
||
154 | * |
||
155 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
156 | * In case of interaction with users, Please use getMembers() instead. |
||
157 | * |
||
158 | * |
||
159 | * @return DeprecatedMember[] |
||
160 | */ |
||
161 | public function forceGetAllMembers() { |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Returns members generated from Contacts that are not 'checked' (as not sent existing shares). |
||
178 | * |
||
179 | * |
||
180 | * @return DeprecatedMember[] |
||
181 | */ |
||
182 | public function forceGetAllRecentContactEdit() { |
||
201 | |||
202 | |||
203 | /** |
||
204 | * @param DeprecatedMember $member |
||
205 | * @param bool $check |
||
206 | */ |
||
207 | public function checkMember(DeprecatedMember $member, bool $check) { |
||
215 | |||
216 | |||
217 | /** |
||
218 | * @param string $circleUniqueId |
||
219 | * @param DeprecatedMember $viewer |
||
220 | * @param bool $force |
||
221 | * |
||
222 | * @return DeprecatedMember[] |
||
223 | */ |
||
224 | public function getMembers(string $circleUniqueId, ?DeprecatedMember $viewer, bool $force = false) { |
||
246 | |||
247 | |||
248 | /** |
||
249 | * forceGetGroup(); |
||
250 | * |
||
251 | * returns group information as a member within a Circle. |
||
252 | * |
||
253 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
254 | * In case of interaction with users, Please use getGroup() instead. |
||
255 | * |
||
256 | * @param string $circleUniqueId |
||
257 | * @param string $groupId |
||
258 | * @param string $instance |
||
259 | * |
||
260 | * @return DeprecatedMember |
||
261 | * @throws MemberDoesNotExistException |
||
262 | */ |
||
263 | public function forceGetGroup(string $circleUniqueId, string $groupId, string $instance) { |
||
280 | |||
281 | |||
282 | /** |
||
283 | * includeGroupMembers(); |
||
284 | * |
||
285 | * This function will get members of a circle throw NCGroups and fill the result an existing |
||
286 | * Members List. In case of duplicate, higher level will be kept. |
||
287 | * |
||
288 | * @param DeprecatedMember[] $members |
||
289 | * @param string $circleUniqueId |
||
290 | * @param int $level |
||
291 | */ |
||
292 | private function includeGroupMembers(array &$members, $circleUniqueId, $level) { |
||
296 | |||
297 | |||
298 | /** |
||
299 | * avoidDuplicateMembers(); |
||
300 | * |
||
301 | * Use this function to add members to the list (1st argument), keeping the higher level in case |
||
302 | * of duplicate |
||
303 | * |
||
304 | * @param DeprecatedMember[] $members |
||
305 | * @param DeprecatedMember[] $groupMembers |
||
306 | */ |
||
307 | public function avoidDuplicateMembers(array &$members, array $groupMembers) { |
||
317 | |||
318 | |||
319 | /** |
||
320 | * returns the index of a specific UserID in a Members List |
||
321 | * |
||
322 | * @param array $members |
||
323 | * @param $userId |
||
324 | * |
||
325 | * @return int |
||
326 | */ |
||
327 | private function indexOfMember(array $members, $userId) { |
||
337 | |||
338 | |||
339 | /** |
||
340 | * Check if a fresh member can be generated (by addMember/joinCircle) |
||
341 | * |
||
342 | * @param string $circleUniqueId |
||
343 | * @param string $name |
||
344 | * @param int $type |
||
345 | * |
||
346 | * @param string $instance |
||
347 | * |
||
348 | * @return DeprecatedMember |
||
349 | */ |
||
350 | public function getFreshNewMember($circleUniqueId, string $name, int $type, string $instance) { |
||
368 | |||
369 | |||
370 | /** |
||
371 | * Returns members list of all Group Members of a Circle. The Level of the linked group will be |
||
372 | * assigned to each entry |
||
373 | * |
||
374 | * NOTE: Can contains duplicate. |
||
375 | * |
||
376 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
377 | * Do not use in case of direct interaction with users. |
||
378 | * |
||
379 | * @param string $circleUniqueId |
||
380 | * @param int $level |
||
381 | * |
||
382 | * @return DeprecatedMember[] |
||
383 | */ |
||
384 | public function forceGetGroupMembers($circleUniqueId, $level = DeprecatedMember::LEVEL_MEMBER) { |
||
401 | |||
402 | |||
403 | /** |
||
404 | * returns all users from a Group as a list of Members. |
||
405 | * |
||
406 | * @param DeprecatedMember $group |
||
407 | * |
||
408 | * @return DeprecatedMember[] |
||
409 | */ |
||
410 | public function getGroupMemberMembers(DeprecatedMember $group) { |
||
429 | |||
430 | |||
431 | /** |
||
432 | * return the higher level group linked to a circle, that include the userId. |
||
433 | * |
||
434 | * WARNING: This function does not filters data regarding the current user/viewer. |
||
435 | * In case of direct interaction with users, Please don't use this. |
||
436 | * |
||
437 | * @param string $circleUniqueId |
||
438 | * @param string $userId |
||
439 | * |
||
440 | * @return DeprecatedMember |
||
441 | */ |
||
442 | public function forceGetHigherLevelGroupFromUser($circleUniqueId, $userId) { |
||
466 | |||
467 | |||
468 | /** |
||
469 | * Insert Member into database. |
||
470 | * |
||
471 | * @param DeprecatedMember $member |
||
472 | * |
||
473 | * @throws MemberAlreadyExistsException |
||
474 | */ |
||
475 | public function createMember(DeprecatedMember $member) { |
||
507 | |||
508 | |||
509 | /** |
||
510 | * @param string $circleUniqueId |
||
511 | * @param DeprecatedMember $viewer |
||
512 | * |
||
513 | * @return DeprecatedMember[] |
||
514 | */ |
||
515 | public function getGroupsFromCircle($circleUniqueId, DeprecatedMember $viewer) { |
||
539 | |||
540 | |||
541 | /** |
||
542 | * update database entry for a specific Member. |
||
543 | * |
||
544 | * @param DeprecatedMember $member |
||
545 | */ |
||
546 | public function updateMemberLevel(DeprecatedMember $member) { |
||
560 | |||
561 | |||
562 | /** |
||
563 | * update database entry for a specific Member. |
||
564 | * |
||
565 | * @param DeprecatedMember $member |
||
566 | */ |
||
567 | public function updateMemberInfo(DeprecatedMember $member) { |
||
582 | |||
583 | |||
584 | /** |
||
585 | * update database entry for a specific Member. |
||
586 | * |
||
587 | * @param DeprecatedMember $member |
||
588 | */ |
||
589 | public function updateContactMeta(DeprecatedMember $member) { |
||
597 | |||
598 | |||
599 | /** |
||
600 | * removeAllFromCircle(); |
||
601 | * |
||
602 | * Remove All members from a Circle. Used when deleting a Circle. |
||
603 | * |
||
604 | * @param string $uniqueCircleId |
||
605 | */ |
||
606 | public function removeAllFromCircle($uniqueCircleId) { |
||
613 | |||
614 | |||
615 | /** |
||
616 | * removeAllMembershipsFromUser(); |
||
617 | * |
||
618 | * remove All membership from a User. Used when removing a User from the Cloud. |
||
619 | * |
||
620 | * @param DeprecatedMember $member |
||
621 | */ |
||
622 | public function removeAllMembershipsFromUser(DeprecatedMember $member) { |
||
645 | |||
646 | |||
647 | /** |
||
648 | * remove member, identified by its id, type and circleId |
||
649 | * |
||
650 | * @param DeprecatedMember $member |
||
651 | */ |
||
652 | public function removeMember(DeprecatedMember $member) { |
||
669 | |||
670 | /** |
||
671 | * update database entry for a specific Group. |
||
672 | * |
||
673 | * @param DeprecatedMember $member |
||
674 | * |
||
675 | * @return bool |
||
676 | */ |
||
677 | public function updateGroup(DeprecatedMember $member) { |
||
686 | |||
687 | |||
688 | public function unlinkAllFromGroup($groupId) { |
||
697 | |||
698 | |||
699 | /** |
||
700 | * @param string $contactId |
||
701 | * |
||
702 | * @return DeprecatedMember[] |
||
703 | */ |
||
704 | public function getMembersByContactId(string $contactId = ''): array { |
||
723 | |||
724 | |||
725 | /** |
||
726 | * @param string $circleId |
||
727 | * @param string $contactId |
||
728 | * |
||
729 | * @return DeprecatedMember |
||
730 | * @throws MemberDoesNotExistException |
||
731 | */ |
||
732 | public function getContactMember(string $circleId, string $contactId): DeprecatedMember { |
||
747 | |||
748 | |||
749 | /** |
||
750 | * @param string $contactId |
||
751 | * |
||
752 | * @return DeprecatedMember[] |
||
753 | */ |
||
754 | public function getLocalContactMembers(string $contactId): array { |
||
768 | |||
769 | |||
770 | /** |
||
771 | * @param string $contactId |
||
772 | * @param int $type |
||
773 | */ |
||
774 | public function removeMembersByContactId(string $contactId, int $type = 0) { |
||
788 | |||
789 | |||
790 | } |
||
791 |
This class, trait or interface has been deprecated.