Conditions | 9 |
Paths | 35 |
Total Lines | 52 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
14 | public function __invoke(): Generator |
||
15 | { |
||
16 | yield 'Synchronizing groups from Azure.'; |
||
17 | |||
18 | $usergroup = new UserGroup(); |
||
19 | |||
20 | $groupIdByUid = []; |
||
21 | |||
22 | foreach ($this->getAzureGroups() as $azureGroupInfo) { |
||
23 | if ($usergroup->usergroup_exists($azureGroupInfo['displayName'])) { |
||
24 | $groupId = $usergroup->getIdByName($azureGroupInfo['displayName']); |
||
25 | |||
26 | if ($groupId) { |
||
27 | $usergroup->subscribe_users_to_usergroup($groupId, []); |
||
28 | |||
29 | yield sprintf('Class exists, all users unsubscribed: %s', $azureGroupInfo['displayName']); |
||
30 | } |
||
31 | } else { |
||
32 | $groupId = $usergroup->save([ |
||
33 | 'name' => $azureGroupInfo['displayName'], |
||
34 | 'description' => $azureGroupInfo['description'], |
||
35 | ]); |
||
36 | |||
37 | if ($groupId) { |
||
38 | yield sprintf('Class created: %s', $azureGroupInfo['displayName']); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | $groupIdByUid[$azureGroupInfo['id']] = $groupId; |
||
43 | } |
||
44 | |||
45 | yield '----------------'; |
||
46 | yield 'Subscribing users to groups'; |
||
47 | |||
48 | foreach ($groupIdByUid as $azureGroupUid => $groupId) { |
||
49 | $newGroupMembers = []; |
||
50 | |||
51 | yield sprintf('Obtaining members for group (ID %d)', $groupId); |
||
52 | |||
53 | foreach ($this->getAzureGroupMembers($azureGroupUid) as $azureGroupMember) { |
||
54 | if ($userId = $this->plugin->getUserIdByVerificationOrder($azureGroupMember, 'id')) { |
||
55 | $newGroupMembers[] = $userId; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | if ($newGroupMembers) { |
||
60 | $usergroup->subscribe_users_to_usergroup($groupId, $newGroupMembers); |
||
61 | |||
62 | yield sprintf( |
||
63 | 'User IDs subscribed in class (ID %d): %s', |
||
64 | $groupId, |
||
65 | implode(', ', $newGroupMembers) |
||
66 | ); |
||
71 |