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 |
||
| 8 | class CreateAttachmentsTable extends Migration |
||
|
|
|||
| 9 | { |
||
| 10 | protected $table_attachments; |
||
| 11 | |||
| 12 | public function __construct() |
||
| 16 | /** |
||
| 17 | * Run the migrations. |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function up() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Reverse the migrations. |
||
| 43 | * |
||
| 44 | * @return void |
||
| 45 | */ |
||
| 46 | public function down() |
||
| 51 | } |
||
| 52 |
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.