DriverGuesser::getDBHelper()   A
last analyzed

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