Passed
Push — master ( 647f42...eee75a )
by Wilmer
04:02
created

Connection::initConnection()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
crap 4.074
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
10
/**
11
 * Database connection class prefilled for ORACLE Server.
12
 */
13
final class Connection extends AbstractConnection
14
{
15 164
    public function createCommand(?string $sql = null, array $params = []): Command
16
    {
17 164
        if ($sql !== null) {
18 164
            $sql = $this->quoteSql($sql);
19
        }
20
21 164
        $command = new Command($this, $sql);
22
23 164
        return $command->bindValues($params);
24
    }
25
26
    /**
27
     * Returns the schema information for the database opened by this connection.
28
     *
29
     * @return Schema the schema information for the database opened by this connection.
30
     */
31 305
    public function getSchema(): Schema
32
    {
33 305
        return new Schema($this);
34
    }
35
36 204
    protected function createPdoInstance(): PDO
37
    {
38 204
        return new PDO($this->getDsn(), $this->getUsername(), $this->getPassword(), $this->getAttributes());
39
    }
40
41 204
    protected function initConnection(): void
42
    {
43 204
        $pdo = $this->getPDO();
44
45 204
        if ($pdo !== null) {
46 204
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
47
48 204
            if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) {
49
                $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare());
50
            }
51
        }
52 204
    }
53
54
    /**
55
     * Returns the name of the DB driver.
56
     *
57
     * @return string name of the DB driver
58
     */
59 7
    public function getDriverName(): string
60
    {
61 7
        return 'oci';
62
    }
63
}
64