Completed
Push — master ( ae3446...a9781c )
by Mahmoud
06:03
created

CreatePermissionTables::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 71
Code Lines 50

Duplication

Lines 62
Ratio 87.32 %

Importance

Changes 0
Metric Value
dl 62
loc 71
rs 9.1369
c 0
b 0
f 0
cc 1
eloc 50
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class CreatePermissionTables extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        $config = config('laravel-permission.table_names');
16
17 View Code Duplication
        Schema::create($config['roles'], function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
            $table->increments('id');
19
            $table->string('name')->unique();
20
            $table->string('display_name')->nullable();
21
            $table->string('description')->nullable();
22
            $table->timestamps();
23
        });
24
25 View Code Duplication
        Schema::create($config['permissions'], function (Blueprint $table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            $table->increments('id');
27
            $table->string('name')->unique();
28
            $table->string('display_name')->nullable();
29
            $table->string('description')->nullable();
30
            $table->timestamps();
31
        });
32
33 View Code Duplication
        Schema::create($config['user_has_permissions'], function (Blueprint $table) use ($config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            $table->integer('user_id')->unsigned();
35
            $table->integer('permission_id')->unsigned();
36
37
            $table->foreign('user_id')
38
                ->references('id')
39
                ->on($config['users'])
40
                ->onDelete('cascade');
41
42
            $table->foreign('permission_id')
43
                ->references('id')
44
                ->on($config['permissions'])
45
                ->onDelete('cascade');
46
47
            $table->primary(['user_id', 'permission_id']);
48
        });
49
50 View Code Duplication
        Schema::create($config['user_has_roles'], function (Blueprint $table) use ($config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $table->integer('role_id')->unsigned();
52
            $table->integer('user_id')->unsigned();
53
54
            $table->foreign('role_id')
55
                ->references('id')
56
                ->on($config['roles'])
57
                ->onDelete('cascade');
58
59
            $table->foreign('user_id')
60
                ->references('id')
61
                ->on($config['users'])
62
                ->onDelete('cascade');
63
64
            $table->primary(['role_id', 'user_id']);
65
        });
66
67 View Code Duplication
        Schema::create($config['role_has_permissions'], function (Blueprint $table) use ($config) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
            $table->integer('permission_id')->unsigned();
69
            $table->integer('role_id')->unsigned();
70
71
            $table->foreign('permission_id')
72
                ->references('id')
73
                ->on($config['permissions'])
74
                ->onDelete('cascade');
75
76
            $table->foreign('role_id')
77
                ->references('id')
78
                ->on($config['roles'])
79
                ->onDelete('cascade');
80
81
            $table->primary(['permission_id', 'role_id']);
82
        });
83
    }
84
85
    /**
86
     * Reverse the migrations.
87
     *
88
     * @return void
89
     */
90
    public function down()
91
    {
92
        $config = config('laravel-permission.table_names');
93
94
        Schema::drop($config['role_has_permissions']);
95
        Schema::drop($config['user_has_roles']);
96
        Schema::drop($config['user_has_permissions']);
97
        Schema::drop($config['roles']);
98
        Schema::drop($config['permissions']);
99
    }
100
}
101