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 |
||
| 4 | class CreateProducts extends AbstractMigration |
||
|
|
|||
| 5 | { |
||
| 6 | /** |
||
| 7 | * Change Method. |
||
| 8 | * |
||
| 9 | * More information on this method is available here: |
||
| 10 | * http://docs.phinx.org/en/latest/migrations.html#the-change-method |
||
| 11 | * @return void |
||
| 12 | */ |
||
| 13 | public function change() |
||
| 14 | { |
||
| 15 | $table = $this->table('products'); |
||
| 16 | $table->addColumn('name', 'string', [ |
||
| 17 | 'default' => null, |
||
| 18 | 'limit' => 255, |
||
| 19 | 'null' => false, |
||
| 20 | ]); |
||
| 21 | $table->addColumn('created', 'datetime', [ |
||
| 22 | 'default' => null, |
||
| 23 | 'null' => false, |
||
| 24 | ]); |
||
| 25 | $table->addColumn('modified', 'datetime', [ |
||
| 26 | 'default' => null, |
||
| 27 | 'null' => false, |
||
| 28 | ]); |
||
| 29 | $table->create(); |
||
| 30 | } |
||
| 31 | } |
||
| 32 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.