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 |
||
| 7 | class CreateSpecialitiesTable extends Migration |
||
|
|
|||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Run the migrations. |
||
| 11 | * |
||
| 12 | * @return void |
||
| 13 | */ |
||
| 14 | View Code Duplication | public function up() |
|
| 15 | { |
||
| 16 | Schema::create('specialities', function (Blueprint $table) { |
||
| 17 | $table->increments('id'); |
||
| 18 | $table->integer('code'); |
||
| 19 | $table->string('name'); |
||
| 20 | $table->timestamps(); |
||
| 21 | }); |
||
| 22 | Schema::create('speciality_user', function (Blueprint $table) { |
||
| 23 | $table->integer('user_id')->unsigned(); |
||
| 24 | $table->integer('speciality_id')->unsigned(); |
||
| 25 | $table->timestamps(); |
||
| 26 | $table->unique(['user_id', 'speciality_id']); |
||
| 27 | }); |
||
| 28 | Schema::create('speciality_submodule', function (Blueprint $table) { |
||
| 29 | $table->integer('speciality_id')->unsigned(); |
||
| 30 | $table->integer('submodule_id')->unsigned(); |
||
| 31 | $table->timestamps(); |
||
| 32 | $table->unique(['speciality_id', 'submodule_id']); |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | /** |
||
| 36 | * Reverse the migrations. |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function down() |
||
| 46 | } |
||
| 47 |
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.