m161031_094747_create_content_table::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.0254
c 0
b 0
f 0
cc 2
nc 2
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 yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `content`.
7
 */
8
// @codingStandardsIgnoreLine
9
class m161031_094747_create_content_table extends Migration
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function up()
15
    {
16
        $tableOptions = null;
17
        if ($this->db->driverName === 'mysql') {
18
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
19
        }
20
21
        $this->createTable('content', [
22
            'id' => $this->primaryKey()->notNull()->append('AUTO_INCREMENT'),
23
            'name' => $this->string(64)->notNull(),
24
            'description' => $this->string(1024),
25
            'flow_id' => $this->integer()->notNull(),
26
            'type_id' => $this->string(45)->notNull(),
27
            'data' => $this->text(),
28
            'duration' => $this->integer()->notNull()->defaultValue(10),
29
            'start_ts' => $this->timestamp()->null(),
30
            'end_ts' => $this->timestamp()->null(),
31
            'add_ts' => $this->timestamp()->notNull()->defaultExpression('CURRENT_TIMESTAMP'),
32
            'enabled' => $this->boolean()->notNull()->defaultValue(true),
33
        ], $tableOptions);
34
35
        $this->createIndex(
36
            'fk_content_flow1_idx',
37
            'content',
38
            'flow_id'
39
        );
40
41
        $this->createIndex(
42
            'fk_content_content_type1_idx',
43
            'content',
44
            'type_id'
45
        );
46
47
        $this->addForeignKey(
48
            'fk_content_flow1',
49
            'content',
50
            'flow_id',
51
            'flow',
52
            'id',
53
            'CASCADE',
54
            'CASCADE'
55
        );
56
57
        $this->addForeignKey(
58
            'fk_content_content_type1',
59
            'content',
60
            'type_id',
61
            'content_type',
62
            'id',
63
            'CASCADE',
64
            'CASCADE'
65
        );
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function down()
72
    {
73
        $this->dropTable('content');
74
    }
75
}
76