| Conditions | 9 |
| Paths | 192 |
| Total Lines | 57 |
| Code Lines | 30 |
| 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 |
||
| 18 | public function up(Schema $schema): void |
||
| 19 | { |
||
| 20 | $survey = $schema->getTable('c_survey'); |
||
| 21 | if (!$survey->hasColumn('is_mandatory')) { |
||
| 22 | $this->addSql('ALTER TABLE c_survey ADD COLUMN is_mandatory TINYINT(1) DEFAULT "0" NOT NULL'); |
||
| 23 | } |
||
| 24 | /*if (!$survey->hasIndex('idx_survey_code')) { |
||
| 25 | $this->addSql('CREATE INDEX idx_survey_code ON c_survey (code)'); |
||
| 26 | }*/ |
||
| 27 | |||
| 28 | $this->addSql('ALTER TABLE c_survey_invitation CHANGE reminder_date reminder_date DATETIME DEFAULT NULL'); |
||
| 29 | $this->addSql( |
||
| 30 | 'UPDATE c_survey_invitation SET reminder_date = NULL WHERE CAST(reminder_date AS CHAR(20)) = "0000-00-00 00:00:00"' |
||
| 31 | ); |
||
| 32 | |||
| 33 | $table = $schema->getTable('c_survey_invitation'); |
||
| 34 | if (false === $table->hasColumn('answered_at')) { |
||
| 35 | $this->addSql('ALTER TABLE c_survey_invitation ADD answered_at DATETIME DEFAULT NULL;'); |
||
| 36 | } |
||
| 37 | if (false === $table->hasIndex('idx_survey_inv_code')) { |
||
| 38 | $this->addSql('CREATE INDEX idx_survey_inv_code ON c_survey_invitation (survey_code)'); |
||
| 39 | } |
||
| 40 | |||
| 41 | $table = $schema->getTable('c_survey_question'); |
||
| 42 | if (!$table->hasColumn('is_required')) { |
||
| 43 | $table |
||
| 44 | ->addColumn('is_required', Types::BOOLEAN) |
||
| 45 | ->setDefault(false); |
||
| 46 | } |
||
| 47 | if (false === $table->hasIndex('idx_survey_q_qid')) { |
||
| 48 | $this->addSql('CREATE INDEX idx_survey_q_qid ON c_survey_question (question_id)'); |
||
| 49 | } |
||
| 50 | |||
| 51 | $table = $schema->getTable('c_survey_question_option'); |
||
| 52 | if (false === $table->hasIndex('idx_survey_qo_qid')) { |
||
| 53 | $this->addSql('CREATE INDEX idx_survey_qo_qid ON c_survey_question_option (question_id)'); |
||
| 54 | } |
||
| 55 | |||
| 56 | $em = $this->getEntityManager(); |
||
| 57 | |||
| 58 | $sql = 'SELECT s.* FROM c_survey s |
||
| 59 | INNER JOIN extra_field_values efv |
||
| 60 | ON s.iid = efv.item_id |
||
| 61 | INNER JOIN extra_field ef |
||
| 62 | ON efv.field_id = ef.id |
||
| 63 | WHERE |
||
| 64 | ef.variable = "is_mandatory" AND |
||
| 65 | ef.extra_field_type = '.ExtraField::SURVEY_FIELD_TYPE.' AND |
||
| 66 | efv.value = 1 |
||
| 67 | '; |
||
| 68 | |||
| 69 | $result = $em->getConnection()->executeQuery($sql); |
||
| 70 | $data = $result->fetchAllAssociative(); |
||
| 71 | if ($data) { |
||
| 72 | foreach ($data as $item) { |
||
| 73 | $id = $item['iid']; |
||
| 74 | $this->addSql("UPDATE c_survey SET is_mandatory = 1 WHERE iid = $id"); |
||
| 75 | } |
||
| 83 |