BuilderFactory::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 3
Ratio 25 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
dl 3
loc 12
c 0
b 0
f 0
ccs 4
cts 6
cp 0.6667
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3.3332
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use AsyncPHP\Icicle\Database\Builder\AuraBuilder;
6
use Aura\SqlQuery\QueryFactory;
7
use InvalidArgumentException;
8
9
final class BuilderFactory
10
{
11
    /**
12
     * @param array $config
13
     *
14
     * @return Builder
15
     *
16
     * @throws InvalidArgumentException
17
     */
18 2
    public function create(array $config)
19
    {
20 2
        $config = $this->validate($config);
21
22 2
        return new AuraBuilder(
23 2
            new QueryFactory($config["driver"])
24 2
        );
25
    }
26
27
    /**
28
     * @param array $config
29
     *
30
     * @return array
31
     *
32
     * @throws InvalidArgumentException
33
     */
34 2
    private function validate(array $config)
35
    {
36 2
        if (!isset($config["driver"])) {
37
            throw new InvalidArgumentException("Undefined driver");
38
        }
39
40 2 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...
41
            throw new InvalidArgumentException("Unrecognised driver");
42
        }
43
44 2
        return $config;
45
    }
46
}
47