Completed
Push — master ( ec17fe...3fc7ad )
by Nate
13:17 queued 11:49
created

m191118_181324_user_state_column::safeUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organizations\migrations;
10
11
use craft\db\Migration;
12
use flipbox\organizations\Organizations;
13
use flipbox\organizations\records\UserAssociation;
14
15
/**
16
 * This migration alters the 'state' column to include the new 'invited' option.
17
 */
18
class m191118_181324_user_state_column extends Migration
19
{
20
    /**
21
     * @inheritdoc
22
     * @throws \yii\base\NotSupportedException
23
     */
24
    public function safeUp()
25
    {
26
        $table = $this->getDb()->getSchema()->getTableSchema(
0 ignored issues
show
Unused Code introduced by
$table 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...
27
            UserAssociation::tableName()
28
        );
29
30
        $states = array_keys(Organizations::getInstance()->getSettings()->getUserStates());
31
        $defaultState = Organizations::getInstance()->getSettings()->getDefaultUserState();
32
33
        $type = $this->enum(
34
            AlterUserStates::COLUMN_NAME,
35
            $states
36
        )->defaultValue($defaultState)->notNull();
37
38
        $this->alterColumn(
39
            UserAssociation::tableName(),
40
            AlterUserStates::COLUMN_NAME,
41
            $type
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function safeDown()
49
    {
50
        echo "m191118_1813249_user_state_column cannot be reverted.\n";
51
        return true;
52
    }
53
}
54