Completed
Push — master ( bfbb50...8023d3 )
by Sherif
09:55
created

CreateTelescopeEntriesTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 14.81 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 12
loc 81
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConnection() 0 4 1
A up() 12 34 1
A down() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateTelescopeEntriesTable extends Migration
8
{
9
    /**
10
     * The database schema.
11
     *
12
     * @var \Illuminate\Database\Schema\Builder
13
     */
14
    protected $schema;
15
16
    /**
17
     * Create a new migration instance.
18
     *
19
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
20
     */
21
    public function __construct()
22
    {
23
        $this->schema = Schema::connection($this->getConnection());
24
    }
25
26
    /**
27
     * Get the migration connection name.
28
     *
29
     * @return string|null
30
     */
31
    public function getConnection()
32
    {
33
        return config('telescope.storage.database.connection');
34
    }
35
36
    /**
37
     * Run the migrations.
38
     *
39
     * @return void
40
     */
41
    public function up()
42
    {
43
        $this->schema->create('telescope_entries', function (Blueprint $table) {
44
            $table->bigIncrements('sequence');
45
            $table->uuid('uuid');
46
            $table->uuid('batch_id');
47
            $table->string('family_hash')->nullable()->index();
48
            $table->boolean('should_display_on_index')->default(true);
49
            $table->string('type', 20);
50
            $table->longText('content');
51
            $table->dateTime('created_at')->nullable();
52
53
            $table->unique('uuid');
54
            $table->index('batch_id');
55
            $table->index(['type', 'should_display_on_index']);
56
        });
57
58 View Code Duplication
        $this->schema->create('telescope_entries_tags', 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...
59
            $table->uuid('entry_uuid');
60
            $table->string('tag');
61
62
            $table->index(['entry_uuid', 'tag']);
63
            $table->index('tag');
64
65
            $table->foreign('entry_uuid')
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...
66
                  ->references('uuid')
67
                  ->on('telescope_entries')
68
                  ->onDelete('cascade');
69
        });
70
71
        $this->schema->create('telescope_monitoring', function (Blueprint $table) {
72
            $table->string('tag');
73
        });
74
    }
75
76
    /**
77
     * Reverse the migrations.
78
     *
79
     * @return void
80
     */
81
    public function down()
82
    {
83
        $this->schema->dropIfExists('telescope_entries_tags');
84
        $this->schema->dropIfExists('telescope_entries');
85
        $this->schema->dropIfExists('telescope_monitoring');
86
    }
87
}
88