Passed
Push — master ( 61fa20...2e9247 )
by Wilmer
25:32 queued 12:00
created

CommandPDO   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B internalExecute() 0 25 9
A getQueryBuilder() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql;
6
7
use Exception;
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\QueryBuilder\QueryBuilderInterface;
13
14
/**
15
 * Implements a database command that can be executed with a PDO (PHP Data Object) database connection for PostgreSQL
16
 * Server.
17
 */
18
final class CommandPDO extends AbstractCommandPDO
19
{
20 284
    protected function getQueryBuilder(): QueryBuilderInterface
21
    {
22 284
        return $this->db->getQueryBuilder();
23
    }
24
25
    /**
26
     * @psalm-suppress UnusedClosureParam
27
     *
28
     * @throws \Yiisoft\Db\Exception\Exception
29
     * @throws Throwable
30
     */
31 259
    protected function internalExecute(string|null $rawSql): void
32
    {
33 259
        $attempt = 0;
34
35 259
        while (true) {
36
            try {
37
                if (
38 259
                    ++$attempt === 1
39 259
                    && $this->isolationLevel !== null
40 259
                    && $this->db->getTransaction() === null
41
                ) {
42 1
                    $this->db->transaction(
43 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

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