Completed
Pull Request — master (#2)
by Mathieu
05:06 queued 01:16
created

DatabaseSQLite   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 27
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A configurePDOSQLite() 0 25 3
1
<?php declare(strict_types=1);
2
namespace Suricate\Traits;
3
4
trait DatabaseSQLite
5
{
6 22
    private function configurePDOSQLite($params, &$pdoDsn, &$pdoUsername, &$pdoPassword)
7
    {
8
        $defaultParams = [
9 22
            'username'  => null,
10
            'password'  => null,
11
            'memory'    => null,
12
            'file'      => null,
13
        ];
14
15 22
        $params = array_merge($defaultParams, $params);
16
        
17 22
        $pdoDsn         = 'sqlite';
18
19 22
        if ($params['memory']) {
20
            $pdoDsn .= '::memory:';
21
        } else {
22 22
            if ($params['file'] !== null) {
23 22
                $pdoDsn .= ':' . $params['file'];
24
            } else {
25
                throw new \Exception("Missing SQLite file parameter");
26
            }
27
        }
28
29 22
        $pdoUsername    = $params['username'];
30 22
        $pdoPassword    = $params['password'];
31
    }
32
}