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

CommandPDOPgsql::prepare()   B

Complexity

Conditions 7
Paths 13

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 7.7656

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 17
c 1
b 0
f 0
nc 13
nop 1
dl 0
loc 30
ccs 12
cts 16
cp 0.75
crap 7.7656
rs 8.8333

1 Method

Rating   Name   Duplication   Size   Complexity  
B CommandPDOPgsql::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