Conditions | 4 |
Paths | 6 |
Total Lines | 54 |
Code Lines | 33 |
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 users from Azure.'; |
||
17 | |||
18 | $token = $this->provider->getAccessToken( |
||
19 | 'client_credentials', |
||
20 | ['resource' => $this->provider->resource] |
||
21 | ); |
||
22 | |||
23 | $existingUsers = []; |
||
24 | |||
25 | foreach ($this->getAzureUsers($token) as $azureUserInfo) { |
||
26 | try { |
||
27 | $userId = $this->plugin->registerUser( |
||
28 | $token, |
||
29 | $this->provider, |
||
30 | $azureUserInfo, |
||
31 | 'users/'.$azureUserInfo['id'].'/memberOf', |
||
32 | 'id', |
||
33 | 'id' |
||
34 | ); |
||
35 | } catch (Exception $e) { |
||
36 | yield $e->getMessage(); |
||
37 | |||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $existingUsers[] = $userId; |
||
42 | |||
43 | $userInfo = api_get_user_info($userId); |
||
44 | |||
45 | yield sprintf('User info: %s', serialize($userInfo)); |
||
46 | } |
||
47 | |||
48 | if ('true' === $this->plugin->get(AzureActiveDirectory::SETTING_DEACTIVATE_NONEXISTING_USERS)) { |
||
49 | yield '----------------'; |
||
50 | |||
51 | yield 'Trying deactivate non-existing users in Azure'; |
||
52 | |||
53 | $users = UserManager::getRepository()->findByAuthSource('azure'); |
||
54 | $userIdList = array_map( |
||
55 | function ($user) { |
||
56 | return $user->getId(); |
||
57 | }, |
||
58 | $users |
||
59 | ); |
||
60 | |||
61 | $nonExistingUsers = array_diff($userIdList, $existingUsers); |
||
62 | |||
63 | UserManager::deactivate_users($nonExistingUsers); |
||
64 | |||
65 | yield sprintf( |
||
66 | 'Deactivated users IDs: %s', |
||
67 | implode(', ', $nonExistingUsers) |
||
68 | ); |
||
119 |