CreateContactsTables::up()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 57

Duplication

Lines 10
Ratio 17.54 %

Importance

Changes 0
Metric Value
dl 10
loc 57
rs 8.9381
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
use Illuminate\Database\Schema\Blueprint;
3
use Illuminate\Database\Migrations\Migration;
4
5
class CreateContactsTables extends Migration
6
{
7
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        
16
        Schema::create(
17
            'emails', function (Blueprint $table) {
18
                $table->engine = 'InnoDB';
19
                $table->string('email')->unique();
20
                $table->primary('email');
21
                $table->string('address', 255)->nullable();
22
                $table->string('domain')->nullable();
23
                $table->integer('integration_id')->nullable();
24
                $table->unique(['address', 'domain', 'integration_id']);
25
                $table->timestamps();
26
                $table->softDeletes();
27
            }
28
        );
29
        
30
        Schema::create(
31 View Code Duplication
            'emailables', 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...
32
                $table->engine = 'InnoDB';
33
                $table->string('emailable_id');
34
                $table->string('emailable_type', 255);
35
                $table->string('email_email');
36
                $table->foreign('email_email')->references('email')->on('emails');
37
            
38
                $table->timestamps();
39
                $table->softDeletes();
40
            }
41
        );
42
        
43
        Schema::create(
44
            'phones', function (Blueprint $table) {
45
                $table->engine = 'InnoDB';
46
                $table->increments('id')->unsigned();
47
                $table->string('country', 255)->default('55')->nullable();
48
                $table->string('state', 255)->default('21')->nullable();
49
                $table->string('number')->nullable();
50
                $table->integer('whatsapp')->nullable();
51
                $table->timestamps();
52
                $table->softDeletes();
53
            }
54
        );
55
        
56
        Schema::create(
57
            'phoneables', function (Blueprint $table) {
58
                $table->engine = 'InnoDB';
59
                $table->integer('phone_id')->unsigned();
60
                $table->string('phoneable_id');
61
                $table->string('phoneable_type', 255);
62
                $table->timestamps();
63
                $table->softDeletes();
64
            }
65
        );
66
        
67
        
68
69
    }
70
71
    /**
72
     * Reverse the migrations.
73
     *
74
     * @return void
75
     */
76
    public function down()
77
    {
78
79
80
81
        Schema::dropIfExists('phoneables');
82
        Schema::dropIfExists('phones');
83
        Schema::dropIfExists('emailables');
84
        Schema::dropIfExists('emails');
85
    }
86
87
}
88