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 CreateLinksTable extends Migration |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Run the migrations. |
||
| 11 | * |
||
| 12 | * @return void |
||
| 13 | */ |
||
| 14 | public function up() |
||
| 15 | { |
||
| 16 | Schema::create('links', function (Blueprint $table) { |
||
| 17 | $table->increments('id'); |
||
| 18 | $table->string('name')->nullable()->index(); |
||
| 19 | $table->string('url')->nullable(); |
||
| 20 | $table->string('text')->nullable(); |
||
| 21 | $table->integer('order'); |
||
| 22 | $table->integer('project_id')->nullable()->unsigned()->index(); |
||
| 23 | $table->timestamp('deleted_at')->nullable(); |
||
| 24 | $table->timestamps(); |
||
| 25 | |||
| 26 | $table->foreign('project_id') |
||
| 27 | ->references('id') |
||
| 28 | ->on('projects') |
||
| 29 | ->onDelete('cascade'); |
||
| 30 | }); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Reverse the migrations. |
||
| 35 | * |
||
| 36 | * @return void |
||
| 37 | */ |
||
| 38 | public function down() |
||
| 39 | { |
||
| 40 | Schema::dropIfExists('links'); |
||
| 41 | } |
||
| 42 | } |
||
| 43 |