Passed
Pull Request — master (#14)
by Wilmer
25:49 queued 10:47
created

SqlsrvPDO   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A lastInsertId() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\Pdo;
6
7
/**
8
 * This is an extension of the default PDO class of SQLSRV driver.
9
 * It provides workarounds for improperly implemented functionalities of the SQLSRV driver.
10
 */
11
final class SqlsrvPDO extends \PDO
12
{
13
    /**
14
     * Returns value of the last inserted ID.
15
     *
16
     * SQLSRV driver implements [[PDO::lastInsertId()]] method but with a single peculiarity:
17
     * when `$sequence` value is a null or an empty string it returns an empty string.
18
     * But when parameter is not specified it works as expected and returns actual
19
     * last inserted ID (like the other PDO drivers).
20
     * @param string|null $sequence the sequence name. Defaults to null.
21
     * @return int last inserted ID value.
22
     */
23
    public function lastInsertId($sequence = null)
24
    {
25
        return !$sequence ? parent::lastInsertId() : parent::lastInsertId($sequence);
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! $sequence ? par...lastInsertId($sequence) returns the type string which is incompatible with the documented return type integer.
Loading history...
26
    }
27
}
28