CreateBuildsTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Faithgen\AppBuild\Models\Build;
4
use Illuminate\Database\Migrations\Migration;
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Support\Facades\Schema;
7
8 View Code Duplication
class CreateBuildsTable extends Migration
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::create('fg_app_builds', function (Blueprint $table) {
18
            $table->string('id')->index();
19
            $table->string('ministry_id', 150)->index();
20
            $table->string('version');
21
            $table->enum('status', Build::BUILD_STATUS)->default('building');
22
            $table->timestamps();
23
24
            $table->foreign('ministry_id')->references('id')->on('fg_ministries')->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...
25
        });
26
    }
27
28
    /**
29
     * Reverse the migrations.
30
     *
31
     * @return void
32
     */
33
    public function down()
34
    {
35
        Schema::dropIfExists('fg_app_builds');
36
    }
37
}
38