Completed
Branch develop (32cfca)
by Oyebanji Jacob
03:26
created

createDatabaseSourceString()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 20
Code Lines 15

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
rs 8.8571
cc 6
eloc 15
nc 10
nop 1
1
<?php 
2
3
namespace Pyjac\ORM;
4
5 View Code Duplication
class DatabaseConnectionStringFactory implements DatabaseConnectionStringFactoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
6
{
7
    /**
8
     * Create a connection string 
9
     * 
10
     * @param  array $config
11
     * @throws Pyjac\PotatoORM\Exception\DatabaseDriverNotSupportedException
12
     * @return string 
13
     */
14
    public function createDatabaseSourceString($config)
15
    {
16
17
        $driver = $config['DRIVER'];
18
19
        switch ($driver) {
20
            case 'sqlite':
21
                $dsn = $driver.'::memory:';
22
                break;
23
            case 'mysql':
24
            case 'postgres':
25
                if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql";
26
                $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME'];
27
                if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT'];
28
                break;
29
            default:
30
                throw new DatabaseDriverNotSupportedException;
31
        }
32
        return $dsn;
33
    }
34
}