Passed
Push — master ( d08abb...a95734 )
by Wilmer
18:13 queued 13:57
created

CommandPDO::internalExecute()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 18
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 25
ccs 17
cts 17
cp 1
crap 9
rs 8.0555
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
/**
16
 * Implements a database command that can be executed against a PDO (PHP Data Object) database connection for MSSQL
17
 * Server.
18
 */
19
final class CommandPDO extends AbstractCommandPDO
20
{
21
    /**
22
     * @psalm-suppress UnusedClosureParam
23
     *
24
     * @throws Exception
25
     * @throws Throwable
26
     */
27 613
    protected function internalExecute(string|null $rawSql): void
28
    {
29 613
        $attempt = 0;
30
31 613
        while (true) {
32
            try {
33
                if (
34 613
                    ++$attempt === 1
35 613
                    && $this->isolationLevel !== null
36 613
                    && $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 613
                    $this->pdoStatement?->execute();
44
                }
45 612
                break;
46 30
            } catch (PDOException $e) {
47 30
                $rawSql = $rawSql ?: $this->getRawSql();
48 30
                $e = (new ConvertException($e, $rawSql))->run();
49
50 30
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
51 30
                    throw $e;
52
                }
53
            }
54
        }
55
    }
56
57 637
    protected function getQueryBuilder(): QueryBuilderInterface
58
    {
59 637
        return $this->db->getQueryBuilder();
60
    }
61
}
62