| Conditions | 5 |
| Paths | 9 |
| Total Lines | 56 |
| Code Lines | 31 |
| 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 | // --- attempt_file --- |
||
| 22 | if ($schema->hasTable('attempt_file')) { |
||
| 23 | $table = $schema->getTable('attempt_file'); |
||
| 24 | |||
| 25 | if (!$table->hasColumn('resource_node_id')) { |
||
| 26 | // Add nullable FK column. We place it after asset_id to keep legacy column nearby. |
||
| 27 | $this->addSql( |
||
| 28 | 'ALTER TABLE attempt_file |
||
| 29 | ADD resource_node_id INT DEFAULT NULL AFTER asset_id' |
||
| 30 | ); |
||
| 31 | |||
| 32 | // Index for FK performance. |
||
| 33 | $this->addSql( |
||
| 34 | 'CREATE INDEX IDX_ATTEMPT_FILE_RESOURCE_NODE |
||
| 35 | ON attempt_file (resource_node_id)' |
||
| 36 | ); |
||
| 37 | |||
| 38 | // FK to resource_node.id. |
||
| 39 | $this->addSql( |
||
| 40 | 'ALTER TABLE attempt_file |
||
| 41 | ADD CONSTRAINT FK_ATTEMPT_FILE_RESOURCE_NODE |
||
| 42 | FOREIGN KEY (resource_node_id) |
||
| 43 | REFERENCES resource_node (id) |
||
| 44 | ON DELETE CASCADE' |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | // --- attempt_feedback --- |
||
| 50 | if ($schema->hasTable('attempt_feedback')) { |
||
| 51 | $table = $schema->getTable('attempt_feedback'); |
||
| 52 | |||
| 53 | if (!$table->hasColumn('resource_node_id')) { |
||
| 54 | $this->addSql( |
||
| 55 | 'ALTER TABLE attempt_feedback |
||
| 56 | ADD resource_node_id INT DEFAULT NULL AFTER asset_id' |
||
| 57 | ); |
||
| 58 | |||
| 59 | $this->addSql( |
||
| 60 | 'CREATE INDEX IDX_ATTEMPT_FEEDBACK_RESOURCE_NODE |
||
| 61 | ON attempt_feedback (resource_node_id)' |
||
| 62 | ); |
||
| 63 | |||
| 64 | $this->addSql( |
||
| 65 | 'ALTER TABLE attempt_feedback |
||
| 66 | ADD CONSTRAINT FK_ATTEMPT_FEEDBACK_RESOURCE_NODE |
||
| 67 | FOREIGN KEY (resource_node_id) |
||
| 68 | REFERENCES resource_node (id) |
||
| 69 | ON DELETE CASCADE' |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $this->declareNewResourceTypes(); |
||
| 75 | } |
||
| 188 |