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 |
||
| 9 | class update_cms_302 extends Migration implements MigrationInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Execute actions when migration is up |
||
| 13 | * @return void |
||
| 14 | */ |
||
| 15 | public function up() |
||
| 16 | { |
||
| 17 | if ($this->getSchema()->hasColumn('user_recoveries', 'password')) { |
||
| 18 | $this->getSchema()->table('user_recoveries', function ($table) { |
||
| 19 | $table->dropColumn('password'); |
||
| 20 | }); |
||
| 21 | } |
||
| 22 | parent::up(); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Seed created table via up() method with some data |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function seed() {} |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Execute actions when migration is down |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | public function down() |
||
| 43 | } |
||
| 44 | } |