Passed
Push — master ( 3ccc44...cef086 )
by Emmanuel
02:16 queued 15s
created

DriverGuesser::getDBHelper()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 5
cts 5
cp 1
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @copyright 2018 Emmanuel Dyan
9
 *
10
 * @package edyan/neuralyzer
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link https://github.com/edyan/neuralyzer
15
 */
16
17
namespace Edyan\Neuralyzer\Helper\DB;
18
19
/**
20
 * Help to find the right DB Type from a driver
21
 */
22
class DriverGuesser
23
{
24
    /**
25
     * Find the right local driver from a php extension
26
     * @param  string $driver
27
     * @return mixed
28
     */
29 50
    public static function getDBHelper(string $driver)
30
    {
31
        $drivers = [
32 50
            'pdo_mysql'  => MySQL::class,
33
            'mysql'      => MySQL::class,
34
            'mysql2'     => MySQL::class,
35
36
            'pdo_pgsql'  => PostgreSQL::class,
37
            'pgsql'      => PostgreSQL::class,
38
            'postgres'   => PostgreSQL::class,
39
            'postgresql' => PostgreSQL::class,
40
41
            'pdo_sqlsrv' => SQLServer::class,
42
            'mssql'      => SQLServer::class,
43
        ];
44
45 50
        if (!array_key_exists($driver, $drivers)) {
46 2
            throw new \InvalidArgumentException("$driver unknown");
47
        }
48
49 48
        return $drivers[$driver];
50
    }
51
}
52