Passed
Pull Request — master (#40)
by Def
06:49
created

Connection::getDriverName()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle;
6
7
use PDO;
8
use Yiisoft\Db\Connection\Connection as AbstractConnection;
9
use Yiisoft\Db\Cache\QueryCache;
10
use Yiisoft\Db\Cache\SchemaCache;
11
12
/**
13
 * Database connection class prefilled for ORACLE Server.
14
 */
15 164
final class Connection extends AbstractConnection
16
{
17 164
    private QueryCache $queryCache;
18 164
    private SchemaCache $schemaCache;
19
20
    public function __construct(string $dsn, QueryCache $queryCache, SchemaCache $schemaCache)
21 164
    {
22
        $this->queryCache = $queryCache;
23 164
        $this->schemaCache = $schemaCache;
24
25
        parent::__construct($dsn, $queryCache);
26
    }
27
28
    public function createCommand(?string $sql = null, array $params = []): Command
29
    {
30
        if ($sql !== null) {
31 305
            $sql = $this->quoteSql($sql);
32
        }
33 305
34
        $command = new Command($this, $this->queryCache, $sql);
35
36 204
        if ($this->logger !== null) {
37
            $command->setLogger($this->logger);
38 204
        }
39
40
        if ($this->profiler !== null) {
41 204
            $command->setProfiler($this->profiler);
42
        }
43 204
44
        return $command->bindValues($params);
45 204
    }
46 204
47
    /**
48 204
     * Returns the schema information for the database opened by this connection.
49
     *
50
     * @return Schema the schema information for the database opened by this connection.
51
     */
52 204
    public function getSchema(): Schema
53
    {
54
        return new Schema($this, $this->schemaCache);
55
    }
56
57
    protected function createPdoInstance(): PDO
58
    {
59 7
        return new PDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes());
60
    }
61 7
62
    protected function initConnection(): void
63
    {
64
        $pdo = $this->getPDO();
65
66
        if ($pdo !== null) {
67
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
68
69
            if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) {
70
                $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare());
71
            }
72
        }
73
    }
74
75
    /**
76
     * Returns the name of the DB driver.
77
     *
78
     * @return string name of the DB driver
79
     */
80
    public function getDriverName(): string
81
    {
82
        return 'oci';
83
    }
84
}
85