DatabaseConnectionStringFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 0
cbo 1
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createDatabaseSourceString() 0 24 6
1
<?php
2
3
namespace Pyjac\ORM;
4
5
use Pyjac\ORM\Exception\DatabaseDriverNotSupportedException;
6
7
class DatabaseConnectionStringFactory implements DatabaseConnectionStringFactoryInterface
8
{
9
    /**
10
     * Create a connection string.
11
     *
12
     * @param array $config
13
     *
14
     * @throws Pyjac\PotatoORM\Exception\DatabaseDriverNotSupportedException
15
     *
16
     * @return string
17
     */
18
    public function createDatabaseSourceString($config)
19
    {
20
        $driver = $config['DRIVER'];
21
22
        switch ($driver) {
23
            case 'sqlite':
24
                $dsn = $driver.'::memory:';
25
                break;
26
            case 'mysql':
27
            case 'postgres':
28
                if (strcasecmp($driver, 'postgres') == 0) {
29
                    $driver = 'pgsql';
30
                }
31
                $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME'];
32
                if (isset($config['PORT'])) {
33
                    $dsn .= ';port='.$config['PORT'];
34
                }
35
                break;
36
            default:
37
                throw new DatabaseDriverNotSupportedException();
38
        }
39
40
        return $dsn;
41
    }
42
}
43