Passed
Push — master ( 2992c2...824837 )
by Def
28:44 queued 24:47
created

CommandPDO::insertWithReturningPks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
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 13
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\Mssql;
6
7
use PDOException;
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\Exception\Exception;
13
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
14
15
use function is_array;
16
17
final class CommandPDO extends AbstractCommandPDO
18
{
19 279
    public function queryBuilder(): QueryBuilderInterface
20
    {
21 279
        return $this->db->getQueryBuilder();
22
    }
23
24
    /**
25
     * @psalm-suppress UnusedClosureParam
26
     *
27
     * @throws Exception
28
     * @throws Throwable
29
     */
30 256
    protected function internalExecute(string|null $rawSql): void
31
    {
32 256
        $attempt = 0;
33
34 256
        while (true) {
35
            try {
36
                if (
37 256
                    ++$attempt === 1
38 256
                    && $this->isolationLevel !== null
39 256
                    && $this->db->getTransaction() === null
40
                ) {
41 1
                    $this->db->transaction(
42 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

42
                        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...
43 1
                        $this->isolationLevel
44 1
                    );
45
                } else {
46 256
                    $this->pdoStatement?->execute();
47
                }
48 255
                break;
49 7
            } catch (PDOException $e) {
50 7
                $rawSql = $rawSql ?: $this->getRawSql();
51 7
                $e = (new ConvertException($e, $rawSql))->run();
52
53 7
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
54 7
                    throw $e;
55
                }
56
            }
57
        }
58
    }
59
}
60