Passed
Push — dev ( adb141...4e189c )
by Def
25:37 queued 22:33
created

CommandPDOPgsql   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 89.66%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 13
eloc 32
c 4
b 0
f 0
dl 0
loc 60
ccs 26
cts 29
cp 0.8966
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A queryBuilder() 0 3 1
A insertEx() 0 12 2
A getCacheKey() 0 8 1
B internalExecute() 0 25 9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql\PDO;
6
7
use Yiisoft\Db\Command\CommandPDO;
8
use Yiisoft\Db\Exception\ConvertException;
9
use Yiisoft\Db\Query\QueryBuilderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\QueryBuilderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
final class CommandPDOPgsql extends CommandPDO
12
{
13
    /**
14
     * @inheritDoc
15
     */
16 1
    public function insertEx(string $table, array $columns): bool|array
17
    {
18 1
        $params = [];
19 1
        $sql = $this->queryBuilder()->insertEx($table, $columns, $params);
20
21 1
        $this->setSql($sql)->bindValues($params);
22 1
        $this->prepare(false);
23
24
        /** @var mixed */
25 1
        $queryOne = $this->queryOne();
26
27 1
        return is_array($queryOne) ? $queryOne : false;
28
    }
29
30 196
    public function queryBuilder(): QueryBuilderInterface
31
    {
32 196
        return $this->db->getQueryBuilder();
33
    }
34
35 176
    protected function getCacheKey(int $queryMode, string $rawSql): array
36
    {
37
        return [
38 176
            __CLASS__,
39
            $queryMode,
40 176
            $this->db->getDriver()->getDsn(),
41 176
            $this->db->getDriver()->getUsername(),
42
            $rawSql,
43
        ];
44
    }
45
46 185
    protected function internalExecute(?string $rawSql): void
47
    {
48 185
        $attempt = 0;
49
50 185
        while (true) {
51
            try {
52
                if (
53 185
                    ++$attempt === 1
54 185
                    && $this->isolationLevel !== null
55 185
                    && $this->db->getTransaction() === null
56
                ) {
57
                    $this->db->transaction(
58
                        fn (?string $rawSql): ?string => $this->internalExecute($rawSql),
59
                        $this->isolationLevel
60
                    );
61
                } else {
62 185
                    $this->pdoStatement?->execute();
63
                }
64 185
                break;
65 7
            } catch (\Exception $e) {
66 7
                $rawSql = $rawSql ?: $this->getRawSql();
67 7
                $e = (new ConvertException($e, $rawSql))->run();
68
69 7
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
70 7
                    throw $e;
71
                }
72
            }
73
        }
74
    }
75
}
76