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

ConnectorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 25
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 3
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 1
            return $connector;
29
        }
30
31
        throw new InvalidArgumentException("Unrecognised driver");
32
    }
33
}
34