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 |
||
12 | public function __invoke(): Generator |
||
13 | { |
||
14 | yield 'Synchronizing groups from Azure.'; |
||
15 | |||
16 | $usergroup = new UserGroup(); |
||
17 | |||
18 | $groupIdByUid = []; |
||
19 | |||
20 | foreach ($this->getAzureGroups() as $azureGroupInfo) { |
||
21 | if ($usergroup->usergroup_exists($azureGroupInfo['displayName'])) { |
||
22 | $groupId = $usergroup->getIdByName($azureGroupInfo['displayName']); |
||
23 | |||
24 | if ($groupId) { |
||
25 | $usergroup->subscribe_users_to_usergroup($groupId, []); |
||
26 | |||
27 | yield sprintf('Class exists, all users unsubscribed: %s', $azureGroupInfo['displayName']); |
||
28 | } |
||
29 | } else { |
||
30 | $groupId = $usergroup->save([ |
||
31 | 'name' => $azureGroupInfo['displayName'], |
||
32 | 'description' => $azureGroupInfo['description'], |
||
33 | ]); |
||
34 | |||
35 | if ($groupId) { |
||
36 | yield sprintf('Class created: %s', $azureGroupInfo['displayName']); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | $groupIdByUid[$azureGroupInfo['id']] = $groupId; |
||
41 | } |
||
42 | |||
43 | yield '----------------'; |
||
44 | yield 'Subscribing users to groups'; |
||
45 | |||
46 | foreach ($groupIdByUid as $azureGroupUid => $groupId) { |
||
47 | $newGroupMembers = []; |
||
48 | |||
49 | yield sprintf('Obtaining members for group (ID %d)', $groupId); |
||
50 | |||
51 | foreach ($this->getAzureGroupMembers($azureGroupUid) as $azureGroupMember) { |
||
52 | if ($userId = $this->plugin->getUserIdByVerificationOrder($azureGroupMember, 'id')) { |
||
53 | $newGroupMembers[] = $userId; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | if ($newGroupMembers) { |
||
58 | $usergroup->subscribe_users_to_usergroup($groupId, $newGroupMembers); |
||
59 | |||
60 | yield sprintf( |
||
61 | 'User IDs subscribed in class (ID %d): %s', |
||
62 | $groupId, |
||
63 | implode(', ', $newGroupMembers) |
||
64 | ); |
||
69 |