Completed
Push — master ( 59df9b...8cdd26 )
by Christopher
03:30
created

BuilderFactory::create()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 32
ccs 0
cts 20
cp 0
rs 8.439
cc 6
eloc 16
nc 6
nop 1
crap 42
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use AsyncPHP\Icicle\Database\Builder\AuraBuilder;
6
use Aura\SqlQuery\QueryFactory;
7
use InvalidArgumentException;
8
9
final class BuilderFactory
10
{
11
    /**
12
     * @param array $config
13
     *
14
     * @return Builder
15
     *
16
     * @throw InvalidArgumentException
17
     */
18
    public function create(array $config)
19
    {
20
        if (!isset($config["driver"])) {
21
            throw new InvalidArgumentException("Undefined driver");
22
        }
23
24
        if ($config["driver"] === "mssql") {
25
            return new AuraBuilder(
26
                new QueryFactory("sqlsrv")
27
            );
28
        }
29
30
        if ($config["driver"] === "mysql") {
31
            return new AuraBuilder(
32
                new QueryFactory("mysql")
33
            );
34
        }
35
36
        if ($config["driver"] === "postgresql") {
37
            return new AuraBuilder(
38
                new QueryFactory("pgsql")
39
            );
40
        }
41
42
        if ($config["driver"] === "sqlite") {
43
            return new AuraBuilder(
44
                new QueryFactory("sqlite")
45
            );
46
        }
47
48
        throw new InvalidArgumentException("Unrecognised driver");
49
    }
50
}
51