DatabaseMySQL   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 10
c 2
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A configurePDOMySQL() 0 27 2
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