Passed
Pull Request — master (#48)
by Jonas
07:38
created

ConnectionFactory::createConnection()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 8.4444
c 1
b 0
f 0
cc 8
nc 7
nop 5
crap 8
1
<?php
2
3
namespace Staudenmeir\LaravelCte\Connectors;
4
5
use Illuminate\Database\Connection;
6
use Illuminate\Database\Connectors\ConnectionFactory as Base;
7
use InvalidArgumentException;
8
use Staudenmeir\LaravelCte\Connections\MySqlConnection;
9
use Staudenmeir\LaravelCte\Connections\PostgresConnection;
10
use Staudenmeir\LaravelCte\Connections\SQLiteConnection;
11
use Staudenmeir\LaravelCte\Connections\SingleStoreConnection;
12
use Staudenmeir\LaravelCte\Connections\SqlServerConnection;
13
14
class ConnectionFactory extends Base
15
{
16
    /**
17
     * Create a new connection instance.
18
     *
19
     * @param string $driver
20
     * @param \PDO|\Closure $connection
21
     * @param string $database
22
     * @param string $prefix
23
     * @param array $config
24
     * @return \Illuminate\Database\Connection
25
     *
26
     * @throws \InvalidArgumentException
27 132
     */
28
    protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
29 132
    {
30
        if ($driver != 'singlestore' && $resolver = Connection::getResolver($driver)) {
31
            return $resolver($connection, $database, $prefix, $config); // @codeCoverageIgnore
32
        }
33
34 132
        switch ($driver) {
35 49
            case 'mysql':
36 83
                return new MySqlConnection($connection, $database, $prefix, $config);
37 31
            case 'pgsql':
38 52
                return new PostgresConnection($connection, $database, $prefix, $config);
39 27
            case 'sqlite':
40 25
                return new SQLiteConnection($connection, $database, $prefix, $config);
41 25
            case 'sqlsrv':
42
                return new SqlServerConnection($connection, $database, $prefix, $config);
43
            case 'singlestore':
44
                return new SingleStoreConnection($connection, $database, $prefix, $config);
45
        }
46
47
        throw new InvalidArgumentException("Unsupported driver [{$driver}]"); // @codeCoverageIgnore
48
    }
49
}
50