Passed
Branch master (914fa2)
by Wilmer
15:13 queued 11:13
created

CommandPDO::insertWithReturningPks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql;
6
7
use Exception;
8
use Throwable;
9
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO;
10
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
11
use Yiisoft\Db\Exception\ConvertException;
12
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
13
14
final class CommandPDO extends AbstractCommandPDO
15
{
16 265
    public function queryBuilder(): QueryBuilderInterface
17
    {
18 265
        return $this->db->getQueryBuilder();
19
    }
20
21
    /**
22
     * @psalm-suppress UnusedClosureParam
23
     *
24
     * @throws \Yiisoft\Db\Exception\Exception
25
     * @throws Throwable
26
     */
27 242
    protected function internalExecute(string|null $rawSql): void
28
    {
29 242
        $attempt = 0;
30
31 242
        while (true) {
32
            try {
33
                if (
34 242
                    ++$attempt === 1
35 242
                    && $this->isolationLevel !== null
36 242
                    && $this->db->getTransaction() === null
37
                ) {
38 1
                    $this->db->transaction(
39 1
                        fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
0 ignored issues
show
Unused Code introduced by
The parameter $db is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
                        fn (/** @scrutinizer ignore-unused */ ConnectionPDOInterface $db) => $this->internalExecute($rawSql),

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40 1
                        $this->isolationLevel
41 1
                    );
42
                } else {
43 242
                    $this->pdoStatement?->execute();
44
                }
45 242
                break;
46 8
            } catch (Exception $e) {
47 8
                $rawSql = $rawSql ?: $this->getRawSql();
48 8
                $e = (new ConvertException($e, $rawSql))->run();
49
50 8
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
51 8
                    throw $e;
52
                }
53
            }
54
        }
55
    }
56
}
57