Passed
Pull Request — dev (#56)
by Def
19:33
created

ConnectionPDOOracle::__clone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ConnectionPDOOracle::createTransaction() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle\PDO;
6
7
use PDO;
8
use Yiisoft\Db\Cache\QueryCache;
9
use Yiisoft\Db\Cache\SchemaCache;
10
use Yiisoft\Db\Connection\ConnectionPDO;
11
use Yiisoft\Db\Driver\PDODriver;
12
use Yiisoft\Db\Exception\Exception;
13
use Yiisoft\Db\Exception\InvalidConfigException;
14
use Yiisoft\Db\Oracle\Quoter;
15
use Yiisoft\Db\Query\Query;
16
use Yiisoft\Db\Query\QueryBuilderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\QueryBuilderInterface 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...
17
use Yiisoft\Db\Schema\QuoterInterface;
18
use Yiisoft\Db\Schema\SchemaInterface;
19
use Yiisoft\Db\Transaction\TransactionInterface;
20
21
use function constant;
22
23
/**
24
 * Database connection class prefilled for Oracle SQL Server.
25
 * The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php).
26
 */
27
final class ConnectionPDOOracle extends ConnectionPDO
28
{
29
    private ?Query $query = null;
30
31 381
    public function __construct(
32
        protected PDODriver $driver,
33
        protected QueryCache $queryCache,
34
        protected SchemaCache $schemaCache
35
    ) {
36 381
        parent::__construct($queryCache);
37
    }
38
39 336
    public function createCommand(?string $sql = null, array $params = []): CommandPDOOracle
40
    {
41 336
        $command = new CommandPDOOracle($this, $this->queryCache);
42
43 336
        if ($sql !== null) {
44 174
            $command->setSql($sql);
45
        }
46
47 336
        if ($this->logger !== null) {
48 336
            $command->setLogger($this->logger);
49
        }
50
51 336
        if ($this->profiler !== null) {
52 336
            $command->setProfiler($this->profiler);
53
        }
54
55 336
        return $command->bindValues($params);
56
    }
57
58 8
    public function createTransaction(): TransactionInterface
59
    {
60 8
        return new TransactionPDOOracle($this);
61
    }
62
63 7
    public function getDriverName(): string
64
    {
65 7
        return 'oci';
66
    }
67
68 336
    public function getQuery(): Query
69
    {
70 336
        if ($this->query === null) {
71 336
            $this->query = new Query($this);
72
        }
73
74 336
        return $this->query;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->query could return the type null which is incompatible with the type-hinted return Yiisoft\Db\Query\Query. Consider adding an additional type-check to rule them out.
Loading history...
75
    }
76
77
    /**
78
     * @throws Exception|InvalidConfigException
79
     */
80 336
    public function getQueryBuilder(): QueryBuilderInterface
81
    {
82 336
        if ($this->queryBuilder === null) {
83 336
            $this->queryBuilder = new QueryBuilderPDOOracle(
84 336
                $this->createCommand(),
85 336
                $this->getQuery(),
86 336
                $this->getQuoter(),
87 336
                $this->getSchema(),
88
            );
89
        }
90
91 336
        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\Query\QueryBuilderInterface. Consider adding an additional type-check to rule them out.
Loading history...
92
    }
93
94 349
    public function getQuoter(): QuoterInterface
95
    {
96 349
        if ($this->quoter === null) {
97 349
            $this->quoter = new Quoter('"', '"', $this->getTablePrefix());
98
        }
99
100 349
        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...
101
    }
102
103 350
    public function getSchema(): SchemaInterface
104
    {
105 350
        if ($this->schema === null) {
106 350
            $this->schema = new SchemaPDOOracle($this, $this->schemaCache);
107
        }
108
109 350
        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...
110
    }
111
112
    /**
113
     * Initializes the DB connection.
114
     *
115
     * This method is invoked right after the DB connection is established.
116
     *
117
     * The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`.
118
     *
119
     * if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty.
120
     *
121
     * It then triggers an {@see EVENT_AFTER_OPEN} event.
122
     */
123 177
    protected function initConnection(): void
124
    {
125 177
        $this->pdo = $this->driver->createConnection();
126 177
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
127
128 177
        if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) {
129
            $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare());
130
        }
131
    }
132
}
133