m170707_070437_avatar_image   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 8 1
A safeDown() 0 6 1
1
<?php
2
3
use inblank\activeuser\migrations\Migration;
4
use yii\db\Schema;
5
6
class m170707_070437_avatar_image 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...
7
{
8
    public function safeUp()
9
    {
10
        // set default value for `avatar` field to NULL
11
        $tab = self::tn(self::TAB_USERS);
12
        $this->alterColumn($tab, 'avatar', Schema::TYPE_STRING . "(45) DEFAULT NULL");
13
        // replace all empty `avatar`
14
        $this->db->createCommand("update " . $tab . " set [[avatar]]=NULL where [[avatar]]=''")->execute();
15
    }
16
17
    public function safeDown()
18
    {
19
        $tab = self::tn(self::TAB_USERS);
20
        $this->db->createCommand("update " . $tab . " set [[avatar]]='' where [[avatar]] IS NULL")->execute();
21
        $this->alterColumn($tab, 'avatar', Schema::TYPE_STRING . "(45) NOT NULL DEFAULT ''");
22
    }
23
}
24