Conditions | 10 |
Paths | 27 |
Total Lines | 59 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
122 | protected function getAzureGroups(): Generator |
||
123 | { |
||
124 | $groupFields = [ |
||
125 | 'id', |
||
126 | 'displayName', |
||
127 | 'description', |
||
128 | ]; |
||
129 | |||
130 | $getUsergroupsDelta = 'true' === $this->plugin->get(AzureActiveDirectory::SETTING_GET_USERGROUPS_DELTA); |
||
131 | |||
132 | if ($getUsergroupsDelta) { |
||
133 | $usergroupsDeltaLink = $this->plugin->getSyncState(AzureSyncState::USERGROUPS_DATALINK); |
||
134 | |||
135 | $query = $usergroupsDeltaLink |
||
136 | ? $usergroupsDeltaLink->getValue() |
||
137 | : sprintf('$select=%s', implode(',', $groupFields)); |
||
138 | } else { |
||
139 | $query = sprintf( |
||
140 | '$top=%d&$select=%s', |
||
141 | AzureActiveDirectory::API_PAGE_SIZE, |
||
142 | implode(',', $groupFields) |
||
143 | ); |
||
144 | } |
||
145 | |||
146 | $token = null; |
||
147 | |||
148 | do { |
||
149 | $this->generateOrRefreshToken($token); |
||
150 | |||
151 | try { |
||
152 | $azureGroupsRequest = $this->provider->request( |
||
153 | 'get', |
||
154 | $getUsergroupsDelta ? "groups/delta?$query" : "groups?$query", |
||
155 | $token |
||
156 | ); |
||
157 | } catch (Exception $e) { |
||
158 | throw new Exception('Exception when requesting groups from Azure: '.$e->getMessage()); |
||
159 | } |
||
160 | |||
161 | $azureGroupsInfo = $azureGroupsRequest['value'] ?? []; |
||
162 | |||
163 | foreach ($azureGroupsInfo as $azureGroupInfo) { |
||
164 | yield $azureGroupInfo; |
||
165 | } |
||
166 | |||
167 | $hasNextLink = false; |
||
168 | |||
169 | if (!empty($azureGroupsRequest['@odata.nextLink'])) { |
||
170 | $hasNextLink = true; |
||
171 | $query = parse_url($azureGroupsRequest['@odata.nextLink'], PHP_URL_QUERY); |
||
172 | } |
||
173 | |||
174 | if ($getUsergroupsDelta && !empty($azureGroupsRequest['@odata.deltaLink'])) { |
||
175 | $this->plugin->saveSyncState( |
||
176 | AzureSyncState::USERGROUPS_DATALINK, |
||
177 | parse_url($azureGroupsRequest['@odata.deltaLink'], PHP_URL_QUERY), |
||
178 | ); |
||
179 | } |
||
180 | } while ($hasNextLink); |
||
181 | } |
||
232 |