| Conditions | 4 |
| Paths | 3 |
| Total Lines | 65 |
| Code Lines | 51 |
| 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 | $settings = [ |
||
| 22 | [ |
||
| 23 | 'name' => 'allow_global_chat', |
||
| 24 | 'title' => 'Allow global chat', |
||
| 25 | 'comment' => 'Users can chat with each other', |
||
| 26 | 'category' => 'chat', |
||
| 27 | 'default' => 'false', |
||
| 28 | ], |
||
| 29 | [ |
||
| 30 | 'name' => 'hide_chat_video', |
||
| 31 | 'title' => 'Hide videochat option in global chat', |
||
| 32 | 'comment' => '', |
||
| 33 | 'category' => 'chat', |
||
| 34 | 'default' => 'true', |
||
| 35 | ], |
||
| 36 | ]; |
||
| 37 | |||
| 38 | foreach ($settings as $setting) { |
||
| 39 | $variable = addslashes($setting['name']); |
||
| 40 | $title = addslashes($setting['title']); |
||
| 41 | $comment = addslashes($setting['comment']); |
||
| 42 | $category = addslashes($setting['category']); |
||
| 43 | $default = addslashes($setting['default']); |
||
| 44 | |||
| 45 | $sqlCheck = \sprintf( |
||
| 46 | "SELECT COUNT(*) AS count |
||
| 47 | FROM settings |
||
| 48 | WHERE variable = '%s'", |
||
| 49 | $variable |
||
| 50 | ); |
||
| 51 | |||
| 52 | $stmt = $this->connection->executeQuery($sqlCheck); |
||
| 53 | $result = $stmt->fetchAssociative(); |
||
| 54 | |||
| 55 | if ($result && (int) $result['count'] > 0) { |
||
| 56 | $this->addSql(\sprintf( |
||
| 57 | "UPDATE settings |
||
| 58 | SET title = '%s', |
||
| 59 | comment = '%s', |
||
| 60 | category = '%s', |
||
| 61 | type = COALESCE(type, 'radio'), |
||
| 62 | selected_value = '%s' |
||
| 63 | WHERE variable = '%s'", |
||
| 64 | $title, |
||
| 65 | $comment, |
||
| 66 | $category, |
||
| 67 | $default, |
||
| 68 | $variable |
||
| 69 | )); |
||
| 70 | $this->write(\sprintf('Updated setting: %s (selected_value set to %s)', $setting['name'], $setting['default'])); |
||
| 71 | } else { |
||
| 72 | $this->addSql(\sprintf( |
||
| 73 | "INSERT INTO settings |
||
| 74 | (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) |
||
| 75 | VALUES |
||
| 76 | ('%s', NULL, 'radio', '%s', '%s', '%s', '%s', 1, 0, 1)", |
||
| 77 | $variable, |
||
| 78 | $category, |
||
| 79 | $default, |
||
| 80 | $title, |
||
| 81 | $comment |
||
| 82 | )); |
||
| 83 | $this->write(\sprintf('Inserted setting: %s (%s)', $setting['name'], $setting['default'])); |
||
| 84 | } |
||
| 104 |