CreatePermissionUserTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 18
c 4
b 0
f 0
dl 0
loc 38
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 5 1
A up() 0 17 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreatePermissionUserTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        $connection = config('roles.connection');
17
        $table = config('roles.permissionsUserTable');
18
        $permissionsTable = config('roles.permissionsTable');
19
        $tableCheck = Schema::connection($connection)->hasTable($table);
20
        $userTable = app(config('auth.providers.users.model'))->getTable();
0 ignored issues
show
introduced by
The method getTable() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $userTable = app(config('auth.providers.users.model'))->/** @scrutinizer ignore-call */ getTable();
Loading history...
21
22
        if (!$tableCheck) {
23
            Schema::connection($connection)->create($table, function (Blueprint $table) use ($permissionsTable, $userTable) {
24
                $table->increments('id')->unsigned();
25
                $table->integer('permission_id')->unsigned()->index();
26
                $table->foreign('permission_id')->references('id')->on($permissionsTable)->onDelete('cascade');
27
                $table->unsignedBigInteger('user_id')->unsigned()->index();
28
                $table->foreign('user_id')->references('id')->on($userTable)->onDelete('cascade');
29
                $table->timestamps();
30
                $table->softDeletes();
31
            });
32
        }
33
    }
34
35
    /**
36
     * Reverse the migrations.
37
     *
38
     * @return void
39
     */
40
    public function down()
41
    {
42
        $connection = config('roles.connection');
43
        $table = config('roles.permissionsUserTable');
44
        Schema::connection($connection)->dropIfExists($table);
45
    }
46
}
47