DatabaseSQLite::configurePDOSQLite()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 16
nc 3
nop 4
dl 0
loc 29
ccs 9
cts 11
cp 0.8182
crap 3.054
rs 9.7333
c 3
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate\Traits;
6
7
trait DatabaseSQLite
8
{
9 22
    private function configurePDOSQLite(
10
        $params,
11
        &$pdoDsn,
12
        &$pdoUsername,
13
        &$pdoPassword
14
    ) {
15
        $defaultParams = [
16 22
            'username' => null,
17
            'password' => null,
18
            'memory' => null,
19
            'file' => null
20
        ];
21
22 22
        $params = array_merge($defaultParams, $params);
23
24 22
        $pdoDsn = 'sqlite';
25
26 22
        if ($params['memory']) {
27
            $pdoDsn .= '::memory:';
28
        } else {
29 22
            if ($params['file'] !== null) {
30 22
                $pdoDsn .= ':' . $params['file'];
31
            } else {
32
                throw new \Exception("Missing SQLite file parameter");
33
            }
34
        }
35
36 22
        $pdoUsername = $params['username'];
37 22
        $pdoPassword = $params['password'];
38 22
    }
39
}
40