Conditions | 23 |
Paths | 10562 |
Total Lines | 91 |
Code Lines | 49 |
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 |
||
173 | private function parseAuthSourceConfig(string $as): array |
||
174 | { |
||
175 | // Log the authsource request |
||
176 | Logger::debug(sprintf( |
||
177 | '%s : Attempting to get configuration values from authsource [%s]', |
||
178 | $this->title, |
||
179 | $as, |
||
180 | )); |
||
181 | |||
182 | // Get the authsources file, which should contain the config |
||
183 | $authsources = Configuration::getConfig('authsources.php'); |
||
184 | |||
185 | // Verify that the authsource config exists |
||
186 | if (!$authsources->hasValue($as)) { |
||
187 | throw new Error\Exception(sprintf( |
||
188 | '%s : Authsource [%s] defined in filter parameters not found in authsources.php', |
||
189 | $this->title, |
||
190 | $as, |
||
191 | )); |
||
192 | } |
||
193 | |||
194 | // Get just the specified authsource config values |
||
195 | $authsource = $authsources->getArray($as); |
||
196 | |||
197 | // Make sure it is an ldap source |
||
198 | if (isset($authsource[0]) && !in_array($authsource[0], self::$ldapsources)) { |
||
199 | throw new Error\Exception(sprintf( |
||
200 | '%s : Authsource [%s] specified in filter parameters is not an ldap:LDAP type', |
||
201 | $this->title, |
||
202 | $as, |
||
203 | )); |
||
204 | } |
||
205 | |||
206 | // Build the authsource config |
||
207 | $authconfig = []; |
||
208 | if (isset($authsource['connection_string'])) { |
||
209 | $authconfig['connection_string'] = $authsource['connection_string']; |
||
210 | } |
||
211 | if (isset($authsource['encryption'])) { |
||
212 | $authconfig['encryption'] = $authsource['encryption']; |
||
213 | } |
||
214 | if (isset($authsource['version'])) { |
||
215 | $authconfig['version'] = $authsource['version']; |
||
216 | } |
||
217 | if (isset($authsource['timeout'])) { |
||
218 | $authconfig['timeout'] = $authsource['timeout']; |
||
219 | } |
||
220 | if (isset($authsource['debug'])) { |
||
221 | $authconfig['debug'] = $authsource['debug']; |
||
222 | } |
||
223 | if (isset($authsource['referrals'])) { |
||
224 | $authconfig['referrals'] = $authsource['referrals']; |
||
225 | } |
||
226 | |||
227 | // only set when search.enabled = true |
||
228 | if (isset($authsource['search.enable']) && ($authsource['search.enable'] === true)) { |
||
229 | if (isset($authsource['search.base'])) { |
||
230 | $authconfig['search.base'] = $authsource['search.base']; |
||
231 | } |
||
232 | if (isset($authsource['search.scope'])) { |
||
233 | $authconfig['search.scope'] = $authsource['search.scope']; |
||
234 | } |
||
235 | |||
236 | if (isset($authsource['search.username'])) { |
||
237 | $authconfig['search.username'] = $authsource['search.username']; |
||
238 | } |
||
239 | if (isset($authsource['search.password'])) { |
||
240 | $authconfig['search.password'] = $authsource['search.password']; |
||
241 | } |
||
242 | |||
243 | // Only set the username attribute if the authsource specifies one attribute |
||
244 | if ( |
||
245 | isset($authsource['search.attributes']) |
||
246 | && is_array($authsource['search.attributes']) |
||
247 | && count($authsource['search.attributes']) == 1 |
||
248 | ) { |
||
249 | $authconfig['attribute.username'] = reset($authsource['search.attributes']); |
||
250 | } |
||
251 | } |
||
252 | |||
253 | // only set when priv.read = true |
||
254 | if (isset($authsource['priv.read']) && $authsource['priv.read']) { |
||
255 | if (isset($authsource['priv.username'])) { |
||
256 | $authconfig['priv.username'] = $authsource['priv.username']; |
||
257 | } |
||
258 | if (isset($authsource['priv.password'])) { |
||
259 | $authconfig['priv.password'] = $authsource['priv.password']; |
||
260 | } |
||
261 | } |
||
262 | |||
263 | return $authconfig; |
||
264 | } |
||
296 |