Completed
Push — develop ( 6deca1...bf40a6 )
by Adolfo
01:08
created

CreateSubscriptionsTables::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
        Schema::create('plans', function(Blueprint $table) {
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
32
        Schema::create('plan_prices', function(Blueprint $table) {
33
            $table->engine = 'InnoDB';
34
35
            $table->increments('id');
36
            $table->integer('plan_id')->unsigned();
37
            $table->decimal('amount');
38
            $table->enum('interval', ['day',  'month',  'year'])->nullable();
39
            $table->integer('interval_unit');
40
41
            $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...
42
                ->references('id')->on('plans');
43
44
            $table->timestamps();
45
46
        });
47
48 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...
49
            $table->engine = 'InnoDB';
50
51
            $table->increments('id');
52
            $table->integer('plan_id')->unsigned();
53
            $table->string('code', 100);
54
            $table->integer('value')->default(0);
55
            $table->integer('sort_order');
56
            $table->boolean('is_consumable')->default(0);
57
58
            $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...
59
                ->references('id')->on('plans');
60
61
            $table->timestamps();
62
63
        });
64
65
        Schema::create('subscriptions', function(Blueprint $table) {
66
            $table->engine = 'InnoDB';
67
68
            $table->increments('id');
69
            $table->integer('plan_id')->unsigned();
70
            $table->string('subscriber_type')->nullable();
71
            $table->timestamp('subscriber_id')->nullable();
72
            $table->timestamp('start_at')->nullable();
73
            $table->timestamp('end_at')->nullable();
74
            $table->timestamp('cancelled_at')->nullable();
75
            $table->timestamp('upgrade_at')->nullable();
76
            $table->timestamp('downgrade_at')->nullable();
77
78
            $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...
79
                ->references('id')->on('plans');
80
81
            $table->timestamps();
82
83
        });
84
85 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...
86
            $table->engine = 'InnoDB';
87
88
            $table->increments('id');
89
            $table->integer('plan_feature_id')->unsigned();
90
            $table->string('subscriber_type');
91
            $table->integer('subscriber_id');
92
            $table->integer('available')->nullable();
93
            $table->integer('used')->nullable();
94
95
            $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...
96
                ->references('id')->on('plans_features');
97
98
            $table->timestamps();
99
100
        });
101
    }
102
103
    /**
104
     * Reverse the migrations.
105
     *
106
     * @return void
107
     */
108
    public function down()
109
    {
110
        Schema::dropIfExists('subscriber_consumables');
111
        Schema::dropIfExists('subscriptions');
112
        Schema::dropIfExists('plan_features');
113
        Schema::dropIfExists('plan_prices');
114
        Schema::dropIfExists('plans');
115
    }
116
}
117