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

Driver   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 10.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 18
dl 0
loc 47
ccs 2
cts 19
cp 0.1053
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
B connect() 0 32 8
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