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 CreateSpatiePermissionsTable extends Migration |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Run the migrations. |
||
| 11 | * |
||
| 12 | * @return void |
||
| 13 | */ |
||
| 14 | 51 | public function up() |
|
| 15 | { |
||
| 16 | 51 | $tableNames = config('permission.table_names'); |
|
| 17 | |||
| 18 | Schema::create($tableNames['permissions'], function (Blueprint $table) { |
||
| 19 | 51 | $table->bigIncrements('id'); |
|
| 20 | 51 | $table->string('name'); |
|
| 21 | 51 | $table->string('guard_name'); |
|
| 22 | 51 | $table->timestamps(); |
|
| 23 | 51 | }); |
|
| 24 | |||
| 25 | 51 | app('cache') |
|
| 26 | 51 | ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) |
|
| 27 | 51 | ->forget(config('permission.cache.key')); |
|
| 28 | 51 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Reverse the migrations. |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | 51 | public function down() |
|
| 36 | { |
||
| 37 | 51 | $tableNames = config('permission.table_names'); |
|
| 38 | |||
| 39 | 51 | Schema::drop($tableNames['permissions']); |
|
| 40 | 51 | } |
|
| 41 | } |
||
| 42 |