Completed
Push — master ( 365f54...bdc15b )
by Christopher
10:19 queued 08:11
created

BuilderFactory::create()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 15.8865

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 32
ccs 7
cts 20
cp 0.35
rs 8.439
cc 6
eloc 16
nc 6
nop 1
crap 15.8865
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 1
    public function create(array $config)
19
    {
20 1
        if (!isset($config["driver"])) {
21
            throw new InvalidArgumentException("Undefined driver");
22
        }
23
24 1
        if ($config["driver"] === "mssql") {
25
            return new AuraBuilder(
26
                new QueryFactory("sqlsrv")
27
            );
28
        }
29
30 1
        if ($config["driver"] === "mysql") {
31 1
            return new AuraBuilder(
32 1
                new QueryFactory("mysql")
33 1
            );
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