Passed
Push — 2.9 ( d389f3...7345cd )
by Sergei
31:44 queued 28:51
created

AbstractOracleDriver   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 20
eloc 32
dl 0
loc 81
ccs 34
cts 36
cp 0.9444
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
C convertException() 0 38 16
A getSchemaManager() 0 3 1
A getDatabase() 0 5 1
A getDatabasePlatform() 0 3 1
A getEasyConnectString() 0 3 1
1
<?php
2
3
namespace Doctrine\DBAL\Driver;
4
5
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Doctrine\DBAL\Driver\Connection. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Doctrine\DBAL\Driver;
7
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
8
use Doctrine\DBAL\Exception;
9
use Doctrine\DBAL\Platforms\OraclePlatform;
10
use Doctrine\DBAL\Schema\OracleSchemaManager;
11
12
/**
13
 * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
14
 */
15
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 90
    public function convertException($message, DriverException $exception)
21
    {
22 90
        switch ($exception->getErrorCode()) {
23 90
            case '1':
24 90
            case '2299':
25 90
            case '38911':
26 90
                return new Exception\UniqueConstraintViolationException($message, $exception);
27
28 90
            case '904':
29 90
                return new Exception\InvalidFieldNameException($message, $exception);
30
31 90
            case '918':
32 90
            case '960':
33 90
                return new Exception\NonUniqueFieldNameException($message, $exception);
34
35 90
            case '923':
36 90
                return new Exception\SyntaxErrorException($message, $exception);
37
38 90
            case '942':
39 90
                return new Exception\TableNotFoundException($message, $exception);
40
41 90
            case '955':
42 90
                return new Exception\TableExistsException($message, $exception);
43
44 90
            case '1017':
45 90
            case '12545':
46 90
                return new Exception\ConnectionException($message, $exception);
47
48 90
            case '1400':
49 90
                return new Exception\NotNullConstraintViolationException($message, $exception);
50
51 90
            case '2266':
52 90
            case '2291':
53 90
            case '2292':
54 90
                return new Exception\ForeignKeyConstraintViolationException($message, $exception);
55
        }
56
57 90
        return new Exception\DriverException($message, $exception);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 180
    public function getDatabase(Connection $conn)
64
    {
65 180
        $params = $conn->getParams();
66
67 180
        return $params['user'];
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 90
    public function getDatabasePlatform()
74
    {
75 90
        return new OraclePlatform();
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 90
    public function getSchemaManager(Connection $conn)
82
    {
83 90
        return new OracleSchemaManager($conn);
84
    }
85
86
    /**
87
     * Returns an appropriate Easy Connect String for the given parameters.
88
     *
89
     * @param mixed[] $params The connection parameters to return the Easy Connect String for.
90
     *
91
     * @return string
92
     */
93
    protected function getEasyConnectString(array $params)
94
    {
95
        return (string) EasyConnectString::fromConnectionParameters($params);
96
    }
97
}
98