Passed
Pull Request — dev (#100)
by Def
03:28
created

ConnectionPDO::createBatchQueryResult()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Driver\PDO\CommandPDOInterface;
8
use Yiisoft\Db\Driver\PDO\ConnectionPDO as AbstractConnectionPDO;
9
use Yiisoft\Db\Exception\Exception;
10
use Yiisoft\Db\Exception\InvalidConfigException;
11
use Yiisoft\Db\Query\BatchQueryResultInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\BatchQueryResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\Db\Query\QueryInterface;
13
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
14
use Yiisoft\Db\Schema\QuoterInterface;
15
use Yiisoft\Db\Schema\SchemaInterface;
16
use Yiisoft\Db\Transaction\TransactionInterface;
17
18
/**
19
 * Database connection class prefilled for Microsoft SQL Server.
20
 * The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php).
21
 */
22
final class ConnectionPDO extends AbstractConnectionPDO
23
{
24
25
    public function createBatchQueryResult(QueryInterface $query, bool $each = false): BatchQueryResultInterface
26
    {
27
        return (new BatchQueryResult($query, $each));
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Yiisoft\Db\Ms...ryResult($query, $each) returns the type Yiisoft\Db\Mssql\BatchQueryResult which is incompatible with the type-hinted return Yiisoft\Db\Query\BatchQueryResultInterface.
Loading history...
Bug introduced by
$query of type Yiisoft\Db\Query\QueryInterface is incompatible with the type Yiisoft\Db\Connection\ConnectionInterface expected by parameter $db of Yiisoft\Db\Mssql\BatchQueryResult::__construct(). ( Ignorable by Annotation )

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

27
        return (new BatchQueryResult(/** @scrutinizer ignore-type */ $query, $each));
Loading history...
Bug introduced by
$each of type boolean is incompatible with the type Yiisoft\Db\Query\QueryInterface expected by parameter $query of Yiisoft\Db\Mssql\BatchQueryResult::__construct(). ( Ignorable by Annotation )

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

27
        return (new BatchQueryResult($query, /** @scrutinizer ignore-type */ $each));
Loading history...
28
    }
29
30 223
    public function createCommand(?string $sql = null, array $params = []): CommandPDOInterface
31
    {
32 223
        $command = new CommandPDO($this, $this->queryCache);
33
34 223
        if ($sql !== null) {
35 223
            $command->setSql($sql);
36
        }
37
38 223
        if ($this->logger !== null) {
39 223
            $command->setLogger($this->logger);
40
        }
41
42 223
        if ($this->profiler !== null) {
43 223
            $command->setProfiler($this->profiler);
44
        }
45
46 223
        return $command->bindValues($params);
47
    }
48
49 11
    public function createTransaction(): TransactionInterface
50
    {
51 11
        return new TransactionPDO($this);
52
    }
53
54
    /**
55
     * @throws Exception|InvalidConfigException
56
     */
57 385
    public function getQueryBuilder(): QueryBuilderInterface
58
    {
59 385
        if ($this->queryBuilder === null) {
60 385
            $this->queryBuilder = new QueryBuilder(
61 385
                $this->getQuoter(),
62 385
                $this->getSchema(),
63
            );
64
        }
65
66 385
        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...
67
    }
68
69 406
    public function getQuoter(): QuoterInterface
70
    {
71 406
        if ($this->quoter === null) {
72 406
            $this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix());
73
        }
74
75 406
        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...
76
    }
77
78 387
    public function getSchema(): SchemaInterface
79
    {
80 387
        if ($this->schema === null) {
81 387
            $this->schema = new Schema($this, $this->schemaCache);
82
        }
83
84 387
        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...
85
    }
86
87
    /**
88
     * Initializes the DB connection.
89
     *
90
     * This method is invoked right after the DB connection is established.
91
     *
92
     * The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`.
93
     *
94
     * if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty.
95
     *
96
     * It then triggers an {@see EVENT_AFTER_OPEN} event.
97
     */
98 219
    protected function initConnection(): void
99
    {
100 219
        $this->pdo = $this->driver->createConnection();
101
    }
102
}
103