Passed
Push — better-naming-classes ( 1280e4...dce7bb )
by Wilmer
03:43
created

Command::getQueryBuilder()   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 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 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 Throwable;
9
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO;
10
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface;
11
use Yiisoft\Db\Exception\ConvertException;
12
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
13
14
/**
15
 * Implements a database command that can be executed with a PDO (PHP Data Object) database connection for PostgreSQL
16
 * Server.
17
 */
18
final class Command extends AbstractCommandPDO
19
{
20 1
    public function showDatabases(): array
21
    {
22 1
        $sql = <<<SQL
23
        SELECT datname FROM pg_database WHERE datistemplate = false AND datname NOT IN ('postgres', 'template0', 'template1')
24 1
        SQL;
25
26 1
        return $this->setSql($sql)->queryColumn();
27
    }
28
29 285
    protected function getQueryBuilder(): QueryBuilderInterface
30
    {
31 285
        return $this->db->getQueryBuilder();
32
    }
33
34
    /**
35
     * @psalm-suppress UnusedClosureParam
36
     *
37
     * @throws \Yiisoft\Db\Exception\Exception
38
     * @throws Throwable
39
     */
40 260
    protected function internalExecute(string|null $rawSql): void
41
    {
42 260
        $attempt = 0;
43
44 260
        while (true) {
45
            try {
46
                if (
47 260
                    ++$attempt === 1
48 260
                    && $this->isolationLevel !== null
49 260
                    && $this->db->getTransaction() === null
50
                ) {
51 1
                    $this->db->transaction(
52 1
                        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 1
                        $this->isolationLevel
54 1
                    );
55
                } else {
56 260
                    $this->pdoStatement?->execute();
57
                }
58 260
                break;
59 8
            } catch (Exception $e) {
60 8
                $rawSql = $rawSql ?: $this->getRawSql();
61 8
                $e = (new ConvertException($e, $rawSql))->run();
62
63 8
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
64 8
                    throw $e;
65
                }
66
            }
67
        }
68
    }
69
}
70