Completed
Push — master ( 6844e6...b8782a )
by ReliQ
05:39 queued 03:33
created

CreateGuidedImageablesTable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
use ReliqArts\GuidedImage\Contracts\ConfigProvider;
7
8
class CreateGuidedImageablesTable extends Migration
9
{
10
    /**
11
     * @var ConfigProvider
12
     */
13
    private $configProvider;
14
15
    /**
16
     * CreateGuidedImagesTable constructor.
17
     *
18
     * @param ConfigProvider $configProvider
19
     */
20
    public function __construct(ConfigProvider $configProvider)
21
    {
22
        $this->configProvider = $configProvider;
23
    }
24
25
    /**
26
     * Run the migrations.
27
     */
28
    public function up()
29
    {
30
        $tableName = $this->configProvider->getImageablesTableName();
31
        $imagesTableName = $this->configProvider->getImagesTableName();
32
33
        if (Schema::hasTable($tableName)) {
34
            return;
35
        }
36
37
        Schema::create($tableName, function (Blueprint $table) use ($imagesTableName) {
38
            $table->increments('id');
39
            $table->integer('image_id')->unsigned();
40
            $table->foreign('image_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')
42
                ->on($imagesTableName)
43
                ->onDelete('CASCADE');
44
            $table->integer('imageable_id');
45
            $table->string('imageable_type');
46
        });
47
    }
48
49
    /**
50
     * Reverse the migrations.
51
     */
52
    public function down()
53
    {
54
        $table = $this->configProvider->getImageablesTableName();
55
        Schema::dropIfExists($table);
56
    }
57
}
58