Completed
Pull Request — master (#322)
by
unknown
03:17
created

MigrationHelper::getBooleanValue()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.5222
c 0
b 0
f 0
cc 5
nc 5
nop 2
crap 30
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Helper;
13
14
use RuntimeException;
15
16
class MigrationHelper
17
{
18
    /**
19
     * @param string $driverName
20
     *
21
     * @throws RuntimeException
22
     * @return null|string
23
     *
24
     */
25
    public static function resolveTableOptions($driverName)
26
    {
27
        switch ($driverName) {
28
            case 'mysql':
29
                return 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
30
            case 'pgsql':
31
            case 'dblib':
32
            case 'mssql':
33
            case 'sqlsrv':
34
                return null;
35
            default:
36
                throw new RuntimeException('Your database is not supported!');
37
        }
38
    }
39
40
    /**
41
     * @param $driverName
42
     *
43
     * @throws RuntimeException
44
     * @return string
45
     *
46
     */
47
    public static function resolveDbType($driverName)
48
    {
49
        switch ($driverName) {
50
            case 'mysql':
51
                return $driverName;
52
            case 'pgsql':
53
                return $driverName;
54
            case 'dblib':
55
            case 'mssql':
56
            case 'sqlsrv':
57
                return 'sqlsrv';
58
            default:
59
                throw new RuntimeException('Your database is not supported!');
60
        }
61
    }
62
63
    /**
64
     * @param string $driverName
65
     *
66
     * @throws RuntimeException
67
     * @return bool
68
     *
69
     */
70
    public static function isMicrosoftSQLServer($driverName)
71
    {
72
        return self::resolveDbType($driverName) === 'sqlsrv';
73
    }
74
75
    public static function getBooleanValue($driverName,$value=false)
76
    {
77
	switch (self::resolveDbType($driverName)) {
78
            case 'sqlsrv':
79
                return $value?1:0;
80
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
81
            case 'pgsql':
82
                return $value?true:false;
83
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
84
            default:
85
              return $value;
86
        }
87
    }
88
}
89