Test Failed
Pull Request — dev (#113)
by Def
04:52 queued 02:29
created

CommandPDOPgsql::getCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
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 internalExecute(?string $rawSql): void
36
    {
37
        $attempt = 0;
38 176
39
        while (true) {
40 176
            try {
41 176
                if (
42
                    ++$attempt === 1
43
                    && $this->isolationLevel !== null
44
                    && $this->db->getTransaction() === null
45
                ) {
46 185
                    $this->db->transaction(
47
                        fn (?string $rawSql): ?string => $this->internalExecute($rawSql),
48 185
                        $this->isolationLevel
49
                    );
50 185
                } else {
51
                    $this->pdoStatement?->execute();
52
                }
53 185
                break;
54 185
            } catch (\Exception $e) {
55 185
                $rawSql = $rawSql ?: $this->getRawSql();
56
                $e = (new ConvertException($e, $rawSql))->run();
57
58
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
59
                    throw $e;
60
                }
61
            }
62 185
        }
63
    }
64
}
65