| Conditions | 2 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 29 |
| 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 | // Rename specific_field -> search_engine_field |
||
| 22 | // (structure remains the same: id, code, title) |
||
| 23 | $this->write('Renaming table specific_field -> search_engine_field...'); |
||
| 24 | $this->connection->executeStatement( |
||
| 25 | 'RENAME TABLE specific_field TO search_engine_field' |
||
| 26 | ); |
||
| 27 | |||
| 28 | // Rename specific_field_values -> search_engine_field_value |
||
| 29 | // and adapt its columns: |
||
| 30 | // - drop course_code, tool_id |
||
| 31 | // - rename ref_id -> resource_node_id |
||
| 32 | $this->write('Renaming table specific_field_values -> search_engine_field_value...'); |
||
| 33 | $this->connection->executeStatement( |
||
| 34 | 'RENAME TABLE specific_field_values TO search_engine_field_value' |
||
| 35 | ); |
||
| 36 | |||
| 37 | $this->write('Dropping legacy columns course_code, tool_id from search_engine_field_value...'); |
||
| 38 | $this->connection->executeStatement( |
||
| 39 | 'ALTER TABLE search_engine_field_value |
||
| 40 | DROP COLUMN course_code, |
||
| 41 | DROP COLUMN tool_id' |
||
| 42 | ); |
||
| 43 | |||
| 44 | $this->write('Renaming ref_id -> resource_node_id in search_engine_field_value...'); |
||
| 45 | $this->connection->executeStatement( |
||
| 46 | 'ALTER TABLE search_engine_field_value |
||
| 47 | CHANGE ref_id resource_node_id INT NOT NULL' |
||
| 48 | ); |
||
| 49 | |||
| 50 | // Simplify search_engine_ref: |
||
| 51 | // - drop FK to course (c_id) |
||
| 52 | // - drop columns c_id, tool_id, ref_id_high_level |
||
| 53 | // - rename ref_id_second_level -> resource_node_id |
||
| 54 | $this->write('Updating search_engine_ref structure...'); |
||
| 55 | |||
| 56 | try { |
||
| 57 | $this->connection->executeStatement( |
||
| 58 | 'ALTER TABLE search_engine_ref DROP FOREIGN KEY FK_473F037891D79BD3' |
||
| 59 | ); |
||
| 60 | $this->write('Dropped foreign key FK_473F037891D79BD3 from search_engine_ref.'); |
||
| 61 | } catch (\Throwable $e) { |
||
| 62 | $this->write('Foreign key FK_473F037891D79BD3 not found on search_engine_ref, skipping FK drop.'); |
||
| 63 | } |
||
| 64 | |||
| 65 | $this->connection->executeStatement( |
||
| 66 | 'ALTER TABLE search_engine_ref |
||
| 67 | DROP COLUMN c_id, |
||
| 68 | DROP COLUMN tool_id, |
||
| 69 | DROP COLUMN ref_id_high_level, |
||
| 70 | CHANGE ref_id_second_level resource_node_id INT DEFAULT NULL' |
||
| 71 | ); |
||
| 72 | |||
| 73 | $this->write('search_engine_ref updated (c_id/tool_id/ref_id_high_level removed, ref_id_second_level -> resource_node_id).'); |
||
| 74 | } |
||
| 136 |