Passed
Push — temp ( ae651e...c74d19 )
by Wilmer
23:03 queued 20:07
created

CommandPDO   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 52
ccs 24
cts 24
cp 1
rs 10
wmc 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A queryBuilder() 0 3 1
A insertEx() 0 12 2
B internalExecute() 0 25 9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql;
6
7
use Exception;
8
use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO;
9
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
10
use Yiisoft\Db\Exception\ConvertException;
11
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
12
13
final class CommandPDO extends AbstractCommandPDO
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 1
    public function insertEx(string $table, array $columns): bool|array
19
    {
20 1
        $params = [];
21 1
        $sql = $this->queryBuilder()->insertEx($table, $columns, $params);
22
23 1
        $this->setSql($sql)->bindValues($params);
24 1
        $this->prepare(false);
25
26
        /** @var mixed */
27 1
        $queryOne = $this->queryOne();
28
29 1
        return is_array($queryOne) ? $queryOne : false;
30
    }
31
32 237
    public function queryBuilder(): QueryBuilderInterface
33
    {
34 237
        return $this->db->getQueryBuilder();
35
    }
36
37
    /**
38
     * @psalm-suppress UnusedClosureParam
39
     */
40 223
    protected function internalExecute(string|null $rawSql): void
41
    {
42 223
        $attempt = 0;
43
44 223
        while (true) {
45
            try {
46
                if (
47
                    ++$attempt === 1
48 223
                    && $this->isolationLevel !== null
49 223
                    && $this->db->getTransaction() === null
50
                ) {
51 1
                    $this->db->transaction(
52 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

52
                        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...
53 1
                        $this->isolationLevel
54
                    );
55
                } else {
56 223
                    $this->pdoStatement?->execute();
57
                }
58 223
                break;
59 9
            } catch (Exception $e) {
60 9
                $rawSql = $rawSql ?: $this->getRawSql();
61 9
                $e = (new ConvertException($e, $rawSql))->run();
62
63 9
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
64 9
                    throw $e;
65
                }
66
            }
67
        }
68
    }
69
}
70