Code Duplication    Length = 30-30 lines in 2 locations

potatoTest.php 1 location

@@ 378-407 (lines=30) @@
375
    static function destroy($id);
376
}
377
378
class DatabaseConnectionStringFactory implements DatabaseConnectionStringFactoryInterface
379
{
380
    /**
381
     * Create a connection string 
382
     * 
383
     * @param  array $config
384
     * @throws Pyjac\PotatoORM\Exception\DatabaseDriverNotSupportedException
385
     * @return string 
386
     */
387
    public function createDatabaseSourceString($config)
388
    {
389
390
        $driver = $config['DRIVER'];
391
392
        switch ($driver) {
393
            case 'sqlite':
394
                $dsn = $driver.'::memory:';
395
                break;
396
            case 'mysql':
397
            case 'postgres':
398
                if(strcasecmp($driver, 'postgres') == 0) $driver="pgsql";
399
                $dsn = $driver.':host='.$config['HOSTNAME'].';dbname='.$config['DBNAME'];
400
                if(isset($config['PORT'])) $dsn .= ';port='.$config['PORT'];
401
                break;
402
            default:
403
                throw new DatabaseDriverNotSupportedException;
404
        }
405
        return $dsn;
406
    }
407
}
408
409
interface DatabaseConnectionStringFactoryInterface 
410
{

src/DatabaseConnectionStringFactory.php 1 location

@@ 5-34 (lines=30) @@
2
3
namespace Pyjac\ORM;
4
5
class DatabaseConnectionStringFactory implements DatabaseConnectionStringFactoryInterface
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
}