Test Failed
Pull Request — master (#253)
by Wilmer
13:45
created

CommandPDO::getQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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 637
    /**
22
     * @psalm-suppress UnusedClosureParam
23 637
     *
24
     * @throws Exception
25
     * @throws Throwable
26
     */
27
    protected function internalExecute(string|null $rawSql): void
28
    {
29
        $attempt = 0;
30
31
        while (true) {
32 613
            try {
33
                if (
34 613
                    ++$attempt === 1
35
                    && $this->isolationLevel !== null
36 613
                    && $this->db->getTransaction() === null
37
                ) {
38
                    $this->db->transaction(
39 613
                        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 613
                        $this->isolationLevel
41 613
                    );
42
                } else {
43 1
                    $this->pdoStatement?->execute();
44 1
                }
45 1
                break;
46 1
            } catch (PDOException $e) {
47
                $rawSql = $rawSql ?: $this->getRawSql();
48 613
                $e = (new ConvertException($e, $rawSql))->run();
49
50 612
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
51 30
                    throw $e;
52 30
                }
53 30
            }
54
        }
55 30
    }
56 30
57
    protected function getQueryBuilder(): QueryBuilderInterface
58
    {
59
        return $this->db->getQueryBuilder();
60
    }
61
}
62