| Conditions | 10 |
| Paths | 512 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 | $table = $schema->getTable('session'); |
||
| 22 | if (false === $table->hasColumn('position')) { |
||
| 23 | $this->addSql('ALTER TABLE session ADD COLUMN position INT DEFAULT 0 NOT NULL'); |
||
| 24 | } else { |
||
| 25 | $this->addSql('ALTER TABLE session CHANGE position position INT DEFAULT 0 NOT NULL'); |
||
| 26 | } |
||
| 27 | |||
| 28 | $this->addSql('UPDATE session SET promotion_id = NULL WHERE promotion_id = 0'); |
||
| 29 | if (false === $table->hasForeignKey('FK_D044D5D4139DF194')) { |
||
| 30 | $this->addSql('ALTER TABLE session ADD CONSTRAINT FK_D044D5D4139DF194 FOREIGN KEY (promotion_id) REFERENCES promotion (id) ON DELETE CASCADE'); |
||
| 31 | $this->addSql('CREATE INDEX IDX_D044D5D4139DF194 ON session (promotion_id);'); |
||
| 32 | } |
||
| 33 | |||
| 34 | if (false === $table->hasColumn('status')) { |
||
| 35 | $this->addSql('ALTER TABLE session ADD COLUMN status INT NOT NULL'); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (false === $table->hasForeignKey('FK_D044D5D4EF87E278')) { |
||
| 39 | $this->addSql('ALTER TABLE session ADD CONSTRAINT FK_D044D5D4EF87E278 FOREIGN KEY(session_admin_id) REFERENCES user(id);'); |
||
| 40 | } |
||
| 41 | |||
| 42 | $this->addSql('UPDATE session_category SET date_start = NULL WHERE date_start = "0000-00-00"'); |
||
| 43 | $this->addSql('UPDATE session_category SET date_end = NULL WHERE date_end = "0000-00-00"'); |
||
| 44 | |||
| 45 | $table = $schema->getTable('session_rel_course_rel_user'); |
||
| 46 | |||
| 47 | if (!$table->hasColumn('progress')) { |
||
| 48 | $this->addSql('ALTER TABLE session_rel_course_rel_user ADD progress INT NOT NULL'); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($table->hasForeignKey('FK_720167E91D79BD3')) { |
||
| 52 | $this->addSql('ALTER TABLE session_rel_course_rel_user DROP FOREIGN KEY FK_720167E91D79BD3'); |
||
| 53 | $this->addSql('ALTER TABLE session_rel_course_rel_user ADD CONSTRAINT FK_720167E91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE'); |
||
| 54 | } else { |
||
| 55 | $this->addSql('ALTER TABLE session_rel_course_rel_user ADD CONSTRAINT FK_720167E91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE'); |
||
| 56 | } |
||
| 57 | |||
| 58 | if (!$table->hasIndex('course_session_unique')) { |
||
| 59 | $this->addSql(' CREATE UNIQUE INDEX course_session_unique ON session_rel_course_rel_user (session_id, c_id, user_id, status);'); |
||
| 60 | } |
||
| 61 | |||
| 62 | $table = $schema->getTable('session_rel_course'); |
||
| 63 | if (!$table->hasIndex('UNIQ_12D110D391D79BD3')) { |
||
| 64 | $this->addSql('CREATE UNIQUE INDEX course_session_unique ON session_rel_course (session_id, c_id)'); |
||
| 65 | } |
||
| 66 | |||
| 67 | $table = $schema->getTable('session_rel_user'); |
||
| 68 | if (!$table->hasIndex('session_user_unique')) { |
||
| 69 | $this->addSql('CREATE UNIQUE INDEX session_user_unique ON session_rel_user (session_id, user_id, relation_type);'); |
||
| 70 | } |
||
| 77 |