DatabaseMySQL::configurePDOMySQL()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
nc 2
nop 5
dl 0
loc 27
ccs 0
cts 11
cp 0
crap 6
rs 9.7
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate\Traits;
6
7
trait DatabaseMySQL
8
{
9
    private function configurePDOMySQL(
10
        $params,
11
        &$pdoDsn,
12
        &$pdoUsername,
13
        &$pdoPassword,
14
        &$pdoAttributes
15
    ) {
16
        $defaultParams = [
17
            'hostname' => null,
18
            'database' => null,
19
            'username' => null,
20
            'password' => null,
21
            'encoding' => null
22
        ];
23
24
        $params = array_merge($defaultParams, $params);
25
26
        $pdoDsn =
27
            'mysql:host=' .
28
            $params['hostname'] .
29
            ';dbname=' .
30
            $params['database'];
31
        $pdoUsername = $params['username'];
32
        $pdoPassword = $params['password'];
33
        if ($params['encoding'] != null) {
34
            $pdoAttributes[\PDO::MYSQL_ATTR_INIT_COMMAND] =
35
                "SET NAMES " . $params['encoding'];
36
        }
37
    }
38
}
39