Failed Conditions
Pull Request — master (#4007)
by Sergei
63:09
created

Connection::quote()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.3149
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver\PDOSqlsrv;
6
7
use Doctrine\DBAL\Driver\PDOConnection;
8
use Doctrine\DBAL\Driver\PDOStatement;
9
use function strpos;
10
use function substr;
11
12
/**
13
 * Sqlsrv Connection implementation.
14
 */
15
class Connection extends PDOConnection
16
{
17 3
    public function lastInsertId(?string $name = null) : string
18
    {
19 3
        if ($name === null) {
20 2
            return parent::lastInsertId($name);
21
        }
22
23 1
        $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?');
24 1
        $stmt->execute([$name]);
25
26 1
        return $stmt->fetchColumn();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $stmt->fetchColumn() could return the type false which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
27
    }
28
29 5
    public function quote(string $input) : string
30
    {
31 5
        $val = parent::quote($input);
32
33
        // Fix for a driver version terminating all values with null byte
34 5
        if (strpos($val, "\0") !== false) {
35
            $val = substr($val, 0, -1);
36
        }
37
38 5
        return $val;
39
    }
40
41 321
    protected function createStatement(\PDOStatement $stmt) : PDOStatement
42
    {
43 321
        return new Statement($stmt);
44
    }
45
}
46