Conditions | 17 |
Paths | 3456 |
Total Lines | 131 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
219 | public static function checkConfiguration(array $fields) |
||
220 | { |
||
221 | $errors = array(); |
||
222 | |||
223 | // Testing the database connection |
||
224 | try { |
||
225 | Symphony::Database()->connect( |
||
226 | $fields['database']['host'], |
||
227 | $fields['database']['user'], |
||
228 | $fields['database']['password'], |
||
229 | $fields['database']['port'], |
||
230 | $fields['database']['db'] |
||
231 | ); |
||
232 | } catch (DatabaseException $e) { |
||
233 | // Invalid credentials |
||
234 | // @link http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
||
235 | if ($e->getDatabaseErrorCode() === 1044 || $e->getDatabaseErrorCode() === 1045) { |
||
236 | $errors['database-invalid-credentials'] = array( |
||
237 | 'msg' => 'Database credentials were denied', |
||
238 | 'details' => __('Symphony was unable to access the database with these credentials.') |
||
239 | ); |
||
240 | } // Connection related |
||
241 | else { |
||
242 | $errors['no-database-connection'] = array( |
||
243 | 'msg' => 'Could not establish database connection.', |
||
244 | 'details' => __('Symphony was unable to establish a valid database connection. You may need to modify host or port settings.') |
||
245 | ); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | try { |
||
250 | // Check the database table prefix is legal. #1815 |
||
251 | if (!preg_match('/^[0-9a-zA-Z\$_]*$/', $fields['database']['tbl_prefix'])) { |
||
252 | $errors['database-table-prefix'] = array( |
||
253 | 'msg' => 'Invalid database table prefix: ‘' . $fields['database']['tbl_prefix'] . '’', |
||
254 | 'details' => __( |
||
255 | 'The table prefix %s is invalid. The table prefix must only contain numbers, letters or underscore characters.', |
||
256 | array('<code>' . $fields['database']['tbl_prefix'] . '</code>') |
||
257 | ) |
||
258 | ); |
||
259 | } // Check the database credentials |
||
260 | elseif (Symphony::Database()->isConnected()) { |
||
261 | // Incorrect MySQL version |
||
262 | $version = Symphony::Database()->fetchVar('version', 0, "SELECT VERSION() AS `version`;"); |
||
263 | if (version_compare($version, '5.5', '<')) { |
||
264 | $errors['database-incorrect-version'] = array( |
||
265 | 'msg' => 'MySQL Version is not correct. ' . $version . ' detected.', |
||
266 | 'details' => __( |
||
267 | 'Symphony requires %1$s or greater to work, however version %2$s was detected. This requirement must be met before installation can proceed.', |
||
268 | array('<code>MySQL 5.5</code>', '<code>' . $version . '</code>') |
||
269 | ) |
||
270 | ); |
||
271 | } else { |
||
272 | // Existing table prefix |
||
273 | if (Symphony::Database()->tableExists($fields['database']['tbl_prefix'] . '%')) { |
||
274 | $errors['database-table-prefix'] = array( |
||
275 | 'msg' => 'Database table prefix clash with ‘' . $fields['database']['db'] . '’', |
||
276 | 'details' => __( |
||
277 | 'The table prefix %s is already in use. Please choose a different prefix to use with Symphony.', |
||
278 | array( |
||
279 | |||
280 | '<code>' . $fields['database']['tbl_prefix'] . '</code>' |
||
281 | ) |
||
282 | ) |
||
283 | ); |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | } catch (DatabaseException $e) { |
||
288 | $errors['unknown-database'] = array( |
||
289 | 'msg' => 'Database ‘' . $fields['database']['db'] . '’ not found.', |
||
290 | 'details' => __('Symphony was unable to connect to the specified database.') |
||
291 | ); |
||
292 | } |
||
293 | |||
294 | // Website name not entered |
||
295 | if (trim($fields['general']['sitename']) === '') { |
||
296 | $errors['general-no-sitename'] = array( |
||
297 | 'msg' => 'No sitename entered.', |
||
298 | 'details' => __('You must enter a Site name. This will be shown at the top of your backend.') |
||
299 | ); |
||
300 | } |
||
301 | |||
302 | // Username Not Entered |
||
303 | if (trim($fields['user']['username']) === '') { |
||
304 | $errors['user-no-username'] = array( |
||
305 | 'msg' => 'No username entered.', |
||
306 | 'details' => __('You must enter a Username. This will be your Symphony login information.') |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | // Password Not Entered |
||
311 | if (trim($fields['user']['password']) === '') { |
||
312 | $errors['user-no-password'] = array( |
||
313 | 'msg' => 'No password entered.', |
||
314 | 'details' => __('You must enter a Password. This will be your Symphony login information.') |
||
315 | ); |
||
316 | } // Password mismatch |
||
317 | elseif ($fields['user']['password'] !== $fields['user']['confirm-password']) { |
||
318 | $errors['user-password-mismatch'] = array( |
||
319 | 'msg' => 'Passwords did not match.', |
||
320 | 'details' => __('The password and confirmation did not match. Please retype your password.') |
||
321 | ); |
||
322 | } |
||
323 | |||
324 | // No Name entered |
||
325 | if (trim($fields['user']['firstname']) === '' || trim($fields['user']['lastname']) === '') { |
||
326 | $errors['user-no-name'] = array( |
||
327 | 'msg' => 'Did not enter First and Last names.', |
||
328 | 'details' => __('You must enter your name.') |
||
329 | ); |
||
330 | } |
||
331 | |||
332 | // Invalid Email |
||
333 | if (!preg_match('/^\w(?:\.?[\w%+-]+)*@\w(?:[\w-]*\.)+?[a-z]{2,}$/i', $fields['user']['email'])) { |
||
334 | $errors['user-invalid-email'] = array( |
||
335 | 'msg' => 'Invalid email address supplied.', |
||
336 | 'details' => __('This is not a valid email address. You must provide an email address since you will need it if you forget your password.') |
||
337 | ); |
||
338 | } |
||
339 | |||
340 | // Admin path not entered |
||
341 | if (trim($fields['symphony']['admin-path']) === '') { |
||
342 | $errors['no-symphony-path'] = array( |
||
343 | 'msg' => 'No Symphony path entered.', |
||
344 | 'details' => __('You must enter a path for accessing Symphony, or leave the default. This will be used to access Symphony\'s backend.') |
||
345 | ); |
||
346 | } |
||
347 | |||
348 | return $errors; |
||
349 | } |
||
350 | |||
442 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: