Completed
Pull Request — master (#322)
by Antonio
03:54
created

MigrationHelper::getBooleanValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
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
        if(self::isMicrosoftSQLServer($driverName)) {
78
            return $value? 1: 0; 
79
        }
80
        return $value;
81
    }
82
}
83