| Conditions | 4 |
| Paths | 3 |
| Total Lines | 62 |
| Code Lines | 49 |
| 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 | 'variable' => 'user_session_display_mode', |
||
| 24 | 'selected_value' => 'card', |
||
| 25 | 'title' => 'Default display mode for My Sessions page', |
||
| 26 | 'comment' => 'Defines the default visual style for showing sessions on the My Sessions page. Options: card (visual blocks), list (classic view).', |
||
| 27 | 'category' => 'session', |
||
| 28 | ], |
||
| 29 | [ |
||
| 30 | 'variable' => 'course_sequence_valid_only_in_same_session', |
||
| 31 | 'selected_value' => 'false', |
||
| 32 | 'title' => 'Course sequence validation only in the same session', |
||
| 33 | 'comment' => 'If enabled, course dependencies are enforced only within the same session and do not block other sessions or standalone courses.', |
||
| 34 | 'category' => 'course', |
||
| 35 | ], |
||
| 36 | ]; |
||
| 37 | |||
| 38 | foreach ($settings as $setting) { |
||
| 39 | $sqlCheck = \sprintf( |
||
| 40 | "SELECT COUNT(*) as count |
||
| 41 | FROM settings |
||
| 42 | WHERE variable = '%s' |
||
| 43 | AND subkey IS NULL |
||
| 44 | AND access_url = 1", |
||
| 45 | addslashes($setting['variable']) |
||
| 46 | ); |
||
| 47 | |||
| 48 | $stmt = $this->connection->executeQuery($sqlCheck); |
||
| 49 | $result = $stmt->fetchAssociative(); |
||
| 50 | |||
| 51 | if ($result && (int) $result['count'] > 0) { |
||
| 52 | $this->addSql(\sprintf( |
||
| 53 | "UPDATE settings |
||
| 54 | SET selected_value = '%s', |
||
| 55 | title = '%s', |
||
| 56 | comment = '%s', |
||
| 57 | category = '%s' |
||
| 58 | WHERE variable = '%s' |
||
| 59 | AND subkey IS NULL |
||
| 60 | AND access_url = 1", |
||
| 61 | addslashes($setting['selected_value']), |
||
| 62 | addslashes($setting['title']), |
||
| 63 | addslashes($setting['comment']), |
||
| 64 | addslashes($setting['category']), |
||
| 65 | addslashes($setting['variable']) |
||
| 66 | )); |
||
| 67 | $this->write(\sprintf('Updated setting: %s', $setting['variable'])); |
||
| 68 | } else { |
||
| 69 | $this->addSql(\sprintf( |
||
| 70 | "INSERT INTO settings |
||
| 71 | (variable, subkey, type, category, selected_value, title, comment, access_url_changeable, access_url_locked, access_url) |
||
| 72 | VALUES |
||
| 73 | ('%s', NULL, NULL, '%s', '%s', '%s', '%s', 1, 0, 1)", |
||
| 74 | addslashes($setting['variable']), |
||
| 75 | addslashes($setting['category']), |
||
| 76 | addslashes($setting['selected_value']), |
||
| 77 | addslashes($setting['title']), |
||
| 78 | addslashes($setting['comment']) |
||
| 79 | )); |
||
| 80 | $this->write(\sprintf('Inserted setting: %s', $setting['variable'])); |
||
| 81 | } |
||
| 104 |