Install::safeUp()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 69
ccs 0
cts 63
cp 0
rs 8.6763
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2

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
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\craft\domains\migrations;
10
11
use craft\db\Migration;
12
use craft\records\Element;
13
use craft\records\Field;
14
use craft\records\Site;
15
use flipbox\craft\domains\records\Domain;
16
17
class Install extends Migration
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function safeUp()
23
    {
24
        $this->createTable(Domain::tableName(), [
25
            'fieldId' => $this->integer()->notNull(),
26
            'elementId' => $this->integer()->notNull(),
27
            'domain' => $this->string()->notNull(),
28
            'status' => $this->enum('status', ['enabled', 'pending', 'disabled'])->notNull()->defaultValue('enabled'),
29
            'sortOrder' => $this->smallInteger()->unsigned(),
30
            'siteId' => $this->integer()->notNull(),
31
            'dateCreated' => $this->dateTime()->notNull(),
32
            'dateUpdated' => $this->dateTime()->notNull(),
33
            'uid' => $this->uid(),
34
        ]);
35
36
        $this->addPrimaryKey(
37
            null,
38
            Domain::tableName(),
39
            [
40
                'fieldId',
41
                'elementId',
42
                'domain',
43
                'siteId'
44
            ]
45
        );
46
47
        $this->createIndex(
48
            null,
49
            Domain::tableName(),
50
            'domain',
51
            false
52
        );
53
54
        $this->createIndex(
55
            null,
56
            Domain::tableName(),
57
            'status',
58
            false
59
        );
60
61
        $this->addForeignKey(
62
            null,
63
            Domain::tableName(),
64
            'fieldId',
65
            Field::tableName(),
66
            'id',
67
            'CASCADE',
68
            null
69
        );
70
71
        $this->addForeignKey(
72
            null,
73
            Domain::tableName(),
74
            'elementId',
75
            Element::tableName(),
76
            'id',
77
            'CASCADE',
78
            null
79
        );
80
81
        $this->addForeignKey(
82
            null,
83
            Domain::tableName(),
84
            'siteId',
85
            Site::tableName(),
86
            'id',
87
            'CASCADE',
88
            'CASCADE'
89
        );
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function safeDown()
96
    {
97
        $this->dropTableIfExists(Domain::tableName());
98
    }
99
}
100