CreateLaravelBlockerTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 7 1
A up() 0 21 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Migrations\Migration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Illuminate\Database\Schema\Blueprint;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Schema\Blueprint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Illuminate\Support\Facades\Schema;
6
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem;
7
use jeremykenedy\LaravelBlocker\App\Models\BlockedType;
8
9
class CreateLaravelBlockerTable extends Migration
10
{
11
    /**
12
     * Run the migrations.
13
     *
14
     * @return void
15
     */
16
    public function up()
17
    {
18
        $blocked = new BlockedItem();
19
        $connection = $blocked->getConnectionName();
20
        $table = $blocked->getTableName();
21
        $tableCheck = Schema::connection($connection)->hasTable($table);
22
23
        if (!$tableCheck) {
24
            Schema::connection($connection)->create($table, function (Blueprint $table) {
25
                $blockedType = new BlockedType();
26
                $connectionType = $blockedType->getConnectionName();
0 ignored issues
show
Unused Code introduced by
The assignment to $connectionType is dead and can be removed.
Loading history...
27
                $tableTypeName = $blockedType->getTableName();
28
                $table->increments('id');
29
                $table->integer('typeId')->unsigned()->index();
30
                $table->foreign('typeId')->references('id')->on($tableTypeName)->onDelete('cascade');
31
                $table->string('value')->unique();
32
                $table->longText('note')->nullable();
33
                $table->integer('userId')->unsigned()->index()->nullable();
34
                // $table->foreign('userId')->references('id')->on('users')->onDelete('cascade');
35
                $table->timestamps();
36
                $table->softDeletes();
37
            });
38
        }
39
    }
40
41
    /**
42
     * Reverse the migrations.
43
     *
44
     * @return void
45
     */
46
    public function down()
47
    {
48
        $blocked = new BlockedItem();
49
        $connection = $blocked->getConnectionName();
50
        $table = $blocked->getTableName();
51
52
        Schema::connection($connection)->dropIfExists($table);
53
    }
54
}
55