Completed
Push — master ( fc326d...94dab4 )
by Antonio
03:05 queued 12s
created

MigrationHelper::resolveTableOptions()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 15
cp 0
rs 8.8333
c 0
b 0
f 0
cc 7
nc 7
nop 1
crap 56
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
            case 'sqlite':
35
                return null;
36
            default:
37
                throw new RuntimeException('Your database is not supported!');
38
        }
39
    }
40
41
    /**
42
     * @param $driverName
43
     *
44
     * @throws RuntimeException
45
     * @return string
46
     *
47
     */
48
    public static function resolveDbType($driverName)
49
    {
50
        switch ($driverName) {
51
            case 'mysql':
52
            case 'pgsql':
53
            case 'sqlite':
54
                return $driverName;
55
            case 'dblib':
56
            case 'mssql':
57
            case 'sqlsrv':
58
                return 'sqlsrv';
59
            default:
60
                throw new RuntimeException('Your database is not supported!');
61
        }
62
    }
63
64
    /**
65
     * @param string $driverName
66
     *
67
     * @throws RuntimeException
68
     * @return bool
69
     *
70
     */
71
    public static function isMicrosoftSQLServer($driverName)
72
    {
73
        return self::resolveDbType($driverName) === 'sqlsrv';
74
    }
75
76
    /**
77
     * @param $driverName
78
     * @param bool $value
79
     *
80
     * @return bool|int
81
     */
82
    public static function getBooleanValue($driverName, $value = false)
83
    {
84
        if (self::isMicrosoftSQLServer($driverName)) {
85
            return $value ? 1 : 0;
86
        }
87
        return $value;
88
    }
89
}
90