Completed
Push — master ( 755d2f...4eddf0 )
by Christopher
05:22
created

ConnectorFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 0
cts 12
cp 0
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
crap 12
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use AsyncPHP\Icicle\Database\Connector\MySQLConnector;
6
use InvalidArgumentException;
7
8
final class ConnectorFactory
9
{
10
    /**
11
     * @param array $config
12
     *
13
     * @return Connector
14
     *
15
     * @throw InvalidArgumentException
16
     */
17
    public function create(array $config)
18
    {
19
        if (!isset($config["driver"])) {
20
            throw new InvalidArgumentException("Undefined driver");
21
        }
22
23
        if ($config["driver"] === "mysql") {
24
            $connector = new MySQLConnector();
25
            $connector->connect($config);
26
27
            return $connector;
28
        }
29
30
        throw new InvalidArgumentException("Unrecognised driver");
31
    }
32
}
33