m170605_145115_create_post_table   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 18 2
A down() 0 4 1
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * Handles the creation of table `post`.
7
 */
8
class m170605_145115_create_post_table extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    public function up()
14
    {
15
        $tableOptions = null;
16
        if ($this->db->driverName === 'mysql') {
17
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
18
        }
19
        $this->createTable('{{%post}}', [
20
            'id' => $this->primaryKey(),
21
            'title' => $this->string()->notNull()->comment('标题'),
22
            'img' => $this->string()->comment('图片'),
23
            'views' => $this->integer()->comment('访问量'),
24
            'order' => $this->smallInteger()->comment('序号'),
25
            'status' => $this->boolean()->defaultValue(1)->comment('状态'),
26
            'content' => $this->text()->comment('内容'),
27
            'created_at' => $this->integer()->comment('创建时间'),
28
            'updated_at' => $this->integer()->comment('更新时间'),
29
        ], $tableOptions);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function down()
36
    {
37
        $this->dropTable('{{%post}}');
38
    }
39
}
40