AlterUserStates   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 16 1
A safeDown() 0 4 1
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
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class AlterUserStates extends Migration
20
{
21
    /**
22
     * The state column name
23
     */
24
    const COLUMN_NAME = 'state';
25
26
    /**
27
     * @inheritdoc
28
     * @throws \Throwable
29
     */
30
    public function safeUp()
31
    {
32
        $states = array_keys(Organizations::getInstance()->getSettings()->getUserStates());
33
        $defaultState = Organizations::getInstance()->getSettings()->getDefaultUserState();
34
35
        $type = $this->enum(
36
            self::COLUMN_NAME,
37
            $states
38
        )->defaultValue($defaultState)->notNull();
39
40
        $this->alterColumn(
41
            UserAssociation::tableName(),
42
            self::COLUMN_NAME,
43
            $type
44
        );
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function safeDown()
51
    {
52
        return false;
53
    }
54
}
55