Passed
Push — master ( 9b125d...f5b0c0 )
by Alexander
11:25 queued 07:35
created

SqlsrvPDO::lastInsertId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
/**
8
 * This is an extension of the default PDO class of SQLSERVER driver. It provides workarounds for improperly implemented
9
 * functionalities of the SQLSERVER driver.
10
 */
11
final class SqlsrvPDO extends \PDO
12
{
13
    /**
14
     * Returns value of the last inserted ID.
15
     *
16
     * SQLSERVER driver implements {@see PDO::lastInsertId()} method but with a single peculiarity:
17
     *
18
     * When `$sequence` value is a null or an empty string it returns an empty string.
19
     * But when parameter is not specified it works as expected and returns actual
20
     * last inserted ID (like the other PDO drivers).
21
     *
22
     * @param string|null $name the sequence name. Defaults to null.
23
     *
24
     * @return string last inserted ID value.
25
     */
26
    public function lastInsertId(string $name = null): string
27
    {
28
        return !$name ? parent::lastInsertId() : parent::lastInsertId($name);
29
    }
30
}
31