Test Setup Failed
Branch dev5 (dcc882)
by Ron
19:55
created

CreateUserRolePermissionsTable::up()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 73
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 61
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 73
rs 8.8509

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
use Illuminate\Support\Facades\Schema;
6
use Carbon\Carbon;
7
8
class CreateUserRolePermissionsTable extends Migration
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::create('user_role_permissions', function (Blueprint $table) {
18
            $table->increments('id');
19
            $table->integer('role_id')->unsigned();
20
            $table->integer('perm_type_id')->unsigned();
21
            $table->boolean('allow')->default(0);
22
            $table->timestamps();
23
            $table->foreign('role_id')->references('role_id')->on('user_role_types')->onUpdate('cascade');
24
            $table->foreign('perm_type_id')->references('perm_type_id')->on('user_role_permission_types')->onUpdate('cascade');
25
        });
26
27
        $defaults = [
28
            1 => [
29
                1  => 1,
30
                2  => 1,
31
                3  => 1,
32
                4  => 1,
33
                5  => 1,
34
                6  => 1,
35
                7  => 1,
36
                8  => 1,
37
                9  => 1,
38
                10 => 1,
39
            ],
40
            2 => [
41
                1  => 1,
42
                2  => 1,
43
                3  => 1,
44
                4  => 1,
45
                5  => 1,
46
                6  => 1,
47
                7  => 1,
48
                8  => 1,
49
                9  => 0,
50
                10 => 0,
51
            ],
52
            3 => [
53
                1  => 0,
54
                2  => 1,
55
                3  => 1,
56
                4  => 0,
57
                5  => 1,
58
                6  => 1,
59
                7  => 0,
60
                8  => 0,
61
                9  => 0,
62
                10 => 0,
63
            ],
64
            4 => [
65
                1  => 0,
66
                2  => 0,
67
                3  => 1,
68
                4  => 0,
69
                5  => 1,
70
                6  => 1,
71
                7  => 0,
72
                8  => 0,
73
                9  => 0,
74
                10 => 0,
75
            ],
76
        ];
77
78
        foreach($defaults as $role_id => $perms)
79
        {
80
            foreach($perms as $perm_type_id => $allow)
81
            {
82
                DB::table('user_role_permissions')->insert([
83
                    'role_id'      => $role_id,
84
                    'perm_type_id' => $perm_type_id,
85
                    'allow'        => $allow,
86
                    'created_at'   => Carbon::now(),
87
                    'updated_at'   => Carbon::now(),
88
                ]);
89
            }
90
        }
91
    }
92
93
    /**
94
     * Reverse the migrations.
95
     *
96
     * @return void
97
     */
98
    public function down()
99
    {
100
        Schema::dropIfExists('user_role_permissions');
101
    }
102
}
103