Passed
Pull Request — master (#19612)
by Fedonyuk
08:17
created

m160313_153426_session_init   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 78.26%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 41
ccs 18
cts 23
cp 0.7826
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 3 1
B up() 0 28 6
1
<?php
2
/**
3
 * @link https://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license https://www.yiiframework.com/license/
6
 */
7
8
use yii\db\Migration;
9
10
/**
11
 * Initializes Session tables.
12
 *
13
 * @author Misbahul D Munir <[email protected]>
14
 * @since 2.0.8
15
 */
16
class m160313_153426_session_init extends Migration
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 30
    public function up()
22
    {
23 30
        $dataType = $this->binary();
24 30
        $tableOptions = null;
25
26 30
        switch ($this->db->driverName) {
27 30
            case 'mysql':
28
                // https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
29 10
                $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
30 10
                break;
31 20
            case 'sqlsrv':
32 20
            case 'mssql':
33 20
            case 'dblib':
34
                $version = $this->db->createCommand("SELECT SERVERPROPERTY('productversion')")->queryScalar();
35
                $version = explode('.', $version, 2);
0 ignored issues
show
Bug introduced by
It seems like $version can also be of type false and null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
                $version = explode('.', /** @scrutinizer ignore-type */ $version, 2);
Loading history...
36
                // "varbinary(max)" added in SQL Server 2012 (version 11.*)
37
                if ($version < 11) {
38
                    $dataType = $this->text();
39
                }
40
                break;
41
        }
42
43 30
        $this->createTable('{{%session}}', [
44 30
            'id' => $this->string()->notNull(),
45 30
            'expire' => $this->integer(),
46 30
            'data' => $dataType,
47 30
            'PRIMARY KEY ([[id]])',
48
        ], $tableOptions);
49 30
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 30
    public function down()
55
    {
56 30
        $this->dropTable('{{%session}}');
57 30
    }
58
}
59