| Conditions | 12 |
| Paths | 2048 |
| Total Lines | 68 |
| Code Lines | 37 |
| 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 |
||
| 17 | public function up(Schema $schema): void |
||
| 18 | { |
||
| 19 | // Assigned users |
||
| 20 | $table = $schema->getTable('ticket_ticket'); |
||
| 21 | $this->addSql( |
||
| 22 | 'UPDATE ticket_ticket SET assigned_last_user = NULL WHERE assigned_last_user NOT IN (SELECT id FROM user)' |
||
| 23 | ); |
||
| 24 | |||
| 25 | $this->addSql('UPDATE ticket_ticket SET session_id = NULL WHERE session_id = 0'); |
||
| 26 | $this->addSql('UPDATE ticket_ticket SET course_id = NULL WHERE course_id = 0'); |
||
| 27 | |||
| 28 | $this->addSql('DELETE FROM ticket_ticket WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)'); |
||
| 29 | $this->addSql('DELETE FROM ticket_ticket WHERE course_id IS NOT NULL AND course_id NOT IN (SELECT id FROM course)'); |
||
| 30 | |||
| 31 | if (!$table->hasForeignKey('FK_EDE2C7686219A7B7')) { |
||
| 32 | $this->addSql( |
||
| 33 | 'ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EDE2C7686219A7B7 FOREIGN KEY (assigned_last_user) REFERENCES user (id) ON DELETE CASCADE' |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | if (!$table->hasForeignKey('FK_EDE2C768591CC992')) { |
||
| 38 | $this->addSql('ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EDE2C768591CC992 FOREIGN KEY (course_id) REFERENCES course (id) ON DELETE CASCADE;'); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (!$table->hasForeignKey('FK_EDE2C768613FECDF')) { |
||
| 42 | $this->addSql('ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EDE2C768613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE;'); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (false === $table->hasIndex('IDX_EDE2C7686219A7B7')) { |
||
| 46 | $this->addSql('CREATE INDEX IDX_EDE2C7686219A7B7 ON ticket_ticket (assigned_last_user)'); |
||
| 47 | } |
||
| 48 | |||
| 49 | if (!$table->hasColumn('exercise_id')) { |
||
| 50 | $this->addSql("ALTER TABLE ticket_ticket ADD exercise_id INT DEFAULT NULL"); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (!$table->hasColumn('lp_id')) { |
||
| 54 | $this->addSql("ALTER TABLE ticket_ticket ADD lp_id INT DEFAULT NULL"); |
||
| 55 | } |
||
| 56 | |||
| 57 | $table = $schema->getTable('ticket_assigned_log'); |
||
| 58 | if (!$table->hasForeignKey('FK_54B65868700047D2')) { |
||
| 59 | $this->addSql('ALTER TABLE ticket_assigned_log ADD CONSTRAINT FK_54B65868700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id) ON DELETE CASCADE;'); |
||
| 60 | } |
||
| 61 | |||
| 62 | $table = $schema->getTable('ticket_message'); |
||
| 63 | if (!$table->hasForeignKey('FK_BA71692D700047D2')) { |
||
| 64 | $this->addSql('ALTER TABLE ticket_message ADD CONSTRAINT FK_BA71692D700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id) ON DELETE CASCADE;'); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Attachments |
||
| 68 | $table = $schema->getTable('ticket_message_attachments'); |
||
| 69 | |||
| 70 | if (!$table->hasForeignKey('FK_70BF9E26537A1329')) { |
||
| 71 | $this->addSql('ALTER TABLE ticket_message_attachments ADD CONSTRAINT FK_70BF9E26537A1329 FOREIGN KEY (message_id) REFERENCES ticket_message (id) ON DELETE CASCADE;'); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!$table->hasForeignKey('FK_70BF9E26700047D2')) { |
||
| 75 | $this->addSql('ALTER TABLE ticket_message_attachments ADD CONSTRAINT FK_70BF9E26700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id) ON DELETE CASCADE;'); |
||
| 76 | } |
||
| 77 | |||
| 78 | if (!$table->hasColumn('resource_node_id')) { |
||
| 79 | $this->addSql('ALTER TABLE ticket_message_attachments ADD resource_node_id INT DEFAULT NULL;'); |
||
| 80 | $this->addSql( |
||
| 81 | 'ALTER TABLE ticket_message_attachments ADD CONSTRAINT FK_70BF9E261BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;' |
||
| 82 | ); |
||
| 83 | $this->addSql( |
||
| 84 | 'CREATE UNIQUE INDEX UNIQ_70BF9E261BAD783F ON ticket_message_attachments (resource_node_id);' |
||
| 85 | ); |
||
| 89 |