Completed
Pull Request — master (#3772)
by Christoph
51:54
created

Driver::connect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.4168

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 17
ccs 9
cts 17
cp 0.5294
rs 9.9332
cc 2
nc 2
nop 4
crap 2.4168
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver\OCI8;
6
7
use Doctrine\DBAL\DBALException;
8
use Doctrine\DBAL\Driver\AbstractOracleDriver;
9
use Doctrine\DBAL\Driver\Connection;
10
use const OCI_DEFAULT;
11
12
/**
13
 * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
14
 */
15
class Driver extends AbstractOracleDriver
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 60
    public function connect(
21
        array $params,
22
        string $username = '',
23
        string $password = '',
24
        array $driverOptions = []
25
    ) : Connection {
26
        try {
27 60
            return new OCI8Connection(
28 60
                $username,
29
                $password,
30 60
                $this->_constructDsn($params),
31 60
                $params['charset'] ?? '',
32 60
                $params['sessionMode'] ?? OCI_DEFAULT,
33 60
                $params['persistent'] ?? false
34
            );
35 6
        } catch (OCI8Exception $e) {
36 6
            throw DBALException::driverException($this, $e);
37
        }
38
    }
39
40
    /**
41
     * Constructs the Oracle DSN.
42
     *
43
     * @param mixed[] $params
44
     *
45
     * @return string The DSN.
46
     */
47 60
    protected function _constructDsn(array $params) : string
48
    {
49 60
        return $this->getEasyConnectString($params);
50
    }
51
}
52