Failed Conditions
Pull Request — develop (#3518)
by Michael
29:00 queued 25:29
created

AbstractOracleDriver::getSchemaManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver;
6
7
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...
8
use Doctrine\DBAL\Driver;
9
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
10
use Doctrine\DBAL\Exception;
11
use Doctrine\DBAL\Platforms\OraclePlatform;
12
use Doctrine\DBAL\Schema\OracleSchemaManager;
13
14
/**
15
 * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
16
 */
17
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 286
    public function convertException($message, DriverException $exception)
23
    {
24 286
        switch ($exception->getCode()) {
25
            case 1:
26
            case 2299:
27
            case 38911:
28 286
                return new Exception\UniqueConstraintViolationException($message, $exception);
29
30
            case 904:
31 286
                return new Exception\InvalidFieldNameException($message, $exception);
32
33
            case 918:
34
            case 960:
35 286
                return new Exception\NonUniqueFieldNameException($message, $exception);
36
37
            case 923:
38 286
                return new Exception\SyntaxErrorException($message, $exception);
39
40
            case 942:
41 286
                return new Exception\TableNotFoundException($message, $exception);
42
43
            case 955:
44 286
                return new Exception\TableExistsException($message, $exception);
45
46
            case 1017:
47
            case 12545:
48 286
                return new Exception\ConnectionException($message, $exception);
49
50
            case 1400:
51 286
                return new Exception\NotNullConstraintViolationException($message, $exception);
52
53
            case 2266:
54
            case 2291:
55
            case 2292:
56 286
                return new Exception\ForeignKeyConstraintViolationException($message, $exception);
57
        }
58
59 286
        return new Exception\DriverException($message, $exception);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 338
    public function getDatabase(Connection $conn)
66
    {
67 338
        $params = $conn->getParams();
68
69 338
        return $params['user'];
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 260
    public function getDatabasePlatform()
76
    {
77 260
        return new OraclePlatform();
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 234
    public function getSchemaManager(Connection $conn)
84
    {
85 234
        return new OracleSchemaManager($conn);
86
    }
87
88
    /**
89
     * Returns an appropriate Easy Connect String for the given parameters.
90
     *
91
     * @param mixed[] $params The connection parameters to return the Easy Connect String for.
92
     *
93
     * @return string
94
     */
95
    protected function getEasyConnectString(array $params)
96
    {
97
        return (string) EasyConnectString::fromConnectionParameters($params);
98
    }
99
}
100