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