Completed
Push — master ( e52675...7b311f )
by Antonio
04:57 queued 03:26
created

MigrationHelper   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 0
dl 0
loc 67
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveTableOptions() 0 14 6
A resolveDbType() 0 15 6
A isMicrosoftSQLServer() 0 4 1
A getBooleanValue() 0 7 3
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