Complex classes like MembersService 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 MembersService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 67 | class MembersService { |
||
| 68 | |||
| 69 | |||
| 70 | use TNC19Request; |
||
| 71 | use TArrayTools; |
||
| 72 | |||
| 73 | |||
| 74 | /** @var string */ |
||
| 75 | private $userId; |
||
| 76 | |||
| 77 | /** @var IL10N */ |
||
| 78 | private $l10n; |
||
| 79 | |||
| 80 | /** @var IUserManager */ |
||
| 81 | private $userManager; |
||
| 82 | |||
| 83 | /** @var ConfigService */ |
||
| 84 | private $configService; |
||
| 85 | |||
| 86 | /** @var CirclesRequest */ |
||
| 87 | private $circlesRequest; |
||
| 88 | |||
| 89 | /** @var MembersRequest */ |
||
| 90 | private $membersRequest; |
||
| 91 | |||
| 92 | /** @var AccountsRequest */ |
||
| 93 | private $accountsRequest; |
||
| 94 | |||
| 95 | /** @var SharesRequest */ |
||
| 96 | private $sharesRequest; |
||
| 97 | |||
| 98 | /** @var TokensRequest */ |
||
| 99 | private $tokensRequest; |
||
| 100 | |||
| 101 | /** @var EventsService */ |
||
| 102 | private $eventsService; |
||
| 103 | |||
| 104 | /** @var GSUpstreamService */ |
||
| 105 | private $gsUpstreamService; |
||
| 106 | |||
| 107 | /** @var FileSharingBroadcaster */ |
||
| 108 | private $fileSharingBroadcaster; |
||
| 109 | |||
| 110 | /** @var MiscService */ |
||
| 111 | private $miscService; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * MembersService constructor. |
||
| 115 | * |
||
| 116 | * @param string $userId |
||
| 117 | * @param IL10N $l10n |
||
| 118 | * @param IUserManager $userManager |
||
| 119 | * @param ConfigService $configService |
||
| 120 | * @param CirclesRequest $circlesRequest |
||
| 121 | * @param MembersRequest $membersRequest |
||
| 122 | * @param AccountsRequest $accountsRequest |
||
| 123 | * @param SharesRequest $sharesRequest |
||
| 124 | * @param TokensRequest $tokensRequest |
||
| 125 | * @param EventsService $eventsService |
||
| 126 | * @param GSUpstreamService $gsUpstreamService |
||
| 127 | * @param FileSharingBroadcaster $fileSharingBroadcaster |
||
| 128 | * @param MiscService $miscService |
||
| 129 | */ |
||
| 130 | public function __construct( |
||
| 151 | |||
| 152 | |||
| 153 | /** |
||
| 154 | * addMember(); |
||
| 155 | * |
||
| 156 | * add a new member to a circle. |
||
| 157 | * |
||
| 158 | * @param string $circleUniqueId |
||
| 159 | * @param $ident |
||
| 160 | * @param int $type |
||
| 161 | * @param string $instance |
||
| 162 | * |
||
| 163 | * @param bool $force |
||
| 164 | * |
||
| 165 | * @return array |
||
| 166 | * @throws Exception |
||
| 167 | */ |
||
| 168 | public function addMember($circleUniqueId, $ident, $type, string $instance, bool $force = false) { |
||
| 186 | |||
| 187 | |||
| 188 | /** |
||
| 189 | * add a single member to a circle. |
||
| 190 | * |
||
| 191 | * @param Circle $circle |
||
| 192 | * @param string $ident |
||
| 193 | * @param int $type |
||
| 194 | * |
||
| 195 | * @param string $instance |
||
| 196 | * @param bool $force |
||
| 197 | * |
||
| 198 | * @return Member |
||
| 199 | * @throws EmailAccountInvalidFormatException |
||
| 200 | * @throws NoUserException |
||
| 201 | * @throws Exception |
||
| 202 | */ |
||
| 203 | private function addSingleMember(Circle $circle, $ident, $type, $instance = '', bool $force = false |
||
| 234 | |||
| 235 | |||
| 236 | /** |
||
| 237 | * add a bunch of users to a circle based on the type of the 'bunch' |
||
| 238 | * |
||
| 239 | * @param Circle $circle |
||
| 240 | * @param string $ident |
||
| 241 | * @param int $type |
||
| 242 | * |
||
| 243 | * @return Member[] |
||
| 244 | * @throws Exception |
||
| 245 | */ |
||
| 246 | private function addMassiveMembers(Circle $circle, $ident, $type): array { |
||
| 257 | |||
| 258 | |||
| 259 | /** |
||
| 260 | * add a new member based on its type. |
||
| 261 | * |
||
| 262 | * @param Circle $circle |
||
| 263 | * @param Member $member |
||
| 264 | * |
||
| 265 | * @throws CircleTypeNotValidException |
||
| 266 | * @throws MemberCantJoinCircleException |
||
| 267 | */ |
||
| 268 | public function addMemberBasedOnItsType(Circle $circle, Member $member) { |
||
| 273 | |||
| 274 | |||
| 275 | /** |
||
| 276 | * @param Circle $circle |
||
| 277 | * @param Member $member |
||
| 278 | * |
||
| 279 | * @throws CircleTypeNotValidException |
||
| 280 | * @throws MemberCantJoinCircleException |
||
| 281 | */ |
||
| 282 | private function addLocalMember(Circle $circle, Member $member) { |
||
| 294 | |||
| 295 | |||
| 296 | /** |
||
| 297 | * add mail address as contact. |
||
| 298 | * |
||
| 299 | * @param Member $member |
||
| 300 | */ |
||
| 301 | private function addEmailAddress(Member $member) { |
||
| 309 | |||
| 310 | |||
| 311 | /** |
||
| 312 | * // TODO - check this on GS setup |
||
| 313 | * Add contact as member. |
||
| 314 | * |
||
| 315 | * @param Member $member |
||
| 316 | */ |
||
| 317 | private function addContact(Member $member) { |
||
| 325 | |||
| 326 | |||
| 327 | /** |
||
| 328 | * // TODO - check this on GS setup |
||
| 329 | * Verify the availability of an ident, based on its type. |
||
| 330 | * |
||
| 331 | * @param string $ident |
||
| 332 | * @param int $type |
||
| 333 | * @param string $instance |
||
| 334 | * |
||
| 335 | * @throws EmailAccountInvalidFormatException |
||
| 336 | * @throws NoUserException |
||
| 337 | */ |
||
| 338 | public function verifyIdentBasedOnItsType(&$ident, $type, string $instance = '') { |
||
| 347 | |||
| 348 | |||
| 349 | /** |
||
| 350 | * Verify if a local account is valid. |
||
| 351 | * |
||
| 352 | * @param $ident |
||
| 353 | * @param $type |
||
| 354 | * |
||
| 355 | * @param string $instance |
||
| 356 | * |
||
| 357 | * @throws NoUserException |
||
| 358 | */ |
||
| 359 | private function verifyIdentLocalMember(&$ident, $type, string $instance = '') { |
||
| 372 | |||
| 373 | |||
| 374 | /** |
||
| 375 | * Verify if a mail have a valid format. |
||
| 376 | * |
||
| 377 | * @param string $ident |
||
| 378 | * @param int $type |
||
| 379 | * |
||
| 380 | * @throws EmailAccountInvalidFormatException |
||
| 381 | */ |
||
| 382 | private function verifyIdentEmailAddress(string $ident, int $type) { |
||
| 399 | |||
| 400 | |||
| 401 | /** |
||
| 402 | * Verify if a contact exist in current user address books. |
||
| 403 | * |
||
| 404 | * @param $ident |
||
| 405 | * @param $type |
||
| 406 | * |
||
| 407 | * @throws NoUserException |
||
| 408 | * @throws EmailAccountInvalidFormatException |
||
| 409 | */ |
||
| 410 | private function verifyIdentContact(&$ident, $type) { |
||
| 429 | |||
| 430 | |||
| 431 | /** |
||
| 432 | * @param Circle $circle |
||
| 433 | * @param string $groupId |
||
| 434 | * |
||
| 435 | * @return Member[] |
||
| 436 | * @throws Exception |
||
| 437 | */ |
||
| 438 | private function addGroupMembers(Circle $circle, $groupId): array { |
||
| 457 | |||
| 458 | |||
| 459 | /** |
||
| 460 | * // TODO - check this on GS setup |
||
| 461 | * |
||
| 462 | * @param Circle $circle |
||
| 463 | * @param string $mails |
||
| 464 | * |
||
| 465 | * @return Member[] |
||
| 466 | */ |
||
| 467 | private function addMassiveMails(Circle $circle, $mails): array { |
||
| 489 | |||
| 490 | |||
| 491 | /** |
||
| 492 | * getMember(); |
||
| 493 | * |
||
| 494 | * Will return any data of a user related to a circle (as a Member). User can be a 'non-member' |
||
| 495 | * Viewer needs to be at least Member of the Circle |
||
| 496 | * |
||
| 497 | * @param $circleId |
||
| 498 | * @param $userId |
||
| 499 | * @param $type |
||
| 500 | * @param bool $forceAll |
||
| 501 | * |
||
| 502 | * @return Member |
||
| 503 | * @throws CircleDoesNotExistException |
||
| 504 | * @throws ConfigNoCircleAvailableException |
||
| 505 | * @throws MemberDoesNotExistException |
||
| 506 | */ |
||
| 507 | public function getMember($circleId, $userId, $type, $forceAll = false) { |
||
| 519 | |||
| 520 | |||
| 521 | /** |
||
| 522 | * @param string $memberId |
||
| 523 | * |
||
| 524 | * @return Member |
||
| 525 | * @throws MemberDoesNotExistException |
||
| 526 | */ |
||
| 527 | public function getMemberById(string $memberId): Member { |
||
| 530 | |||
| 531 | |||
| 532 | /** |
||
| 533 | * @param Member $member |
||
| 534 | * |
||
| 535 | * @throws Exception |
||
| 536 | */ |
||
| 537 | public function updateMember(Member $member) { |
||
| 544 | |||
| 545 | |||
| 546 | /** |
||
| 547 | * @param string $circleUniqueId |
||
| 548 | * @param string $name |
||
| 549 | * @param int $type |
||
| 550 | * @param string $instance |
||
| 551 | * @param int $level |
||
| 552 | * @param bool $force |
||
| 553 | * |
||
| 554 | * @return array |
||
| 555 | * @throws CircleDoesNotExistException |
||
| 556 | * @throws CircleTypeNotValidException |
||
| 557 | * @throws ConfigNoCircleAvailableException |
||
| 558 | * @throws MemberDoesNotExistException |
||
| 559 | * @throws Exception |
||
| 560 | */ |
||
| 561 | public function levelMember( |
||
| 597 | |||
| 598 | |||
| 599 | /** |
||
| 600 | * @param string $circleUniqueId |
||
| 601 | * @param string $name |
||
| 602 | * @param int $type |
||
| 603 | * @param string $instance |
||
| 604 | * @param bool $force |
||
| 605 | * |
||
| 606 | * @return Member[] |
||
| 607 | * @throws CircleDoesNotExistException |
||
| 608 | * @throws ConfigNoCircleAvailableException |
||
| 609 | * @throws MemberDoesNotExistException |
||
| 610 | * @throws MemberIsNotModeratorException |
||
| 611 | * @throws Exception |
||
| 612 | */ |
||
| 613 | public function removeMember( |
||
| 640 | |||
| 641 | |||
| 642 | /** |
||
| 643 | * When a user is removed, remove him from all Circles |
||
| 644 | * |
||
| 645 | * @param string $userId |
||
| 646 | * |
||
| 647 | * @throws Exception |
||
| 648 | */ |
||
| 649 | public function onUserRemoved(string $userId) { |
||
| 659 | |||
| 660 | |||
| 661 | /** |
||
| 662 | * @param Member $member |
||
| 663 | * @param bool $fresh |
||
| 664 | */ |
||
| 665 | public function updateCachedName(Member $member, bool $fresh = true) { |
||
| 682 | |||
| 683 | |||
| 684 | /** |
||
| 685 | * @param Circle $circle |
||
| 686 | */ |
||
| 687 | public function updateCachedFromCircle(Circle $circle) { |
||
| 697 | |||
| 698 | |||
| 699 | /** |
||
| 700 | * @param string $ident |
||
| 701 | * @param bool $fresh |
||
| 702 | * |
||
| 703 | * @return string |
||
| 704 | * @throws GSStatusException |
||
| 705 | */ |
||
| 706 | public function getUserDisplayName(string $ident, bool $fresh = false): string { |
||
| 727 | |||
| 728 | |||
| 729 | /** |
||
| 730 | * @param string $ident |
||
| 731 | * |
||
| 732 | * @return string |
||
| 733 | * @throws GSStatusException |
||
| 734 | */ |
||
| 735 | private function getGlobalScaleUserDisplayName(string $ident): string { |
||
| 757 | |||
| 758 | |||
| 759 | /** |
||
| 760 | * @param Member $member |
||
| 761 | * |
||
| 762 | * @return Circle |
||
| 763 | * @throws CircleDoesNotExistException |
||
| 764 | */ |
||
| 765 | public function getCircleFromMembership(Member $member): Circle { |
||
| 768 | |||
| 769 | |||
| 770 | /** |
||
| 771 | * @param Member[] $curr |
||
| 772 | * @param Member[] $new |
||
| 773 | * |
||
| 774 | * @return array |
||
| 775 | */ |
||
| 776 | private function filterDuplicate(array $curr, array $new): array { |
||
| 792 | |||
| 793 | |||
| 794 | } |
||
| 795 | |||
| 796 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.