| Conditions | 12 |
| Paths | 459 |
| Total Lines | 59 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 | $schemaManager = $this->connection->createSchemaManager(); |
||
| 22 | |||
| 23 | // Add 'new_subscription_session_id' to the 'session_rel_user' table |
||
| 24 | if ($schemaManager->tablesExist('session_rel_user')) { |
||
| 25 | $sessionRelUserTable = $schemaManager->listTableColumns('session_rel_user'); |
||
| 26 | |||
| 27 | if (!isset($sessionRelUserTable['new_subscription_session_id'])) { |
||
| 28 | $this->addSql("ALTER TABLE session_rel_user ADD new_subscription_session_id INT DEFAULT NULL"); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | // Add fields to the 'session' table |
||
| 33 | if ($schemaManager->tablesExist('session')) { |
||
| 34 | $sessionTable = $schemaManager->listTableColumns('session'); |
||
| 35 | |||
| 36 | if (!isset($sessionTable['parent_id'])) { |
||
| 37 | $this->addSql("ALTER TABLE session ADD parent_id INT DEFAULT NULL"); |
||
| 38 | } |
||
| 39 | if (!isset($sessionTable['days_to_reinscription'])) { |
||
| 40 | $this->addSql("ALTER TABLE session ADD days_to_reinscription INT DEFAULT NULL"); |
||
| 41 | } |
||
| 42 | if (!isset($sessionTable['last_repetition'])) { |
||
| 43 | $this->addSql("ALTER TABLE session ADD last_repetition TINYINT(1) DEFAULT 0 NOT NULL"); |
||
| 44 | } |
||
| 45 | if (!isset($sessionTable['days_to_new_repetition'])) { |
||
| 46 | $this->addSql("ALTER TABLE session ADD days_to_new_repetition INT DEFAULT NULL"); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | // Add 'validity_in_days' to the 'session' table |
||
| 51 | if ($schemaManager->tablesExist('session')) { |
||
| 52 | $sessionTable = $schemaManager->listTableColumns('session'); |
||
| 53 | |||
| 54 | if (!isset($sessionTable['validity_in_days'])) { |
||
| 55 | $this->addSql("ALTER TABLE session ADD validity_in_days INT DEFAULT NULL"); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | // Remove 'validity_in_days' from the 'c_lp' table |
||
| 60 | if ($schemaManager->tablesExist('c_lp')) { |
||
| 61 | $clpTable = $schemaManager->listTableColumns('c_lp'); |
||
| 62 | |||
| 63 | if (isset($clpTable['validity_in_days'])) { |
||
| 64 | $this->addSql("ALTER TABLE c_lp DROP COLUMN validity_in_days"); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | // Insert new settings if not exist |
||
| 69 | $this->addSql(" |
||
| 70 | INSERT INTO settings (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) |
||
| 71 | SELECT 'enable_auto_reinscription', NULL, NULL, 'session', '0', 'Enable Auto Reinscription', 'Allow users to be automatically reinscribed in new sessions.', '', NULL, 1, 1, 1 |
||
| 72 | WHERE NOT EXISTS ( |
||
| 73 | SELECT 1 FROM settings WHERE variable = 'enable_auto_reinscription' |
||
| 74 | ) |
||
| 75 | "); |
||
| 76 | |||
| 77 | $this->addSql(" |
||
| 78 | INSERT INTO settings (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) |
||
| 140 |