Completed
Pull Request — master (#325)
by
unknown
03:01
created

MigrationHelper   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 0
dl 0
loc 63
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B resolveTableOptions() 0 16 7
B resolveDbType() 0 17 7
A isMicrosoftSQLServer() 0 4 1
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
            case 'sqlite':
36
                return null;
37
            default:
38
                throw new RuntimeException('Your database is not supported!');
39
        }
40
    }
41
42
    /**
43
     * @param $driverName
44
     *
45
     * @throws RuntimeException
46
     * @return string
47
     *
48
     */
49
    public static function resolveDbType($driverName)
50
    {
51
        switch ($driverName) {
52
            case 'mysql':
53
                return $driverName;
54
            case 'pgsql':
55
                return $driverName;
56
            case 'dblib':
57
            case 'mssql':
58
            case 'sqlsrv':
59
                return 'sqlsrv';
60
            case 'sqlite':
61
                return $driverName;
62
            default:
63
                throw new RuntimeException('Your database is not supported!');
64
        }
65
    }
66
67
    /**
68
     * @param string $driverName
69
     *
70
     * @throws RuntimeException
71
     * @return bool
72
     *
73
     */
74
    public static function isMicrosoftSQLServer($driverName)
75
    {
76
        return self::resolveDbType($driverName) === 'sqlsrv';
77
    }
78
}
79