Completed
Push — master ( 0ef884...67a9c4 )
by Christopher
02:54
created

ConnectionFactory::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
crap 12
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use AsyncPHP\Icicle\Database\Connection\MySQLConnection;
6
use InvalidArgumentException;
7
8
final class ConnectionFactory
9
{
10
    /**
11
     * @param array $config
12
     *
13
     * @return Connection
14
     *
15
     * @throw InvalidArgumentException
16
     */
17
    public function create(array $config)
18
    {
19
        if (!isset($config["driver"])) {
20
            throw new InvalidArgumentException("Undefined connection driver");
21
        }
22
23
        if ($config["driver"] === "mysql") {
24
            return new MySQLConnection($config);
0 ignored issues
show
Unused Code introduced by
The call to MySQLConnection::__construct() has too many arguments starting with $config.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
        }
26
27
        throw new InvalidArgumentException("Unrecognised connection driver");
28
    }
29
}
30