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 | |||
9 | class AddForeignKeysToInlineQueryTable extends Migration |
||
10 | { |
||
11 | public function up(): void |
||
12 | { |
||
13 | Schema::table('inline_query', static function (Blueprint $table) { |
||
14 | $table->foreign('user_id', 'inline_query_ibfk_1')->references('id')->on('user')->onUpdate('RESTRICT')->onDelete('RESTRICT'); |
||
15 | }); |
||
16 | } |
||
17 | |||
18 | public function down(): void |
||
22 | }); |
||
23 | } |
||
24 | } |
||
25 |