m151220_112320_lang   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A safeUp() 0 30 2
A safeDown() 0 4 1
1
<?php
2
3
use yii\db\Migration;
4
use lav45\translate\LocaleHelperTrait;
5
6
class m151220_112320_lang extends Migration
7
{
8
    use LocaleHelperTrait;
9
10
    public function safeUp()
11
    {
12
        $tableOptions = null;
13
        if ($this->db->driverName === 'mysql') {
14
            // https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
15
            // https://stackoverflow.com/questions/30074492/what-is-the-difference-between-utf8mb4-and-utf8-charsets-in-mysql/30074553#30074553
16
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
17
        }
18
19
        $this->createTable('{{%lang}}', [
20
            'id' => $this->string(2)->notNull(),
21
            'locale' => $this->string(8)->notNull(),
22
            'name' => $this->string(32)->notNull(),
23
            'status' => $this->smallInteger(),
24
            'PRIMARY KEY (id)',
25
        ], $tableOptions);
26
27
        $this->createIndex('lang_name_idx', '{{%lang}}', 'name', true);
28
        $this->createIndex('lang_status_idx', '{{%lang}}', 'status');
29
30
        $source_language = Yii::$app->sourceLanguage;
31
        $source_language_id = $this->getPrimaryLanguage($source_language);
32
33
        $this->insert('{{%lang}}', [
34
            'id' => strtolower($source_language_id),
35
            'locale' => $source_language,
36
            'name' => strtoupper($source_language_id),
37
            'status' => 10,
38
        ]);
39
    }
40
41
    public function safeDown()
42
    {
43
        $this->dropTable('{{%lang}}');
44
    }
45
}
46