Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 13 | class Version20150529164400 extends AbstractMigrationChamilo |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @param Schema $schema |
||
| 17 | */ |
||
| 18 | public function up(Schema $schema) |
||
| 19 | { |
||
| 20 | if (!$schema->hasTable('gradebook_score_log')) { |
||
| 21 | $gradebookScoreLog = $schema->createTable('gradebook_score_log'); |
||
| 22 | $gradebookScoreLog->addColumn( |
||
| 23 | 'id', |
||
| 24 | TableColumnType::INTEGER, |
||
| 25 | ['unsigned' => true, 'autoincrement' => true, 'notnull' => true] |
||
| 26 | ); |
||
| 27 | $gradebookScoreLog->addColumn( |
||
| 28 | 'category_id', |
||
| 29 | TableColumnType::INTEGER, |
||
| 30 | ['unsigned' => true, 'notnull' => true] |
||
| 31 | ); |
||
| 32 | $gradebookScoreLog->addColumn( |
||
| 33 | 'user_id', |
||
| 34 | TableColumnType::INTEGER, |
||
| 35 | ['unsigned' => true, 'notnull' => true] |
||
| 36 | ); |
||
| 37 | $gradebookScoreLog->addColumn( |
||
| 38 | 'score', |
||
| 39 | TableColumnType::FLOAT, |
||
| 40 | ['notnull' => true, 'scale' => 0, 'precision' => 10] |
||
| 41 | ); |
||
| 42 | $gradebookScoreLog->addColumn( |
||
| 43 | 'registered_at', |
||
| 44 | TableColumnType::DATETIME, |
||
| 45 | ['notnull' => true] |
||
| 46 | ); |
||
| 47 | $gradebookScoreLog->setPrimaryKey(['id']); |
||
| 48 | $gradebookScoreLog->addIndex( |
||
| 49 | ['user_id'], |
||
| 50 | 'idx_gradebook_score_log_user' |
||
| 51 | ); |
||
| 52 | $gradebookScoreLog->addIndex( |
||
| 53 | ['user_id', 'category_id'], |
||
| 54 | 'idx_gradebook_score_log_user_category' |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param Schema $schema |
||
| 61 | */ |
||
| 62 | public function down(Schema $schema) |
||
| 63 | { |
||
| 64 | $schema->dropTable('gradebook_score_log'); |
||
| 65 | } |
||
| 66 | |||
| 67 | } |
||
| 68 |