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

DatabaseMySQL   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 19
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A configurePDOMySQL() 0 17 2
1
<?php declare(strict_types=1);
2
namespace Suricate\Traits;
3
4
trait DatabaseMySQL
5
{
6
    private function configurePDOMySQL($params, &$pdoDsn, &$pdoUsername, &$pdoPassword, &$pdoAttributes)
7
    {
8
        $defaultParams = [
9
            'hostname' => null,
10
            'database' => null,
11
            'username' => null,
12
            'password' => null,
13
            'encoding' => null
14
        ];
15
16
        $params = array_merge($defaultParams, $params);
17
18
        $pdoDsn         = 'mysql:host=' . $params['hostname'] . ';dbname=' . $params['database'];
19
        $pdoUsername    = $params['username'];
20
        $pdoPassword    = $params['password'];
21
        if ($params['encoding'] != null) {
22
            $pdoAttributes[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $params['encoding'];
23
        }
24
    }
25
}