Completed
Push — master ( c64d25...ac7c6c )
by Christopher
19:43 queued 17:08
created

ConnectorFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 3
Ratio 20 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 3
loc 15
ccs 6
cts 8
cp 0.75
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
crap 3.1406
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
     * @throws 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 View Code Duplication
        if (!in_array($config["driver"], ["sqlsrv", "mysql", "pgsql", "sqlite"])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
            throw new InvalidArgumentException("Unrecognised driver");
26
        }
27
28 1
        $connector = new DoormanConnector();
29 1
        $connector->connect($config);
30
31 1
        return $connector;
32
    }
33
}
34