BuilderFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 7.89 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
dl 3
loc 38
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A validate() 3 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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