MySQLDriver::dsn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace SimplePDO\Drivers;
3
4
use SimplePDO\Configuration;
5
use SimplePDO\Drivers\DriverInterface;
6
7
class MySQLDriver implements DriverInterface
8
{
9
10
    /**
11
     * {@inheritdoc}
12
     */
13
    final public static function dsn(Configuration $configuration)
14
    {
15
        $dbname = $configuration->get('MYSQL', 'DBNAME');
16
        $host = $configuration->get('MYSQL', 'HOST');
17
        $port = $configuration->get('MYSQL', 'PORT');
18
        $charset = $configuration->get('MYSQL', 'CHARSET');
19
        $socket = $configuration->get('MYSQL', 'SOCKET');
20
        
21
        if (!empty($socket))
22
        {
23
            return "mysql:dbname={$dbname};unix_socket{$socket};charset={$charset}";
24
        }
25
        return "mysql:dbname={$dbname};host={$host};port={$port};charset={$charset}";
26
    }
27
28
}
29