Failed Conditions
Pull Request — 2.10 (#3762)
by Benjamin
09:16
created

Driver::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Doctrine\DBAL\Driver\SQLSrv;
4
5
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
6
7
/**
8
 * Driver for ext/sqlsrv.
9
 */
10
class Driver extends AbstractSQLServerDriver
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
16
    {
17
        if (! isset($params['host'])) {
18
            throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
19
        }
20
21
        $serverName = $params['host'];
22
        if (isset($params['port'])) {
23
            $serverName .= ', ' . $params['port'];
24
        }
25
26
        if (isset($params['dbname'])) {
27
            $driverOptions['Database'] = $params['dbname'];
28
        }
29
30
        if (isset($params['charset'])) {
31
            $driverOptions['CharacterSet'] = $params['charset'];
32
        }
33
34
        if ($username !== null) {
35
            $driverOptions['UID'] = $username;
36
        }
37
38
        if ($password !== null) {
39
            $driverOptions['PWD'] = $password;
40
        }
41
42
        if (! isset($driverOptions['ReturnDatesAsStrings'])) {
43
            $driverOptions['ReturnDatesAsStrings'] = 1;
44
        }
45
46
        return new SQLSrvConnection($serverName, $driverOptions);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @deprecated
53
     */
54 29
    public function getName()
55
    {
56 29
        return 'sqlsrv';
57
    }
58
}
59