Completed
Pull Request — development (#560)
by Thomas
06:46
created

DbalConnection::__construct()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 32
nop 0
dl 0
loc 30
rs 8.439
c 0
b 0
f 0
1
<?php
2
/***************************************************************************
3
 * For license information see LICENSE.md
4
 * small helper class to get a dbal connection or dbal query builder
5
 * to refactor sql methods
6
 ***************************************************************************/
7
8
namespace Oc\Util;
9
10
use Doctrine\DBAL\DriverManager;
11
12
class DbalConnection
13
{
14
    public static function createDbalConnection(
15
        $host,
16
        $name,
17
        $user,
18
        $password,
19
        $port = null
20
    ) {
21
        $params = [];
22
        $params['driver'] = 'pdo_mysql';
23
24
        if ($host) {
25
            $params['host'] = $host;
26
        }
27
28
        if ($name) {
29
            $params['dbname'] = $name;
30
        }
31
32
        if ($user) {
33
            $params['user'] = $user;
34
        }
35
36
        if ($password) {
37
            $params['password'] = $password;
38
        }
39
40
        if ($port) {
41
            $params['port'] = $port;
42
        }
43
44
        return DriverManager::getConnection($params);
45
    }
46
}
47