Completed
Pull Request — master (#10)
by alexfloppy
07:51
created

EntrustSetupTables::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 41

Duplication

Lines 48
Ratio 82.76 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 48
loc 58
rs 9.639
cc 1
eloc 41
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 EntrustSetupTables 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
        // Create table for storing roles
16 View Code Duplication
        Schema::create('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...
17
            $table->increments('id');
18
            $table->string('name')->unique();
19
            $table->string('display_name')->nullable();
20
            $table->string('description')->nullable();
21
            $table->timestamps();
22
        });
23
24
        // Create table for associating roles to users (Many-to-Many)
25 View Code Duplication
        Schema::create('role_user', 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->integer('user_id')->unsigned();
27
            $table->integer('role_id')->unsigned();
28
29
            $table->foreign('user_id')
30
                ->references('id')
31
                ->on('users')
32
                ->onUpdate('cascade')
33
                ->onDelete('cascade');
34
            $table->foreign('role_id')
35
                ->references('id')
36
                ->on('roles')
37
                ->onUpdate('cascade')
38
                ->onDelete('cascade');
39
40
            $table->primary(['user_id', 'role_id']);
41
        });
42
43
        // Create table for storing permissions
44 View Code Duplication
        Schema::create('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...
45
            $table->increments('id');
46
            $table->string('name')->unique();
47
            $table->string('display_name')->nullable();
48
            $table->string('description')->nullable();
49
            $table->timestamps();
50
        });
51
52
        // Create table for associating permissions to roles (Many-to-Many)
53 View Code Duplication
        Schema::create('permission_role', 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...
54
            $table->integer('permission_id')->unsigned();
55
            $table->integer('role_id')->unsigned();
56
57
            $table->foreign('permission_id')
58
                ->references('id')
59
                ->on('permissions')
60
                ->onUpdate('cascade')
61
                ->onDelete('cascade');
62
            $table->foreign('role_id')
63
                ->references('id')
64
                ->on('roles')
65
                ->onUpdate('cascade')
66
                ->onDelete('cascade');
67
68
            $table->primary(['permission_id', 'role_id']);
69
        });
70
    }
71
72
    /**
73
     * Reverse the migrations.
74
     *
75
     * @return  void
76
     */
77
    public function down()
78
    {
79
        Schema::drop('permission_role');
80
        Schema::drop('permissions');
81
        Schema::drop('role_user');
82
        Schema::drop('roles');
83
    }
84
}
85