DatabaseSQLite   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A configurePDOSQLite() 0 29 3
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