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