Passed
Push — dev ( 85c32d...c7af07 )
by Def
16:37 queued 08:07
created

ConnectionPDOOracle   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 96.97%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 83
ccs 32
cts 33
cp 0.9697
rs 10
c 0
b 0
f 0
wmc 15

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createCommand() 0 17 4
A createTransaction() 0 3 1
A getQuoter() 0 7 2
A getDriverName() 0 3 1
A getSchema() 0 7 2
A getQueryBuilder() 0 11 2
A initConnection() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle\PDO;
6
7
use PDO;
8
use Yiisoft\Db\Connection\ConnectionPDO;
9
use Yiisoft\Db\Exception\Exception;
10
use Yiisoft\Db\Exception\InvalidConfigException;
11
use Yiisoft\Db\Oracle\Quoter;
12
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...
13
use Yiisoft\Db\Schema\QuoterInterface;
14
use Yiisoft\Db\Schema\SchemaInterface;
15
use Yiisoft\Db\Transaction\TransactionInterface;
16
17
use function constant;
18
19
/**
20
 * Database connection class prefilled for Oracle SQL 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 ConnectionPDOOracle extends ConnectionPDO
24
{
25 336
    public function createCommand(?string $sql = null, array $params = []): CommandPDOOracle
26
    {
27 336
        $command = new CommandPDOOracle($this, $this->queryCache);
28
29 336
        if ($sql !== null) {
30 174
            $command->setSql($sql);
31
        }
32
33 336
        if ($this->logger !== null) {
34 336
            $command->setLogger($this->logger);
35
        }
36
37 336
        if ($this->profiler !== null) {
38 336
            $command->setProfiler($this->profiler);
39
        }
40
41 336
        return $command->bindValues($params);
42
    }
43
44 8
    public function createTransaction(): TransactionInterface
45
    {
46 8
        return new TransactionPDOOracle($this);
47
    }
48
49 7
    public function getDriverName(): string
50
    {
51 7
        return 'oci';
52
    }
53
54
    /**
55
     * @throws Exception|InvalidConfigException
56
     */
57 336
    public function getQueryBuilder(): QueryBuilderInterface
58
    {
59 336
        if ($this->queryBuilder === null) {
60 336
            $this->queryBuilder = new QueryBuilderPDOOracle(
61 336
                $this->createCommand(),
62 336
                $this->getQuoter(),
63 336
                $this->getSchema(),
64
            );
65
        }
66
67 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...
68
    }
69
70 349
    public function getQuoter(): QuoterInterface
71
    {
72 349
        if ($this->quoter === null) {
73 349
            $this->quoter = new Quoter('"', '"', $this->getTablePrefix());
74
        }
75
76 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...
77
    }
78
79 350
    public function getSchema(): SchemaInterface
80
    {
81 350
        if ($this->schema === null) {
82 350
            $this->schema = new SchemaPDOOracle($this, $this->schemaCache);
83
        }
84
85 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...
86
    }
87
88
    /**
89
     * Initializes the DB connection.
90
     *
91
     * This method is invoked right after the DB connection is established.
92
     *
93
     * The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`.
94
     *
95
     * if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty.
96
     *
97
     * It then triggers an {@see EVENT_AFTER_OPEN} event.
98
     */
99 177
    protected function initConnection(): void
100
    {
101 177
        $this->pdo = $this->driver->createConnection();
102 177
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
103
104 177
        if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) {
105
            $this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare());
106
        }
107
    }
108
}
109