| Conditions | 3 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 43 |
| 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 up(Schema $schema): void |
||
| 20 | { |
||
| 21 | $setting = [ |
||
| 22 | 'variable' => 'hosting_limit_identical_email', |
||
| 23 | 'selected_value' => '0', |
||
| 24 | 'title' => 'Limit identical email usage', |
||
| 25 | 'comment' => 'Maximum number of accounts allowed to share the same e-mail address. Set to 0 to disable this limit.', |
||
| 26 | 'category' => 'platform', |
||
| 27 | ]; |
||
| 28 | |||
| 29 | $sqlCheck = sprintf( |
||
| 30 | "SELECT COUNT(*) as count |
||
| 31 | FROM settings |
||
| 32 | WHERE variable = '%s' |
||
| 33 | AND subkey IS NULL |
||
| 34 | AND access_url = 1", |
||
| 35 | addslashes($setting['variable']) |
||
| 36 | ); |
||
| 37 | |||
| 38 | $stmt = $this->connection->executeQuery($sqlCheck); |
||
| 39 | $result = $stmt->fetchAssociative(); |
||
| 40 | |||
| 41 | if ($result && (int)$result['count'] > 0) { |
||
| 42 | // UPDATE existing setting |
||
| 43 | $this->addSql(sprintf( |
||
| 44 | "UPDATE settings |
||
| 45 | SET selected_value = '%s', |
||
| 46 | title = '%s', |
||
| 47 | comment = '%s', |
||
| 48 | category = '%s' |
||
| 49 | WHERE variable = '%s' |
||
| 50 | AND subkey IS NULL |
||
| 51 | AND access_url = 1", |
||
| 52 | addslashes($setting['selected_value']), |
||
| 53 | addslashes($setting['title']), |
||
| 54 | addslashes($setting['comment']), |
||
| 55 | addslashes($setting['category']), |
||
| 56 | addslashes($setting['variable']) |
||
| 57 | )); |
||
| 58 | $this->write(sprintf("Updated setting: %s", $setting['variable'])); |
||
| 59 | } else { |
||
| 60 | // INSERT new setting |
||
| 61 | $this->addSql(sprintf( |
||
| 62 | "INSERT INTO settings |
||
| 63 | (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) |
||
| 64 | VALUES |
||
| 65 | ('%s', NULL, NULL, '%s', '%s', '%s', '%s', 1, 0, 1)", |
||
| 66 | addslashes($setting['variable']), |
||
| 67 | addslashes($setting['category']), |
||
| 68 | addslashes($setting['selected_value']), |
||
| 69 | addslashes($setting['title']), |
||
| 70 | addslashes($setting['comment']) |
||
| 71 | )); |
||
| 72 | $this->write(sprintf("Inserted setting: %s", $setting['variable'])); |
||
| 73 | } |
||
| 88 |