Completed
Push — master ( b985db...bee0c3 )
by Christian
05:14
created

CreateSpatieModelHasRolesTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 44
loc 44
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 23 2
A down() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateSpatieModelHasRolesTable 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 51
        $columnNames = config('permission.column_names');
18
19
        Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
20 51
            $table->unsignedBigInteger('role_id');
21 51
            $table->string('model_type');
22 51
            $table->unsignedBigInteger($columnNames['model_morph_key']);
23 51
            $table->index([$columnNames['model_morph_key'], 'model_type',]);
24 51
            $table->foreign('role_id')
25 51
                ->references('id')
26 51
                ->on($tableNames['roles'])
27 51
                ->onDelete('cascade');
28 51
            $table->primary(
29 51
                ['role_id', $columnNames['model_morph_key'], 'model_type'],
30 51
                'model_has_roles_role_model_type_primary'
31
            );
32 51
        });
33
34 51
        app('cache')
35 51
            ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
36 51
            ->forget(config('permission.cache.key'));
37 51
    }
38
39
    /**
40
     * Reverse the migrations.
41
     *
42
     * @return void
43
     */
44 51
    public function down()
45
    {
46 51
        $tableNames = config('permission.table_names');
47
48 51
        Schema::drop($tableNames['model_has_roles']);
49 51
    }
50
}
51