| Conditions | 7 |
| Paths | 36 |
| Total Lines | 71 |
| Code Lines | 54 |
| 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 |
||
| 22 | public function up(Schema $schema): void |
||
| 23 | { |
||
| 24 | $skipAttendances = (bool) getenv(DoctrineMigrationsMigrateCommandDecorator::SKIP_ATTENDANCES_FLAG); |
||
| 25 | $platform = $this->connection->getDatabasePlatform(); |
||
| 26 | |||
| 27 | // MySQL-only FK checks toggle |
||
| 28 | if ($platform instanceof MySQLPlatform) { |
||
| 29 | $this->addSql('SET FOREIGN_KEY_CHECKS = 0;'); |
||
| 30 | } |
||
| 31 | |||
| 32 | $tablesToDrop = [ |
||
| 33 | 'page__snapshot', |
||
| 34 | 'class_item', |
||
| 35 | 'classification__collection', |
||
| 36 | 'c_userinfo_def', |
||
| 37 | 'class_user', |
||
| 38 | 'faq_question', |
||
| 39 | 'timeline__component', |
||
| 40 | 'page__page', |
||
| 41 | 'c_online_connected', |
||
| 42 | 'c_permission_task', |
||
| 43 | 'page__bloc', |
||
| 44 | 'c_online_link', |
||
| 45 | 'c_permission_user', |
||
| 46 | 'c_role_user', |
||
| 47 | 'c_role', |
||
| 48 | 'page__site', |
||
| 49 | 'shared_survey', |
||
| 50 | 'media__gallery', |
||
| 51 | 'faq_category', |
||
| 52 | 'classification__context', |
||
| 53 | 'timeline__timeline', |
||
| 54 | 'classification__category', |
||
| 55 | 'faq_question_translation', |
||
| 56 | 'c_userinfo_content', |
||
| 57 | 'contact_category', |
||
| 58 | 'classification__tag', |
||
| 59 | 'faq_category_translation', |
||
| 60 | 'timeline__action_component', |
||
| 61 | 'media__media', |
||
| 62 | 'c_role_permissions', |
||
| 63 | 'shared_survey_question_option', |
||
| 64 | 'shared_survey_question', |
||
| 65 | 'timeline__action', |
||
| 66 | 'contact_category_translation', |
||
| 67 | 'media__gallery_media', |
||
| 68 | // 'c_item_property' handled separately below |
||
| 69 | 'c_survey_group', |
||
| 70 | 'c_permission_group', |
||
| 71 | 'c_role_group', |
||
| 72 | 'track_e_open', |
||
| 73 | ]; |
||
| 74 | |||
| 75 | foreach ($tablesToDrop as $table) { |
||
| 76 | if ($schema->hasTable($table)) { |
||
| 77 | $this->addSql('DROP TABLE '.$this->quoteIdentifier($platform, $table).';'); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | // If skip-attendances is enabled, we keep c_item_property because the post-migration command |
||
| 82 | // "chamilo:migration:migrate-attendances-fast" needs it to map attendances to courses and metadata. |
||
| 83 | if ($schema->hasTable('c_item_property')) { |
||
| 84 | if ($skipAttendances) { |
||
| 85 | $this->write('skip-attendances enabled: keeping c_item_property for post-migration attendance fast migration.'); |
||
| 86 | } else { |
||
| 87 | $this->addSql('DROP TABLE '.$this->quoteIdentifier($platform, 'c_item_property').';'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($platform instanceof MySQLPlatform) { |
||
| 92 | $this->addSql('SET FOREIGN_KEY_CHECKS = 1;'); |
||
| 93 | } |
||
| 105 |