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

ConnectorFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.4746

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 5
cts 8
cp 0.625
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
crap 3.4746
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use AsyncPHP\Icicle\Database\Connector\DoormanConnector;
6
use AsyncPHP\Icicle\Database\Connector\MySQLConnector;
7
use InvalidArgumentException;
8
9
final class ConnectorFactory
10
{
11
    /**
12
     * @param array $config
13
     *
14
     * @return Connector
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"] === "mysql") {
25 1
            $connector = new DoormanConnector();
26 1
            $connector->connect($config);
27
28
            return $connector;
29
        }
30
31
        throw new InvalidArgumentException("Unrecognised driver");
32
    }
33
}
34