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 CreatePermissionUserTable extends Migration |
||
8 | { |
||
9 | /** |
||
10 | * Run the migrations. |
||
11 | * |
||
12 | * @return void |
||
13 | */ |
||
14 | public function up() |
||
15 | { |
||
16 | Schema::create('permission_user', function (Blueprint $table) { |
||
17 | $table->id(); |
||
18 | $table->foreignId('permission_id')->constrained()->cascadeOnDelete(); |
||
19 | $table->foreignId('user_id')->constrained()->cascadeOnDelete(); |
||
20 | $table->timestamps(); |
||
21 | }); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Reverse the migrations. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | public function down() |
||
32 | } |
||
33 | } |
||
34 |