Failed Conditions
Pull Request — master (#3546)
by Sergei
14:16
created

Driver::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 4
crap 2
1
<?php
2
3
namespace Doctrine\DBAL\Driver\PDOOracle;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\Driver\AbstractOracleDriver;
7
use Doctrine\DBAL\Driver\PDOConnection;
8
use PDOException;
9
10
/**
11
 * PDO Oracle driver.
12
 *
13
 * WARNING: This driver gives us segfaults in our testsuites on CLOB and other
14
 * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
15
 * which leads us to the recommendation to use the "oci8" driver to connect
16
 * to Oracle instead.
17
 */
18
class Driver extends AbstractOracleDriver
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 32
    public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
24
    {
25
        try {
26 32
            return new PDOConnection(
27 32
                $this->constructPdoDsn($params),
28 32
                $username,
29 32
                $password,
30 32
                $driverOptions
31
            );
32 3
        } catch (PDOException $e) {
33 3
            throw DBALException::driverException($this, $e);
34
        }
35
    }
36
37
    /**
38
     * Constructs the Oracle PDO DSN.
39
     *
40
     * @param mixed[] $params
41
     *
42
     * @return string The DSN.
43
     */
44 32
    private function constructPdoDsn(array $params)
45
    {
46 32
        $dsn = 'oci:dbname=' . $this->getEasyConnectString($params);
47
48 32
        if (isset($params['charset'])) {
49
            $dsn .= ';charset=' . $params['charset'];
50
        }
51
52 32
        return $dsn;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 27
    public function getName()
59
    {
60 27
        return 'pdo_oracle';
61
    }
62
}
63