Test Failed
Pull Request — master (#177)
by Def
22:22 queued 18:44
created

CommandPDO   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B internalExecute() 0 25 9
A queryBuilder() 0 3 1
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
    public function queryBuilder(): QueryBuilderInterface
20
    {
21
        return $this->db->getQueryBuilder();
22 6
    }
23
24 6
    /**
25
     * @psalm-suppress UnusedClosureParam
26 6
     *
27
     * @throws Exception
28 6
     * @throws Throwable
29 6
     */
30
    protected function internalExecute(string|null $rawSql): void
31
    {
32 6
        $attempt = 0;
33
34 6
        while (true) {
35
            try {
36
                if (
37 280
                    ++$attempt === 1
38
                    && $this->isolationLevel !== null
39 280
                    && $this->db->getTransaction() === null
40
                ) {
41
                    $this->db->transaction(
42
                        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
                        $this->isolationLevel
44
                    );
45
                } else {
46
                    $this->pdoStatement?->execute();
47
                }
48 257
                break;
49
            } catch (PDOException $e) {
50 257
                $rawSql = $rawSql ?: $this->getRawSql();
51
                $e = (new ConvertException($e, $rawSql))->run();
52 257
53
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
54
                    throw $e;
55 257
                }
56 257
            }
57 257
        }
58
    }
59
}
60