CreateProjectsTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 52
rs 9.0472
c 0
b 0
f 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
use Illuminate\Support\Facades\Schema;
6
7
class CreateProjectsTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create('projects', function (Blueprint $table) {
17
            $table->bigIncrements('id');
18
19
            $table->foreignId('author_id')->nullable()
20
            ->references(user_model()->getKeyName())
21
            ->on(user_model()->getTable());
22
23
            $table->foreignId('owner_id')->nullable()
24
            ->references(user_model()->getKeyName())
25
            ->on(user_model()->getTable());
26
27
            $table->foreignId('status_id')->nullable()
28
            ->references('id')
29
            ->on('statuses');
30
31
            $table->string('title');
32
            $table->text('description')->nullable();
33
            $table->text('notes')->nullable();
34
            $table->integer('visible')->default(1)->nullable();
35
36
            $table->timestamp('started_at')->nullable();
37
            $table->timestamp('delivered_at')->nullable();
38
            $table->timestamp('expected_at')->nullable();
39
40
            $table->timestamps();
41
            $table->softDeletes();
42
        });
43
44
        Schema::create('projectables', function (Blueprint $table) {
45
            $table->increments('id');
46
            $table->integer('project_id');
47
            $table->integer('projectable_id');
48
            $table->string('projectable_type');
49
        });
50
51
        Schema::create('project_users', function (Blueprint $table) {
52
            $table->increments('id');
53
54
            $table->foreignId('project_id')
55
            ->references('id')
56
            ->on('projects');
57
58
            $table->foreignId('user_id')
59
            ->references(user_model()->getKeyName())
60
            ->on(user_model()->getTable());
61
62
            $table->string('status')->nullable();
63
            $table->string('role')->nullable();
64
        });
65
    }
66
67
    /**
68
     * Reverse the migrations.
69
     *
70
     * @return void
71
     */
72
    public function down()
73
    {
74
        Schema::dropIfExists('project_users');
75
76
        Schema::dropIfExists('projectables');
77
78
        Schema::dropIfExists('projects');
79
    }
80
}
81