Passed
Push — master ( d5a984...e1ae71 )
by Wilmer
37:04 queued 24:52
created

ConnectionPDO::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 PDO;
8
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
9
use Yiisoft\Db\Driver\PDO\ConnectionPDO as AbstractConnectionPDO;
10
use Yiisoft\Db\Exception\Exception;
11
use Yiisoft\Db\Exception\InvalidArgumentException;
12
use Yiisoft\Db\Exception\InvalidConfigException;
13
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
14
use Yiisoft\Db\Schema\Quoter;
15
use Yiisoft\Db\Schema\QuoterInterface;
16
use Yiisoft\Db\Schema\SchemaInterface;
17
use Yiisoft\Db\Transaction\TransactionInterface;
18
19
/**
20
 * Database connection class prefilled for PgSQL Server.
21
 * The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php).
22
 */
23
final class ConnectionPDO extends AbstractConnectionPDO
24
{
25 260
    public function createCommand(string $sql = null, array $params = []): CommandPDOInterface
26
    {
27 260
        $command = new CommandPDO($this, $this->queryCache);
28
29 260
        if ($sql !== null) {
30 238
            $command->setSql($sql);
31
        }
32
33 260
        if ($this->logger !== null) {
34 1
            $command->setLogger($this->logger);
35
        }
36
37 260
        if ($this->profiler !== null) {
38 1
            $command->setProfiler($this->profiler);
39
        }
40
41 260
        return $command->bindValues($params);
42
    }
43
44 8
    public function createTransaction(): TransactionInterface
45
    {
46 8
        return new TransactionPDO($this);
47
    }
48
49 4
    public function getLastInsertID(string $sequenceName = null): string
50
    {
51 4
        if ($sequenceName === null) {
52 1
            throw new InvalidArgumentException('PostgreSQL not support lastInsertId without sequence name.');
53
        }
54
55 3
        return parent::getLastInsertID($sequenceName);
56
    }
57
58
    /**
59
     * @throws Exception|InvalidConfigException
60
     */
61 521
    public function getQueryBuilder(): QueryBuilderInterface
62
    {
63 521
        if ($this->queryBuilder === null) {
64 521
            $this->queryBuilder = new QueryBuilder(
65 521
                $this->getQuoter(),
66 521
                $this->getSchema(),
67 521
            );
68
        }
69
70 521
        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...
71
    }
72
73 557
    public function getQuoter(): QuoterInterface
74
    {
75 557
        if ($this->quoter === null) {
76 557
            $this->quoter = new Quoter('"', '"', $this->getTablePrefix());
77
        }
78
79 557
        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...
80
    }
81
82 545
    public function getSchema(): SchemaInterface
83
    {
84 545
        if ($this->schema === null) {
85 545
            $this->schema = new Schema($this, $this->schemaCache);
86
        }
87
88 545
        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...
89
    }
90
}
91