Schema   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 63.64 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 12
Bugs 7 Features 0
Metric Value
wmc 9
c 12
b 7
f 0
lcom 0
cbo 2
dl 49
loc 77
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A createUser() 14 14 2
A createKeyword() 11 11 2
A createCategory() 10 10 2
A createEmoji() 13 13 2

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
 * @author   Temitope Olotin <[email protected]>
4
 * @license  <https://opensource.org/license/MIT> MIT
5
 */
6
namespace Laztopaz\EmojiRestfulAPI;
7
8
use Illuminate\Database\Capsule\Manager as Capsule;
9
10
class Schema
11
{
12
    /**
13
     * This method migrates all database schema when this class is instatiated.
14
     */
15
    public function __construct()
16
    {
17
        $this->createUser();
18
        $this->createKeyword();
19
        $this->createCategory();
20
        $this->createEmoji();
21
    }
22
23
    /**
24
     * This method create users schema.
25
     */
26 View Code Duplication
    public function createUser()
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...
27
    {
28
        if (! Capsule::schema()->hasTable('users')) {
29
            Capsule::schema()->create('users', function ($table) {
30
                $table->increments('id');
31
                $table->string('firstname');
32
                $table->string('lastname');
33
                $table->string('username');
34
                $table->string('password');
35
                $table->string('email')->unique();
36
                $table->timestamps();
37
            });
38
        }
39
    }
40
41
    /**
42
     * This method creates keyword schema.
43
     */
44 View Code Duplication
    public function createKeyword()
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...
45
    {
46
        if (! Capsule::schema()->hasTable('keywords')) {
47
            Capsule::schema()->create('keywords', function ($table) {
48
                $table->increments('id');
49
                $table->integer('emoji_id');
50
                $table->string('keyword_name');
51
                $table->timestamps();
52
            });
53
        }
54
    }
55
56
    /**
57
     * This method creates emoji category schema.
58
     */
59 View Code Duplication
    public function createCategory()
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...
60
    {
61
        if (! Capsule::schema()->hasTable('categories')) {
62
            Capsule::schema()->create('categories', function ($table) {
63
                $table->increments('id');
64
                $table->string('category_name');
65
                $table->timestamps();
66
            });
67
        }
68
    }
69
70
    /**
71
     * This method creates emoji  schema.
72
     */
73 View Code Duplication
    public function createEmoji()
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...
74
    {
75
        if (! Capsule::schema()->hasTable('emojis')) {
76
            Capsule::schema()->create('emojis', function ($table) {
77
                $table->increments('id');
78
                $table->string('name');
79
                $table->string('char');
80
                $table->string('category');
81
                $table->string('created_by');
82
                $table->timestamps();
83
            });
84
        }
85
    }
86
}
87