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 |
||
| 11 | class Version20170623205224 extends AbstractMigration |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @param Schema $schema |
||
| 15 | */ |
||
| 16 | public function up(Schema $schema) |
||
| 17 | { |
||
| 18 | $table = $schema->createTable('usage_projects'); |
||
| 19 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 20 | $table->addColumn('tool', 'string'); |
||
| 21 | $table->addColumn('project', 'string'); |
||
| 22 | $table->addColumn('count', 'integer'); |
||
| 23 | $table->setPrimaryKey(['id']); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Schema $schema |
||
| 28 | */ |
||
| 29 | public function down(Schema $schema) |
||
| 30 | { |
||
| 31 | $schema->dropTable('usage_projects'); |
||
| 32 | } |
||
| 33 | } |
||
| 34 |