Passed
Push — master ( 87f444...2985b9 )
by Jonas
12:59
created

ConnectionFactory::createConnection()   B

Complexity

Conditions 9
Paths 8

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 9

Importance

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