| Conditions | 10 |
| Paths | 30 |
| Total Lines | 67 |
| Code Lines | 45 |
| 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 |
||
| 66 | protected function getAzureUsers(): Generator |
||
| 67 | { |
||
| 68 | $userFields = [ |
||
| 69 | 'givenName', |
||
| 70 | 'surname', |
||
| 71 | 'mail', |
||
| 72 | 'userPrincipalName', |
||
| 73 | 'businessPhones', |
||
| 74 | 'mobilePhone', |
||
| 75 | 'accountEnabled', |
||
| 76 | 'mailNickname', |
||
| 77 | 'id', |
||
| 78 | ]; |
||
| 79 | |||
| 80 | if ($this->providerParams['script_users_delta']) { |
||
| 81 | $usersDeltaLink = $this->syncStateRepo->findOneBy(['title' => AzureSyncState::USERS_DATALINK]); |
||
| 82 | |||
| 83 | $query = $usersDeltaLink |
||
| 84 | ? $usersDeltaLink->getValue() |
||
| 85 | : sprintf('$select=%s', implode(',', $userFields)); |
||
| 86 | } else { |
||
| 87 | $query = sprintf( |
||
| 88 | '$top=%d&$select=%s', |
||
| 89 | AzureSyncState::API_PAGE_SIZE, |
||
| 90 | implode(',', $userFields) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | $token = null; |
||
| 95 | |||
| 96 | do { |
||
| 97 | try { |
||
| 98 | $this->generateOrRefreshToken($token); |
||
| 99 | |||
| 100 | $azureUsersRequest = $this->provider->request( |
||
| 101 | 'get', |
||
| 102 | $this->providerParams['script_users_delta'] ? "users/delta?$query" : "users?$query", |
||
| 103 | $token |
||
| 104 | ); |
||
| 105 | } catch (GuzzleException|Exception $e) { |
||
| 106 | throw new Exception('Exception when requesting users from Azure: '.$e->getMessage()); |
||
| 107 | } |
||
| 108 | |||
| 109 | $azureUsersInfo = $azureUsersRequest['value'] ?? []; |
||
| 110 | |||
| 111 | foreach ($azureUsersInfo as $azureUserInfo) { |
||
| 112 | $azureUserInfo['mail'] = $azureUserInfo['mail'] ?? null; |
||
| 113 | $azureUserInfo['surname'] = $azureUserInfo['surname'] ?? null; |
||
| 114 | $azureUserInfo['givenName'] = $azureUserInfo['givenName'] ?? null; |
||
| 115 | |||
| 116 | yield $azureUserInfo; |
||
| 117 | } |
||
| 118 | |||
| 119 | $hasNextLink = false; |
||
| 120 | |||
| 121 | if (!empty($azureUsersRequest['@odata.nextLink'])) { |
||
| 122 | $hasNextLink = true; |
||
| 123 | $query = parse_url($azureUsersRequest['@odata.nextLink'], PHP_URL_QUERY); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($this->providerParams['script_users_delta'] && !empty($azureUsersRequest['@odata.deltaLink'])) { |
||
| 127 | $this->syncStateRepo->save( |
||
| 128 | AzureSyncState::USERS_DATALINK, |
||
| 129 | parse_url($azureUsersRequest['@odata.deltaLink'], PHP_URL_QUERY), |
||
| 130 | ); |
||
| 131 | } |
||
| 132 | } while ($hasNextLink); |
||
| 133 | } |
||
| 224 | } |