| Conditions | 9 |
| Paths | 96 |
| Total Lines | 55 |
| Code Lines | 28 |
| 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 |
||
| 19 | public function __construct(array $info, array $config) |
||
| 20 | { |
||
| 21 | /* Transform PasswordVerify (version 1) config to SQL2 config |
||
| 22 | * Version 1 supported only one database, but multiple queries. The first query was defined |
||
| 23 | * to be the "authentication query", all subsequent queries were "attribute queries". |
||
| 24 | */ |
||
| 25 | $v2config = [ |
||
| 26 | 'sqlauth:SQL2', |
||
| 27 | 'databases' => [ |
||
| 28 | 'default' => [ |
||
| 29 | 'dsn' => $config['dsn'], |
||
| 30 | 'username' => $config['username'], |
||
| 31 | 'password' => $config['password'], |
||
| 32 | ], |
||
| 33 | ], |
||
| 34 | |||
| 35 | 'auth_queries' => [ |
||
| 36 | 'default' => [ |
||
| 37 | 'database' => 'default', |
||
| 38 | 'query' => is_array($config['query']) ? $config['query'][0] : $config['query'], |
||
| 39 | 'password_verify_hash_column' => 'passwordhash', |
||
| 40 | ], |
||
| 41 | ], |
||
| 42 | ]; |
||
| 43 | |||
| 44 | if (array_key_exists('username_regex', $config)) { |
||
| 45 | $v2config['auth_queries']['default']['username_regex'] = $config['username_regex']; |
||
| 46 | } |
||
| 47 | |||
| 48 | // Override the default passwordhash column if configured |
||
| 49 | if (array_key_exists('passwordhash_column', $config)) { |
||
| 50 | $v2config['auth_queries']['default']['password_verify_hash_column'] = $config['passwordhash_column']; |
||
| 51 | } |
||
| 52 | |||
| 53 | $numQueries = is_array($config['query']) ? count($config['query']) : 0; |
||
| 54 | if ($numQueries > 1) { |
||
| 55 | $v2config['attr_queries'] = []; |
||
| 56 | for ($i = 1; $i < $numQueries; $i++) { |
||
| 57 | $v2config['attr_queries']['query' . $i] = [ |
||
| 58 | 'database' => 'default', |
||
| 59 | 'query' => $config['query'][$i], |
||
| 60 | ]; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | // Copy other config keys that are not specific to SQL1 (eg. core:login_links) |
||
| 65 | foreach (array_keys($config) as $key) { |
||
| 66 | if (in_array($key, ['dsn', 'username', 'password', 'query', 'username_regex', 'passwordhashcolumn'])) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | |||
| 70 | $v2config[$key] = $config[$key]; |
||
| 71 | } |
||
| 72 | |||
| 73 | parent::__construct($info, $v2config); |
||
| 74 | } |
||
| 76 |