Failed Conditions
Pull Request — 3.0.x (#3980)
by Guilherme
07:55
created

DB2Driver::connect()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 9.4888
c 0
b 0
f 0
cc 5
nc 6
nop 4
crap 30
1
<?php
2
3
namespace Doctrine\DBAL\Driver\IBMDB2;
4
5
use Doctrine\DBAL\Driver\AbstractDB2Driver;
6
7
/**
8
 * IBM DB2 Driver.
9
 */
10
class DB2Driver extends AbstractDB2Driver
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
16
    {
17
        if (! isset($params['protocol'])) {
18
            $params['protocol'] = 'TCPIP';
19
        }
20
21
        if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') {
22
            // if the host isn't localhost, use extended connection params
23
            $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
24
                     ';DATABASE=' . $params['dbname'] .
25
                     ';HOSTNAME=' . $params['host'] .
26
                     ';PROTOCOL=' . $params['protocol'] .
27
                     ';UID=' . $username .
28
                     ';PWD=' . $password . ';';
29
            if (isset($params['port'])) {
30
                $params['dbname'] .= 'PORT=' . $params['port'];
31
            }
32
33
            $username = null;
34
            $password = null;
35
        }
36
37
        return new DB2Connection($params, (string) $username, (string) $password, $driverOptions);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     *
43
     * @deprecated
44
     */
45 22
    public function getName()
46
    {
47 22
        return 'ibm_db2';
48
    }
49
}
50