Completed
Push — master ( e68c06...8ce3f9 )
by Adolfo
14s queued 11s
created

CreateSubscriptionsTables::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 83

Duplication

Lines 46
Ratio 55.42 %

Importance

Changes 0
Metric Value
dl 46
loc 83
rs 8.3709
c 0
b 0
f 0
cc 1
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\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateSubscriptionsTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16 View Code Duplication
        Schema::create('plans', 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->engine = 'InnoDB';
18
19
            $table->increments('id');
20
            $table->string('name');
21
            $table->text('description')->nullable();
22
            $table->string('group', 100)->nullable();
23
            $table->integer('free_days')->default(0);
24
            $table->tinyInteger('sort_order');
25
            $table->boolean('is_active')->default(0);
26
            $table->boolean('is_default')->default(0);
27
28
            $table->timestamps();
29
        });
30
31
        Schema::create('plan_prices', function (Blueprint $table) {
32
            $table->engine = 'InnoDB';
33
34
            $table->increments('id');
35
            $table->integer('plan_id')->unsigned();
36
            $table->decimal('amount');
37
            $table->enum('interval', ['day',  'month',  'year'])->nullable();
38
            $table->integer('interval_unit');
39
40
            $table->foreign('plan_id')
0 ignored issues
show
Bug introduced by
The method references does only exist in Illuminate\Database\Schema\ForeignKeyDefinition, but not in Illuminate\Support\Fluent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
41
                ->references('id')->on('plans');
42
43
            $table->timestamps();
44
        });
45
46 View Code Duplication
        Schema::create('plan_features', 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...
47
            $table->engine = 'InnoDB';
48
49
            $table->increments('id');
50
            $table->integer('plan_id')->unsigned();
51
            $table->string('code', 100);
52
            $table->integer('value')->default(0);
53
            $table->integer('sort_order');
54
            $table->boolean('is_consumable')->default(0);
55
56
            $table->foreign('plan_id')
0 ignored issues
show
Bug introduced by
The method references does only exist in Illuminate\Database\Schema\ForeignKeyDefinition, but not in Illuminate\Support\Fluent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
57
                ->references('id')->on('plans');
58
59
            $table->timestamps();
60
        });
61
62
        Schema::create('subscriptions', function (Blueprint $table) {
63
            $table->engine = 'InnoDB';
64
65
            $table->increments('id');
66
            $table->integer('plan_id')->unsigned();
67
            $table->string('subscriber_type')->nullable();
68
            $table->timestamp('subscriber_id')->nullable();
69
            $table->timestamp('start_at')->nullable();
70
            $table->timestamp('end_at')->nullable();
71
            $table->timestamp('cancelled_at')->nullable();
72
            $table->timestamp('upgrade_at')->nullable();
73
            $table->timestamp('downgrade_at')->nullable();
74
75
            $table->foreign('plan_id')
0 ignored issues
show
Bug introduced by
The method references does only exist in Illuminate\Database\Schema\ForeignKeyDefinition, but not in Illuminate\Support\Fluent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
76
                ->references('id')->on('plans');
77
78
            $table->timestamps();
79
        });
80
81 View Code Duplication
        Schema::create('subscriber_consumables', 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...
82
            $table->engine = 'InnoDB';
83
84
            $table->increments('id');
85
            $table->integer('plan_feature_id')->unsigned();
86
            $table->string('subscriber_type');
87
            $table->integer('subscriber_id');
88
            $table->integer('available')->nullable();
89
            $table->integer('used')->nullable();
90
91
            $table->foreign('plan_feature_id')
0 ignored issues
show
Bug introduced by
The method references does only exist in Illuminate\Database\Schema\ForeignKeyDefinition, but not in Illuminate\Support\Fluent.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
92
                ->references('id')->on('plans_features');
93
94
            $table->timestamps();
95
        });
96
    }
97
98
    /**
99
     * Reverse the migrations.
100
     *
101
     * @return void
102
     */
103
    public function down()
104
    {
105
        Schema::dropIfExists('subscriber_consumables');
106
        Schema::dropIfExists('subscriptions');
107
        Schema::dropIfExists('plan_features');
108
        Schema::dropIfExists('plan_prices');
109
        Schema::dropIfExists('plans');
110
    }
111
}
112