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