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 Version20150608104600 extends AbstractMigrationChamilo |
||
14 | { |
||
15 | /** |
||
16 | * @param Schema $schema |
||
17 | */ |
||
18 | public function up(Schema $schema) |
||
19 | { |
||
20 | if (!$schema->hasTable('extra_field_rel_tag')) { |
||
21 | $extraFieldRelTag = $schema->createTable('extra_field_rel_tag'); |
||
22 | $extraFieldRelTag->addColumn( |
||
23 | 'id', |
||
24 | TableColumnType::INTEGER, |
||
25 | ['unsigned' => true, 'autoincrement' => true, 'notnull' => true] |
||
26 | ); |
||
27 | $extraFieldRelTag->addColumn( |
||
28 | 'field_id', |
||
29 | TableColumnType::INTEGER, |
||
30 | ['unsigned' => true, 'notnull' => true] |
||
31 | ); |
||
32 | $extraFieldRelTag->addColumn( |
||
33 | 'item_id', |
||
34 | TableColumnType::INTEGER, |
||
35 | ['unsigned' => true, 'notnull' => true] |
||
36 | ); |
||
37 | $extraFieldRelTag->addColumn( |
||
38 | 'tag_id', |
||
39 | TableColumnType::INTEGER, |
||
40 | ['unsigned' => true, 'notnull' => true] |
||
41 | ); |
||
42 | $extraFieldRelTag->setPrimaryKey(['id']); |
||
43 | $extraFieldRelTag->addIndex( |
||
44 | ['field_id'], |
||
45 | 'idx_frt_field' |
||
46 | ); |
||
47 | $extraFieldRelTag->addIndex( |
||
48 | ['item_id'], |
||
49 | 'idx_frt_item' |
||
50 | ); |
||
51 | $extraFieldRelTag->addIndex( |
||
52 | ['tag_id'], |
||
53 | 'idx_frt_tag' |
||
54 | ); |
||
55 | $extraFieldRelTag->addIndex( |
||
56 | ['field_id', 'item_id', 'tag_id'], |
||
57 | 'idx_frt_field_item_tag' |
||
58 | ); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param Schema $schema |
||
64 | */ |
||
65 | public function down(Schema $schema) |
||
66 | { |
||
67 | $schema->dropTable('extra_field_rel_tag'); |
||
68 | } |
||
69 | |||
70 | } |
||
71 |