Test Failed
Push — temp ( 23cb4b...ea73cc )
by Wilmer
08:07 queued 05:34
created

CommandPDO::schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Pgsql;
6
7
use Exception;
8
use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO;
9
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
10
use Yiisoft\Db\Exception\ConvertException;
11
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
12
13
final class CommandPDO extends AbstractCommandPDO
14
{
15
    /**
16
     * @inheritDoc
17
     */
18 1
    public function insertEx(string $table, array $columns): bool|array
19
    {
20 1
        $params = [];
21 1
        $sql = $this->queryBuilder()->insertEx($table, $columns, $params);
22
23 1
        $this->setSql($sql)->bindValues($params);
24 1
        $this->prepare(false);
25
26
        /** @var mixed */
27 1
        $queryOne = $this->queryOne();
28
29 1
        return is_array($queryOne) ? $queryOne : false;
30
    }
31
32 209
    public function queryBuilder(): QueryBuilderInterface
33
    {
34 209
        return $this->db->getQueryBuilder();
35
    }
36
37
    /**
38
     * @psalm-suppress UnusedClosureParam
39
     */
40
    protected function internalExecute(string|null $rawSql): void
41
    {
42 198
        $attempt = 0;
43
44 198
        while (true) {
45
            try {
46 198
                if (
47
                    ++$attempt === 1
48
                    && $this->isolationLevel !== null
49
                    && $this->db->getTransaction() === null
50 198
                ) {
51 198
                    $this->db->transaction(
52
                        fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql),
0 ignored issues
show
Unused Code introduced by
The parameter $db is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

52
                        fn (/** @scrutinizer ignore-unused */ ConnectionPDOInterface $db) => $this->internalExecute($rawSql),

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
                        $this->isolationLevel
54
                    );
55
                } else {
56
                    $this->pdoStatement?->execute();
57
                }
58 198
                break;
59
            } catch (Exception $e) {
60 198
                $rawSql = $rawSql ?: $this->getRawSql();
61 7
                $e = (new ConvertException($e, $rawSql))->run();
62 7
63 7
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
64
                    throw $e;
65 7
                }
66 7
            }
67
        }
68
    }
69
}
70