Passed
Pull Request — master (#300)
by Sergei
03:59
created

Connection::createBatchQueryResult()   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 2
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\Mssql;
6
7
use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
8
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
9
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
10
use Yiisoft\Db\Schema\QuoterInterface;
11
use Yiisoft\Db\Schema\SchemaInterface;
12
use Yiisoft\Db\Transaction\TransactionInterface;
13
14
/**
15
 * Implements a connection to a database via PDO (PHP Data Objects) for MSSQL Server.
16
 *
17
 * @link https://www.php.net/manual/en/ref.pdo-sqlsrv.php
18
 */
19
final class Connection extends AbstractPdoConnection
20
{
21 673
    public function createCommand(string $sql = null, array $params = []): PdoCommandInterface
22
    {
23 673
        $command = new Command($this);
24
25 673
        if ($sql !== null) {
26 614
            $command->setSql($sql);
27
        }
28
29 673
        if ($this->logger !== null) {
30 2
            $command->setLogger($this->logger);
31
        }
32
33 673
        if ($this->profiler !== null) {
34 3
            $command->setProfiler($this->profiler);
35
        }
36
37 673
        return $command->bindValues($params);
38
    }
39
40 14
    public function createTransaction(): TransactionInterface
41
    {
42 14
        return new Transaction($this);
43
    }
44
45 920
    public function getQueryBuilder(): QueryBuilderInterface
46
    {
47 920
        if ($this->queryBuilder === null) {
48 920
            $this->queryBuilder = new QueryBuilder(
49 920
                $this->getQuoter(),
50 920
                $this->getSchema(),
51 920
            );
52
        }
53
54 920
        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...
55
    }
56
57 985
    public function getQuoter(): QuoterInterface
58
    {
59 985
        if ($this->quoter === null) {
60 985
            $this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix());
61
        }
62
63 985
        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...
64
    }
65
66 931
    public function getSchema(): SchemaInterface
67
    {
68 931
        if ($this->schema === null) {
69 931
            $this->schema = new Schema($this, $this->schemaCache);
70
        }
71
72 931
        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...
73
    }
74
75
    /**
76
     * Initializes the DB connection.
77
     *
78
     * This method is invoked right after the DB connection is established.
79
     */
80 661
    protected function initConnection(): void
81
    {
82 661
        $this->pdo = $this->driver->createConnection();
83
    }
84
}
85