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

ConnectorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 25
wmc 3
lcom 0
cbo 1
ccs 0
cts 12
cp 0
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\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