Conditions | 6 |
Paths | 24 |
Total Lines | 53 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | // Create table settings_value_template |
||
24 | if (!$schemaManager->tablesExist(['settings_value_template'])) { |
||
25 | $this->addSql(" |
||
26 | CREATE TABLE settings_value_template ( |
||
27 | id INT UNSIGNED AUTO_INCREMENT NOT NULL, |
||
28 | variable VARCHAR(190) NOT NULL, |
||
29 | description LONGTEXT DEFAULT NULL, |
||
30 | json_example LONGTEXT DEFAULT NULL, |
||
31 | created_at DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)', |
||
32 | updated_at DATETIME DEFAULT NULL COMMENT '(DC2Type:datetime)', |
||
33 | UNIQUE INDEX UNIQ_settings_value_template_variable (variable), |
||
34 | PRIMARY KEY(id) |
||
35 | ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC; |
||
36 | "); |
||
37 | $this->write('Created table settings_value_template.'); |
||
38 | } |
||
39 | |||
40 | // Add column value_template_id to settings |
||
41 | $columns = $schemaManager->listTableColumns('settings'); |
||
42 | if (!isset($columns['value_template_id'])) { |
||
43 | $this->addSql(' |
||
44 | ALTER TABLE settings ADD value_template_id INT UNSIGNED DEFAULT NULL; |
||
45 | '); |
||
46 | $this->write('Added value_template_id column to settings table.'); |
||
47 | } |
||
48 | |||
49 | // Add FK constraint |
||
50 | $foreignKeys = $schemaManager->listTableForeignKeys('settings'); |
||
51 | $fkExists = false; |
||
52 | foreach ($foreignKeys as $fk) { |
||
53 | if (\in_array('value_template_id', $fk->getLocalColumns(), true)) { |
||
54 | $fkExists = true; |
||
55 | |||
56 | break; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | if (!$fkExists) { |
||
61 | $this->addSql(' |
||
62 | ALTER TABLE settings |
||
63 | ADD CONSTRAINT FK_E545A0C5C72FB79B |
||
64 | FOREIGN KEY (value_template_id) REFERENCES settings_value_template (id) ON DELETE SET NULL; |
||
65 | '); |
||
66 | $this->write('Added foreign key constraint from settings to settings_value_template.'); |
||
67 | |||
68 | $this->addSql(' |
||
69 | CREATE INDEX IDX_E545A0C5C72FB79B ON settings (value_template_id); |
||
70 | '); |
||
71 | $this->write('Created index IDX_E545A0C5C72FB79B on settings.value_template_id.'); |
||
72 | } |
||
111 |