M170307150614CreatePasswordHistoryTable::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 *   _   __ __ _____ _____ ___  ____  _____
5
 *  | | / // // ___//_  _//   ||  __||_   _|
6
 *  | |/ // /(__  )  / / / /| || |     | |
7
 *  |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\user\migrations;
14
15
use rhosocial\user\User;
16
use rhosocial\user\security\PasswordHistory;
17
18
/**
19
 * Create Password History Table.
20
 *
21
 * This migration is equivalent to:
22
```SQL
23
CREATE TABLE `password_history` (
24
    `guid` varbinary(16) NOT NULL COMMENT 'Password GUID',
25
    `user_guid` varbinary(16) NOT NULL COMMENT 'Created By',
26
    `created_at` datetime NOT NULL COMMENT 'Created At',
27
    `pass_hash` varchar(80) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Password Hash',
28
    PRIMARY KEY (`guid`),
29
    KEY `user_password_fk` (`user_guid`),
30
    KEY `user_password_created_at_normal` (`created_at`) USING BTREE,
31
    CONSTRAINT `user_password_fk` FOREIGN KEY (`user_guid`) REFERENCES `user` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE
32
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Password History';
33
```
34
 *
35
 * If you want to go back, please execute `yii migrate/to rhosocial\user\migrations\M170307150614CreatePasswordHistoryTable`,
36
 * instead of droping password history table yourself.
37
 * Note: this execution will reverse all the migrations after this migration.
38
 *
39
 * @version 1.0
40
 * @author vistart <[email protected]>
41
 */
42
class M170307150614CreatePasswordHistoryTable extends Migration
43
{
44
    public function up()
45
    {
46
        $tableOptions = null;
0 ignored issues
show
Unused Code introduced by
$tableOptions is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
        if ($this->getDb()->driverName == 'mysql') {
48
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
49
            $tableOptions = "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Password History'";
50
            $this->createTable(PasswordHistory::tableName(), [
51
                'guid' => $this->varbinary(16)->notNull()->comment('Password GUID'),
52
                'user_guid' => $this->varbinary(16)->notNull()->comment('Created By'),
53
                'created_at' => $this->dateTime()->notNull()->comment('Created At'),
54
                'pass_hash' => $this->varchar(80)->notNull()->comment('Password Hash'),
55
            ], $tableOptions);
56
        }
57
        $this->addPrimaryKey('password_guid_pk', PasswordHistory::tableName(), 'guid');
58
        $this->addForeignKey('user_password_fk', PasswordHistory::tableName(), 'user_guid', User::tableName(), 'guid', 'CASCADE', 'CASCADE');
59
        $this->createIndex('user_password_created_at_normal', PasswordHistory::tableName(), 'created_at');
60
    }
61
62
    public function down()
63
    {
64
        $this->dropTable(PasswordHistory::tableName());
65
    }
66
67
    /*
68
    // Use safeUp/safeDown to run migration code within a transaction
69
    public function safeUp()
70
    {
71
    }
72
73
    public function safeDown()
74
    {
75
    }
76
    */
77
}
78