Failed Conditions
Pull Request — develop (#3368)
by Benjamin
42:38 queued 39:25
created

Connection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 40
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createStatement() 0 3 1
A quote() 0 10 2
A getSequenceNumber() 0 12 2
1
<?php
2
3
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
4
5
use Doctrine\DBAL\Driver\DriverException;
6
use Doctrine\DBAL\Driver\PDOConnection;
7
use Doctrine\DBAL\Driver\PDOStatement;
8
use function strpos;
9
use function substr;
10
11
/**
12
 * Sqlsrv Connection implementation.
13
 */
14
class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19 2
    public function getSequenceNumber(string $name) : string
20
    {
21 2
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
22 2
        $stmt->execute([$name]);
23
24 2
        $result = $stmt->fetchColumn();
25
26 2
        if ($result === false) {
27 1
            throw DriverException::noSuchSequence($name);
28
        }
29
30 1
        return (string) $result;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 7
    public function quote(string $value) : string
37
    {
38 7
        $val = parent::quote($value);
39
40
        // Fix for a driver version terminating all values with null byte
41 7
        if (strpos($val, "\0") !== false) {
42
            $val = substr($val, 0, -1);
43
        }
44
45 7
        return $val;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 246
    protected function createStatement(\PDOStatement $stmt) : PDOStatement
52
    {
53 246
        return new Statement($stmt);
54
    }
55
}
56