Completed
Push — master ( 613104...610d83 )
by Adeola
02:41
created

DatabaseSchema::createKeywordsTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 12
Bugs 1 Features 2
Metric Value
c 12
b 1
f 2
dl 16
loc 16
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
namespace Demo;
4
5
6
use Illuminate\Database\Schema\Blueprint;
7
use Illuminate\Database\Capsule\Manager as Capsule;
8
9
class DatabaseSchema
10
{
11
    /**
12
     * Create users table
13
     */
14
    public function createUsersTable()
15
    {
16
        if (!Capsule::schema()->hasTable('users')) {
17
            Capsule::schema()->create('users', function (Blueprint $table) {
18
                $table->increments('id')->unsigned;
19
                $table->string('fullname');
20
                $table->string('username')->unique();
21
                $table->string('password');
22
                $table->timestamps();
23
            });
24
        }
25
    }
26
27
    /**
28
     * Create emojis table
29
     */
30 View Code Duplication
    public function createEmojisTable()
0 ignored issues
show
Duplication introduced by
This method 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...
31
    {
32
        if (!Capsule::schema()->hasTable('emojis')) {
33
            Capsule::schema()->create('emojis', function (Blueprint $table) {
34
                $table->increments('id')->unsigned;
35
                $table->string('name');
36
                $table->string('chars');
37
                $table->string('category');
38
                $table->string('created_by');
39
                $table->timestamps();
40
41
                $table->foreign('created_by')
42
                    ->references('username')
43
                    ->on('users')
44
                    ->delete('cascade');
45
            });
46
        }
47
    }
48
49
    /**
50
     * Create keywords table
51
     */
52 View Code Duplication
    public function createKeywordsTable()
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        if (!Capsule::schema()->hasTable('keywords')) {
55
            Capsule::schema()->create('keywords', function (Blueprint $table) {
56
                $table->increments('id')->unsigned();
57
                $table->integer('emoji_id')->unsigned();
58
                $table->string('name');
59
                $table->timestamps();
60
61
                $table->foreign('emoji_id')
62
                    ->references('id')
63
                    ->on('emojis')
64
                    ->delete('cascade');
65
            });
66
        }
67
    }
68
69
    /**
70
     * This method dropdown the table
71
     */
72
    public function down()
73
    {
74
        Capsule::schema()->drop('keywords');
75
        Capsule::schema()->drop('emojis');
76
        Capsule::schema()->drop('users');
77
    }
78
}