m210101_000000_create_user_table   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 40
c 1
b 0
f 0
dl 0
loc 58
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 48 2
A safeDown() 0 4 1
1
<?php
2
3
use yii\db\Migration;
4
5
/**
6
 * phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
7
 * phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
8
 */
9
class m210101_000000_create_user_table extends Migration
10
{
11
    public function safeUp()
12
    {
13
        $this->createTable('{{user}}', [
14
            'id' => $this->primaryKey(),
15
            'username' => $this->string()->notNull(),
16
            'password_hash' => $this->string()->notNull(),
17
            'email_address' => $this->string()->notNull(),
18
            'latest_authenticated_at' => $this->integer(),
19
            'enabled' => $this->boolean()->notNull()->defaultValue(true),
20
            'created_at' => $this->integer()->notNull(),
21
            'updated_at' => $this->integer()->notNull(),
22
        ]);
23
24
        if ($this->db->getDriverName() === 'sqlite') {
25
26
            $this->createTable('{{user_identity_link}}', [
27
                'user_id' => $this->integer()->notNull(),
28
                'linked_user_id' => $this->integer()->notNull(),
29
                'PRIMARY KEY (user_id, linked_user_id)',
30
                'FOREIGN KEY (user_id) REFERENCES user(id)',
31
                'FOREIGN KEY (linked_user_id) REFERENCES user(id)',
32
            ]);
33
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
34
        } else {
35
36
            $this->createTable('{{user_identity_link}}', [
37
                'user_id' => $this->integer()->notNull(),
38
                'linked_user_id' => $this->integer()->notNull(),
39
                'PRIMARY KEY (user_id, linked_user_id)',
40
            ]);
41
42
            $this->addForeignKey(
43
                'linked_identity_user',
44
                '{{user_identity_link}}',
45
                'user_id',
46
                'user',
47
                'id',
48
                'CASCADE',
49
                'CASCADE',
50
            );
51
            $this->addForeignKey(
52
                'linked_identity_linked_user',
53
                '{{user_identity_link}}',
54
                'linked_user_id',
55
                'user',
56
                'id',
57
                'CASCADE',
58
                'CASCADE',
59
            );
60
        }
61
    }
62
63
    public function safeDown()
64
    {
65
        $this->dropTable('{{user_identity_link}}');
66
        $this->dropTable('{{user}}');
67
    }
68
}
69