Passed
Push — master ( f23765...94498b )
by Def
28:10 queued 25:16
created

CommandPDO   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 20
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

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\Mysql;
6
7
use PDOException;
8
use Throwable;
9
use Yiisoft\Db\Driver\PDO\CommandPDO as 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 227
    public function queryBuilder(): QueryBuilderInterface
17
    {
18 227
        return $this->db->getQueryBuilder();
19
    }
20
21
    /**
22
     * @psalm-suppress UnusedClosureParam
23
     *
24
     * @throws Throwable
25
     */
26 215
    protected function internalExecute(string|null $rawSql): void
27
    {
28 215
        $attempt = 0;
29
30 215
        while (true) {
31
            try {
32
                if (
33
                    ++$attempt === 1
34 215
                    && $this->isolationLevel !== null
35 215
                    && $this->db->getTransaction() === null
36
                ) {
37 1
                    $this->db->transaction(
38 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

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