Completed
Pull Request — develop (#3570)
by Jonathan
155:39 queued 152:58
created

Driver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 8
eloc 17
dl 0
loc 41
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B connect() 0 36 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver\SQLSrv;
6
7
use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
8
use Doctrine\DBAL\Driver\Connection;
9
10
/**
11
 * Driver for ext/sqlsrv.
12
 */
13
class Driver extends AbstractSQLServerDriver
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 24
    public function connect(
19
        array $params,
20
        string $username = '',
21
        string $password = '',
22
        array $driverOptions = []
23
    ) : Connection {
24 24
        if (! isset($params['host'])) {
25
            throw new SQLSrvException('Missing "host" in configuration for sqlsrv driver.');
26
        }
27
28 24
        $serverName = $params['host'];
29 24
        if (isset($params['port'])) {
30 24
            $serverName .= ', ' . $params['port'];
31
        }
32
33 24
        if (isset($params['dbname'])) {
34 24
            $driverOptions['Database'] = $params['dbname'];
35
        }
36
37 24
        if (isset($params['charset'])) {
38
            $driverOptions['CharacterSet'] = $params['charset'];
39
        }
40
41 24
        if ($username !== '') {
42 24
            $driverOptions['UID'] = $username;
43
        }
44
45 24
        if ($password !== '') {
46 24
            $driverOptions['PWD'] = $password;
47
        }
48
49 24
        if (! isset($driverOptions['ReturnDatesAsStrings'])) {
50 24
            $driverOptions['ReturnDatesAsStrings'] = 1;
51
        }
52
53 24
        return new SQLSrvConnection($serverName, $driverOptions);
54
    }
55
}
56