Test Failed
Pull Request — master (#2)
by Julien
03:38
created

CreateCategoryTable::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 72
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 9.102
c 0
b 0
f 0
cc 1
eloc 52
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
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
6
class CreateCategoryTable extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return void
12
     */
13
    public function up()
14
    {
15
        Schema::create('category', function (Blueprint $table) {
16
            $table->increments('id');
17
            $table->string('name');
18
            $table->string('alias')->default('');
19
            $table->string('gender')->nullable();
20
            $table->integer('isTeam')->unsigned()->default(0);
21
            $table->integer('ageCategory')->unsigned()->default(0); // 0 = none, 1 = child, 2= teenager, 3 = adult, 4 = master
22
            $table->integer('ageMin')->unsigned()->default(0);
23
            $table->integer('ageMax')->unsigned()->default(0);
24
            $table->integer('gradeCategory')->unsigned()->default(0);
25
            $table->integer('gradeMin')->unsigned()->default(0);
26
            $table->integer('gradeMax')->unsigned()->default(0);
27
//            $table->foreign('gradeMin')
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
//                ->references('id')
29
//                ->on('grade');
30
//            $table->foreign('gradeMax')
31
//                ->references('id')
32
//                ->on('grade');
33
            $table->unique(['name', 'alias', 'gender', 'isTeam', 'ageCategory', 'ageMin', 'ageMax', 'gradeCategory', 'gradeMin', 'gradeMax'], 'category_fields_unique');
34
            $table->timestamps();
35
            $table->engine = 'InnoDB';
36
        });
37
38
        Schema::create('championship', function (Blueprint $table) {
39
            $table->increments('id');
40
            $table->integer('tournament_id')->unsigned()->index();
41
            $table->integer('category_id')->unsigned()->index();
42
            $table->unique(['tournament_id', 'category_id']);
43
44
            $table->foreign('tournament_id')
45
                ->references('id')
46
                ->on('tournament')
47
                ->onUpdate('cascade')
48
                ->onDelete('cascade');
49
50
            $table->foreign('category_id')
51
                ->references('id')
52
                ->on('category')
53
                ->onDelete('cascade');
54
55
            $table->timestamps();
56
            $table->softDeletes();
57
            $table->engine = 'InnoDB';
58
        });
59
60
        Schema::create('competitor', function (Blueprint $table) {
61
            $table->increments('id');
62
            $table->integer('championship_id')->unsigned()->index();
63
            $table->foreign('championship_id')
64
                ->references('id')
65
                ->on('championship')
66
                ->onUpdate('cascade')
67
                ->onDelete('cascade');
68
69
            $table->integer('user_id')->unsigned()->index();
70
            $table->foreign('user_id')
71
                ->references('id')
72
                ->on('users')
73
                ->onUpdate('cascade')
74
                ->onDelete('cascade');
75
76
            $table->unique(['championship_id', 'user_id']);
77
78
            $table->boolean('confirmed');
79
80
            $table->timestamps();
81
            $table->softDeletes();
82
            $table->engine = 'InnoDB';
83
        });
84
    }
85
86
    /**
87
     * Reverse the migrations.
88
     *
89
     * @return void
90
     */
91
    public function down()
92
    {
93
        DB::statement('SET FOREIGN_KEY_CHECKS = 0');
94
        Schema::dropIfExists('competitor');
95
        Schema::dropIfExists('championship');
96
        Schema::dropIfExists('category');
97
        DB::statement('SET FOREIGN_KEY_CHECKS = 1');
98
    }
99
}
100