Passed
Push — better-naming-classes ( 1280e4 )
by Wilmer
04:32
created

PdoConnection::getQuoter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
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 Yiisoft\Db\Driver\PDO\AbstractConnectionPDO;
8
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
9
use Yiisoft\Db\Exception\InvalidArgumentException;
10
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
11
use Yiisoft\Db\Schema\Quoter;
12
use Yiisoft\Db\Schema\QuoterInterface;
13
use Yiisoft\Db\Schema\SchemaInterface;
14
use Yiisoft\Db\Transaction\TransactionInterface;
15
16
/**
17
 * Implements a connection to a database via PDO (PHP Data Objects) for PostgreSQL Server.
18
 *
19
 * @link https://www.php.net/manual/en/ref.pdo-pgsql.php
20
 */
21
final class PdoConnection extends AbstractConnectionPDO
22
{
23 289
    public function createCommand(string $sql = null, array $params = []): CommandPDOInterface
24
    {
25 289
        $command = new PdoCommand($this);
26
27 289
        if ($sql !== null) {
28 263
            $command->setSql($sql);
29
        }
30
31 289
        if ($this->logger !== null) {
32 2
            $command->setLogger($this->logger);
33
        }
34
35 289
        if ($this->profiler !== null) {
36 3
            $command->setProfiler($this->profiler);
37
        }
38
39 289
        return $command->bindValues($params);
40
    }
41
42 13
    public function createTransaction(): TransactionInterface
43
    {
44 13
        return new PdoTransaction($this);
45
    }
46
47 4
    public function getLastInsertID(string $sequenceName = null): string
48
    {
49 4
        if ($sequenceName === null) {
50 1
            throw new InvalidArgumentException('PostgreSQL not support lastInsertId without sequence name.');
51
        }
52
53 3
        return parent::getLastInsertID($sequenceName);
54
    }
55
56 574
    public function getQueryBuilder(): QueryBuilderInterface
57
    {
58 574
        if ($this->queryBuilder === null) {
59 574
            $this->queryBuilder = new QueryBuilder(
60 574
                $this->getQuoter(),
61 574
                $this->getSchema(),
62 574
            );
63
        }
64
65 574
        return $this->queryBuilder;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->queryBuilder could return the type null which is incompatible with the type-hinted return Yiisoft\Db\QueryBuilder\QueryBuilderInterface. Consider adding an additional type-check to rule them out.
Loading history...
66
    }
67
68 611
    public function getQuoter(): QuoterInterface
69
    {
70 611
        if ($this->quoter === null) {
71 611
            $this->quoter = new Quoter('"', '"', $this->getTablePrefix());
72
        }
73
74 611
        return $this->quoter;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->quoter could return the type null which is incompatible with the type-hinted return Yiisoft\Db\Schema\QuoterInterface. Consider adding an additional type-check to rule them out.
Loading history...
75
    }
76
77 598
    public function getSchema(): SchemaInterface
78
    {
79 598
        if ($this->schema === null) {
80 598
            $this->schema = new Schema($this, $this->schemaCache);
81
        }
82
83 598
        return $this->schema;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->schema could return the type null which is incompatible with the type-hinted return Yiisoft\Db\Schema\SchemaInterface. Consider adding an additional type-check to rule them out.
Loading history...
84
    }
85
}
86