| Conditions | 3 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 32 |
| 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 |
||
| 76 | public function down(Schema $schema): void |
||
| 77 | { |
||
| 78 | $this->write('Reverting search_engine_ref structure...'); |
||
| 79 | |||
| 80 | // Revert search_engine_ref |
||
| 81 | // - rename resource_node_id -> ref_id_second_level |
||
| 82 | // - re-add c_id, tool_id, ref_id_high_level (as nullable/default values) |
||
| 83 | $this->connection->executeStatement( |
||
| 84 | 'ALTER TABLE search_engine_ref |
||
| 85 | CHANGE resource_node_id ref_id_second_level INT DEFAULT NULL, |
||
| 86 | ADD c_id INT DEFAULT NULL AFTER id, |
||
| 87 | ADD tool_id VARCHAR(100) NOT NULL DEFAULT \'\' AFTER c_id, |
||
| 88 | ADD ref_id_high_level INT NOT NULL DEFAULT 0 AFTER tool_id' |
||
| 89 | ); |
||
| 90 | |||
| 91 | try { |
||
| 92 | $this->connection->executeStatement( |
||
| 93 | 'CREATE INDEX IDX_473F037891D79BD3 ON search_engine_ref (c_id)' |
||
| 94 | ); |
||
| 95 | } catch (\Throwable $e) { |
||
| 96 | $this->write('Could not recreate index IDX_473F037891D79BD3 on search_engine_ref: '.$e->getMessage()); |
||
| 97 | } |
||
| 98 | |||
| 99 | try { |
||
| 100 | $this->connection->executeStatement( |
||
| 101 | 'ALTER TABLE search_engine_ref |
||
| 102 | ADD CONSTRAINT FK_473F037891D79BD3 |
||
| 103 | FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE SET NULL' |
||
| 104 | ); |
||
| 105 | } catch (\Throwable $e) { |
||
| 106 | $this->write('Could not recreate foreign key FK_473F037891D79BD3 on search_engine_ref: '.$e->getMessage()); |
||
| 107 | } |
||
| 108 | |||
| 109 | // Revert search_engine_field_value |
||
| 110 | $this->write('Reverting search_engine_field_value -> specific_field_values...'); |
||
| 111 | |||
| 112 | // resource_node_id -> ref_id |
||
| 113 | $this->connection->executeStatement( |
||
| 114 | 'ALTER TABLE search_engine_field_value |
||
| 115 | CHANGE resource_node_id ref_id INT NOT NULL' |
||
| 116 | ); |
||
| 117 | |||
| 118 | $this->connection->executeStatement( |
||
| 119 | "ALTER TABLE search_engine_field_value |
||
| 120 | ADD course_code VARCHAR(40) NOT NULL DEFAULT '', |
||
| 121 | ADD tool_id VARCHAR(100) NOT NULL DEFAULT ''" |
||
| 122 | ); |
||
| 123 | |||
| 124 | $this->connection->executeStatement( |
||
| 125 | 'RENAME TABLE search_engine_field_value TO specific_field_values' |
||
| 126 | ); |
||
| 127 | |||
| 128 | // Revert search_engine_field -> specific_field |
||
| 129 | $this->write('Reverting search_engine_field -> specific_field...'); |
||
| 130 | |||
| 131 | $this->connection->executeStatement( |
||
| 132 | 'RENAME TABLE search_engine_field TO specific_field' |
||
| 133 | ); |
||
| 136 |