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

ConnectorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 12 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 3
loc 25
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 3 15 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\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