Passed
Push — dev ( 76dd6e...27bec4 )
by Def
31:49 queued 28:08
created

CommandPDOMssql::queryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql\PDO;
6
7
use PDOException;
8
use Yiisoft\Db\Command\CommandPDO;
9
use Yiisoft\Db\Exception\ConvertException;
10
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...
11
12
use function is_array;
13
14
final class CommandPDOMssql extends CommandPDO
15
{
16
    /**
17
     * @inheritDoc
18
    */
19 2
    public function insertEx(string $table, array $columns): bool|array
20
    {
21 2
        $params = [];
22 2
        $sql = $this->queryBuilder()->insertEx($table, $columns, $params);
23
24 2
        $this->setSql($sql)->bindValues($params);
25 2
        $this->prepare(false);
26
27
        /** @psalm-var array|bool */
28 2
        $result = $this->queryOne();
29
30 2
        return is_array($result) ? $result : false;
31
    }
32
33 214
    public function queryBuilder(): QueryBuilderInterface
34
    {
35 214
        return $this->db->getQueryBuilder();
36
    }
37
38 194
    protected function getCacheKey(int $queryMode, string $rawSql): array
39
    {
40
        return [
41 194
            __CLASS__,
42
            $queryMode,
43 194
            $this->db->getDriver()->getDsn(),
44 194
            $this->db->getDriver()->getUsername(),
45
            $rawSql,
46
        ];
47
    }
48
49 203
    protected function internalExecute(?string $rawSql): void
50
    {
51 203
        $attempt = 0;
52
53 203
        while (true) {
54
            try {
55
                if (
56 203
                    ++$attempt === 1
57 203
                    && $this->isolationLevel !== null
58 203
                    && $this->db->getTransaction() === null
59
                ) {
60
                    $this->db->transaction(
61
                        fn (string $rawSql) => $this->internalExecute($rawSql),
62
                        $this->isolationLevel
63
                    );
64
                } else {
65 203
                    $this->pdoStatement?->execute();
66
                }
67 202
                break;
68 5
            } catch (PDOException $e) {
69 5
                $rawSql = $rawSql ?: $this->getRawSql();
70 5
                $e = (new ConvertException($e, $rawSql))->run();
71
72 5
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
73 5
                    throw $e;
74
                }
75
            }
76
        }
77
    }
78
}
79