Completed
Push — master ( a20c7b...d885ca )
by Nate
02:36
created

Install::safeUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 0
cts 54
cp 0
rs 8.8945
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://github.com/flipboxfactory/craft-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\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\element\lists\records\Association;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Install extends Migration
22
{
23
    /**
24
     * @inheritdoc
25
     */
26
    public function safeUp()
27
    {
28
        $this->createTable(Association::tableName(), [
29
            'fieldId' => $this->integer()->notNull(),
30
            'sourceId' => $this->integer()->notNull(),
31
            'targetId' => $this->integer()->notNull(),
32
            'siteId' => $this->integer()->notNull(),
33
            'sortOrder' => $this->integer()->unsigned(),
34
            'dateCreated' => $this->dateTime()->notNull(),
35
            'dateUpdated' => $this->dateTime()->notNull(),
36
            'uid' => $this->uid(),
37
        ]);
38
39
        $this->addPrimaryKey(
40
            null,
41
            Association::tableName(),
42
            ['fieldId', 'sourceId', 'targetId', 'siteId']
43
        );
44
45
        $this->addForeignKey(
46
            null,
47
            Association::tableName(),
48
            'fieldId',
49
            Field::tableName(),
50
            'id',
51
            'CASCADE',
52
            null
53
        );
54
55
        $this->addForeignKey(
56
            null,
57
            Association::tableName(),
58
            'sourceId',
59
            Element::tableName(),
60
            'id',
61
            'CASCADE',
62
            null
63
        );
64
65
        $this->addForeignKey(
66
            null,
67
            Association::tableName(),
68
            'targetId',
69
            Element::tableName(),
70
            'id',
71
            'CASCADE',
72
            null
73
        );
74
75
        $this->addForeignKey(
76
            null,
77
            Association::tableName(),
78
            'siteId',
79
            Site::tableName(),
80
            'id',
81
            'CASCADE',
82
            'CASCADE'
83
        );
84
    }
85
}
86