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

Driver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 43
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A connect() 0 11 2
A constructPdoDsn() 0 9 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