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

DatabaseSQLite::configurePDOSQLite()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 3
nop 4
dl 0
loc 25
ccs 9
cts 11
cp 0.8182
crap 3.054
rs 9.7333
c 0
b 0
f 0
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
}