Passed
Push — master ( a4f7f2...d3cc39 )
by Melech
04:09
created

PgsqlManager::lastInsertId()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 14
rs 10
cc 4
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Orm;
15
16
use Valkyrja\Orm\Exception\RuntimeException;
17
18
use function is_string;
19
20
/**
21
 * Class PgsqlManager.
22
 *
23
 * @author Melech Mizrachi
24
 */
25
class PgsqlManager extends PdoManager
26
{
27
    /**
28
     * @inheritDoc
29
     */
30
    public function lastInsertId(string|null $table = null, string|null $idField = null): string
31
    {
32
        $name = null;
33
34
        if ($table !== null && $idField !== null) {
35
            $name = "{$table}_{$idField}_seq";
36
        }
37
38
        /** @var non-empty-string|false $lastInsertId */
39
        $lastInsertId = $this->pdo->lastInsertId($name);
40
41
        return is_string($lastInsertId)
0 ignored issues
show
introduced by
The condition is_string($lastInsertId) is always true.
Loading history...
42
            ? $lastInsertId
43
            : throw new RuntimeException('No last insert id found');
44
    }
45
}
46