Completed
Pull Request — master (#4037)
by Muhlis
02:52
created

CreateTestTables   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 93
Duplicated Lines 9.68 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 9 69 1
A down() 0 10 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
6
class CreateTestTables extends Migration
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        Schema::create('test_images', function (Blueprint $table) {
16
            $table->increments('id');
17
            $table->string('image1');
18
            $table->string('image2');
19
            $table->string('image3');
20
            $table->string('image4');
21
            $table->string('image5');
22
            $table->string('image6');
23
            $table->timestamps();
24
        });
25
26
        Schema::create('test_multiple_images', function (Blueprint $table) {
27
            $table->increments('id');
28
            $table->text('pictures');
29
            $table->timestamps();
30
        });
31
32
        Schema::create('test_files', function (Blueprint $table) {
33
            $table->increments('id');
34
            $table->string('file1');
35
            $table->string('file2');
36
            $table->string('file3');
37
            $table->string('file4');
38
            $table->string('file5');
39
            $table->string('file6');
40
            $table->timestamps();
41
        });
42
43 View Code Duplication
        Schema::create('test_users', 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...
44
            $table->increments('id');
45
            $table->string('username');
46
            $table->string('email');
47
            $table->string('mobile')->nullable();
48
            $table->string('avatar')->nullable();
49
            $table->string('password');
50
            $table->timestamps();
51
        });
52
53
        Schema::create('test_user_profiles', function (Blueprint $table) {
54
            $table->increments('id');
55
            $table->string('user_id');
56
            $table->string('first_name')->nullable();
57
            $table->string('last_name')->nullable();
58
            $table->string('postcode')->nullable();
59
            $table->string('address')->nullable();
60
            $table->string('latitude')->nullable();
61
            $table->string('longitude')->nullable();
62
            $table->string('color')->nullable();
63
            $table->timestamp('start_at')->nullable();
64
            $table->timestamp('end_at')->nullable();
65
66
            $table->timestamps();
67
        });
68
69
        Schema::create('test_tags', function (Blueprint $table) {
70
            $table->increments('id');
71
            $table->string('name');
72
            $table->timestamps();
73
        });
74
75
        Schema::create('test_user_tags', function (Blueprint $table) {
76
            $table->integer('user_id');
77
            $table->integer('tag_id');
78
            $table->index(['user_id', 'tag_id']);
79
            $table->timestamps();
80
        });
81
    }
82
83
    /**
84
     * Reverse the migrations.
85
     *
86
     * @return void
87
     */
88
    public function down()
89
    {
90
        Schema::dropIfExists('test_images');
91
        Schema::dropIfExists('test_multiple_images');
92
        Schema::dropIfExists('test_files');
93
        Schema::dropIfExists('test_users');
94
        Schema::dropIfExists('test_user_profiles');
95
        Schema::dropIfExists('test_tags');
96
        Schema::dropIfExists('test_user_tags');
97
    }
98
}
99