Conditions | 14 |
Paths | 290 |
Total Lines | 51 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 210 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
83 | private static function parseDatabaseUrl(array $params) |
||
84 | { |
||
85 | if (!isset($params['url'])) { |
||
86 | return $params; |
||
87 | } |
||
88 | |||
89 | // (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid |
||
1 ignored issue
–
show
|
|||
90 | $url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $params['url']); |
||
91 | |||
92 | $url = parse_url($url); |
||
93 | |||
94 | if ($url === false) { |
||
95 | throw new DBALException('Malformed parameter "url".'); |
||
96 | } |
||
97 | |||
98 | if (isset($url['scheme'])) { |
||
99 | $params['driver'] = str_replace('-', '_', $url['scheme']); // URL schemes must not contain underscores, but dashes are ok |
||
100 | if (isset(self::$driverSchemeAliases[$params['driver']])) { |
||
101 | $params['driver'] = self::$driverSchemeAliases[$params['driver']]; // use alias like "postgres", else we just let checkParams decide later if the driver exists (for literal "pdo-pgsql" etc) |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if (isset($url['host'])) { |
||
106 | $params['host'] = $url['host']; |
||
107 | } |
||
108 | if (isset($url['port'])) { |
||
109 | $params['port'] = $url['port']; |
||
110 | } |
||
111 | if (isset($url['user'])) { |
||
112 | $params['user'] = $url['user']; |
||
113 | } |
||
114 | if (isset($url['pass'])) { |
||
115 | $params['password'] = $url['pass']; |
||
116 | } |
||
117 | |||
118 | if (isset($url['path'])) { |
||
119 | if (!isset($url['scheme']) || (strpos($url['scheme'], 'sqlite') !== false && $url['path'] == ':memory:')) { |
||
120 | $params['dbname'] = $url['path']; // if the URL was just "sqlite::memory:", which parses to scheme and path only |
||
121 | } else { |
||
122 | $params['dbname'] = substr($url['path'], 1); // strip the leading slash from the URL |
||
123 | } |
||
124 | } |
||
125 | |||
126 | if (isset($url['query'])) { |
||
127 | $query = array(); |
||
128 | parse_str($url['query'], $query); // simply ingest query as extra params, e.g. charset or sslmode |
||
129 | $params = array_merge($params, $query); // parse_str wipes existing array elements |
||
130 | } |
||
131 | |||
132 | return $params; |
||
133 | } |
||
134 | |||
136 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.