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