Passed
Push — dev ( 8dff19...9eee51 )
by Def
03:13
created

CommandPDOMssql::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\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 203
    protected function internalExecute(?string $rawSql): void
39
    {
40 203
        $attempt = 0;
41
42 203
        while (true) {
43
            try {
44
                if (
45 203
                    ++$attempt === 1
46 203
                    && $this->isolationLevel !== null
47 203
                    && $this->db->getTransaction() === null
48
                ) {
49
                    $this->db->transaction(
50
                        fn (string $rawSql) => $this->internalExecute($rawSql),
51
                        $this->isolationLevel
52
                    );
53
                } else {
54 203
                    $this->pdoStatement?->execute();
55
                }
56 202
                break;
57 5
            } catch (PDOException $e) {
58 5
                $rawSql = $rawSql ?: $this->getRawSql();
59 5
                $e = (new ConvertException($e, $rawSql))->run();
60
61 5
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
62 5
                    throw $e;
63
                }
64
            }
65
        }
66
    }
67
}
68