CreatePromocodesTable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 27 1
A down() 0 5 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class CreatePromocodesTable extends Migration
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        Schema::create('promocodes', function (Blueprint $table) {
16
            $table->increments('id');
17
18
            $table->string('code', 32)->unique();
19
            $table->double('reward', 10, 2)->nullable();
20
            $table->integer('quantity')->nullable();
21
22
            $table->text('data')->nullable();
23
24
            $table->boolean('is_disposable')->default(false);
25
            $table->timestamp('expires_at')->nullable();
26
        });
27
28
        Schema::create('promocode_user', function (Blueprint $table) {
29
            $table->increments('id');
30
31
            $table->unsignedBigInteger('user_id');
32
            $table->unsignedBigInteger('promocode_id');
33
34
            $table->timestamp('used_at');
35
36
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
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...
37
            $table->foreign('promocode_id')->references('id')->on('promocodes')->onDelete('cascade');
38
        });
39
    }
40
41
    /**
42
     * Reverse the migrations.
43
     *
44
     * @return void
45
     */
46
    public function down()
47
    {
48
        Schema::drop('promocode_user');
49
        Schema::drop('promocodes');
50
    }
51
}
52