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

ManagerFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0068

Importance

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