| Conditions | 14 |
| Paths | 5120 |
| Total Lines | 76 |
| Code Lines | 43 |
| 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 |
||
| 15 | public function up(Schema $schema): void |
||
| 16 | { |
||
| 17 | $this->addSql('CREATE TABLE IF NOT EXISTS c_exercise_category (id BIGINT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, position INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'); |
||
| 18 | |||
| 19 | // c_quiz. |
||
| 20 | $table = $schema->getTable('c_quiz'); |
||
| 21 | if ($table->hasColumn('exercise_category_id')) { |
||
| 22 | $this->addSql('ALTER TABLE c_quiz CHANGE exercise_category_id exercise_category_id BIGINT DEFAULT NULL;'); |
||
| 23 | } else { |
||
| 24 | $this->addSql('ALTER TABLE c_quiz ADD COLUMN exercise_category_id BIGINT DEFAULT NULL;'); |
||
| 25 | } |
||
| 26 | if (!$table->hasColumn('autolaunch')) { |
||
| 27 | $this->addSql('ALTER TABLE c_quiz ADD autolaunch TINYINT(1) DEFAULT 0'); |
||
| 28 | } |
||
| 29 | |||
| 30 | if (false === $table->hasForeignKey('FK_B7A1C35FB48D66')) { |
||
| 31 | $this->addSql( |
||
| 32 | 'ALTER TABLE c_quiz ADD CONSTRAINT FK_B7A1C35FB48D66 FOREIGN KEY (exercise_category_id) REFERENCES c_exercise_category (id);' |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | if (false === $table->hasIndex('IDX_B7A1C35FB48D66')) { |
||
| 36 | $this->addSql('CREATE INDEX IDX_B7A1C35FB48D66 ON c_quiz (exercise_category_id);'); |
||
| 37 | } |
||
| 38 | |||
| 39 | if (false === $table->hasColumn('show_previous_button')) { |
||
| 40 | $this->addSql( |
||
| 41 | 'ALTER TABLE c_quiz ADD COLUMN show_previous_button TINYINT(1) DEFAULT 1;' |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (false === $table->hasColumn('notifications')) { |
||
| 46 | $this->addSql( |
||
| 47 | 'ALTER TABLE c_quiz ADD COLUMN notifications VARCHAR(255) NULL DEFAULT NULL;' |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (false === $table->hasColumn('page_result_configuration')) { |
||
| 52 | $this->addSql( |
||
| 53 | "ALTER TABLE c_quiz ADD page_result_configuration LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)'" |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->addSql('ALTER TABLE c_quiz MODIFY COLUMN save_correct_answers INT NULL DEFAULT NULL'); |
||
| 58 | |||
| 59 | // c_quiz_question. |
||
| 60 | $table = $schema->getTable('c_quiz_question'); |
||
| 61 | if (false === $table->hasColumn('resource_node_id')) { |
||
| 62 | $this->addSql('ALTER TABLE c_quiz_question ADD resource_node_id INT DEFAULT NULL;'); |
||
| 63 | $this->addSql( |
||
| 64 | 'ALTER TABLE c_quiz_question ADD CONSTRAINT FK_9A48A59F1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;' |
||
| 65 | ); |
||
| 66 | $this->addSql('CREATE UNIQUE INDEX UNIQ_9A48A59F1BAD783F ON c_quiz_question (resource_node_id);'); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (false === $table->hasColumn('feedback')) { |
||
| 70 | $this->addSql('ALTER TABLE c_quiz_question ADD feedback LONGTEXT DEFAULT NULL;'); |
||
| 71 | } |
||
| 72 | |||
| 73 | // c_quiz_question_category. |
||
| 74 | $table = $schema->getTable('c_quiz_question_category'); |
||
| 75 | if (false === $table->hasColumn('session_id')) { |
||
| 76 | $this->addSql('ALTER TABLE c_quiz_question_category ADD session_id INT DEFAULT NULL'); |
||
| 77 | if (false === $table->hasIndex('IDX_1414369D613FECDF')) { |
||
| 78 | $this->addSql('CREATE INDEX IDX_1414369D613FECDF ON c_quiz_question_category (session_id)'); |
||
| 79 | } |
||
| 80 | if (false === $table->hasForeignKey('FK_1414369D613FECDF')) { |
||
| 81 | $this->addSql( |
||
| 82 | 'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D613FECDF FOREIGN KEY (session_id) REFERENCES session (id)' |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | $this->addSql('ALTER TABLE c_quiz_question_category CHANGE description description LONGTEXT DEFAULT NULL;'); |
||
| 87 | |||
| 88 | if (false === $table->hasForeignKey('FK_1414369D91D79BD3')) { |
||
| 89 | $this->addSql( |
||
| 90 | 'ALTER TABLE c_quiz_question_category ADD CONSTRAINT FK_1414369D91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);' |
||
| 91 | ); |
||
| 99 |