Failed Conditions
Pull Request — master (#3666)
by
unknown
03:20
created

createDatabasePlatformForVersion()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 9.8333
cc 3
nc 3
nop 1
crap 3
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\Platforms\Oracle122Platform;
11
use Doctrine\DBAL\Schema\OracleSchemaManager;
12
13
/**
14
 * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
15
 */
16
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Driver\VersionAwarePlatformDriver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
{
18
    /**
19
     * {@inheritdoc}
20 1622
     */
21
    public function convertException($message, DriverException $exception)
22 1622
    {
23 1622
        switch ($exception->getErrorCode()) {
24 1612
            case '1':
25 1606
            case '2299':
26 1022
            case '38911':
27
                return new Exception\UniqueConstraintViolationException($message, $exception);
28 1600
29 1183
            case '904':
30
                return new Exception\InvalidFieldNameException($message, $exception);
31 1592
32 1584
            case '918':
33 1164
            case '960':
34
                return new Exception\NonUniqueFieldNameException($message, $exception);
35 1578
36 1083
            case '923':
37
                return new Exception\SyntaxErrorException($message, $exception);
38 1570
39 1155
            case '942':
40
                return new Exception\TableNotFoundException($message, $exception);
41 1562
42 1099
            case '955':
43
                return new Exception\TableExistsException($message, $exception);
44 1514
45 1479
            case '1017':
46 1268
            case '12545':
47
                return new Exception\ConnectionException($message, $exception);
48 1446
49 1108
            case '1400':
50
                return new Exception\NotNullConstraintViolationException($message, $exception);
51 1438
52 1438
            case '2266':
53 1438
            case '2291':
54 1214
            case '2292':
55
                return new Exception\ForeignKeyConstraintViolationException($message, $exception);
56
        }
57 1157
58
        return new Exception\DriverException($message, $exception);
59
    }
60
61
/**
62
     * {@inheritdoc}
63 1440
     */
64
    public function createDatabasePlatformForVersion($version)
65 1440
    {
66
        //Example: "Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production"
67 1440
        if (! preg_match('/\s+((?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\.(\d+)\.(\d+))\s+/', $version, $versionParts)) {
68
            throw DBALException::invalidPlatformVersionSpecified(
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Driver\DBALException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
                $version,
70
                '<major_version>.<minor_version>.<patch_version>'
71
            );
72
        }
73 948
        
74
        $majorVersion = $versionParts['major'];
75 948
        $minorVersion = $versionParts['minor'] ?? 0;
76
        $patchVersion = $versionParts['patch'] ?? 0;
77
        $version      = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
78
79
        switch (true) {
80
            case version_compare($version, '12.2', '>='):
81 902
                return new Oracle122Platform();
82
            default:
83 902
                return new OraclePlatform();
84
        }
85
    }
86
    
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getDatabase(Connection $conn)
91
    {
92
        $params = $conn->getParams();
93 64
94
        return $params['user'];
95 64
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function getDatabasePlatform()
101
    {
102
        return new OraclePlatform();
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getSchemaManager(Connection $conn)
109
    {
110
        return new OracleSchemaManager($conn);
111
    }
112
113
    /**
114
     * Returns an appropriate Easy Connect String for the given parameters.
115
     *
116
     * @param mixed[] $params The connection parameters to return the Easy Connect String for.
117
     *
118
     * @return string
119
     */
120
    protected function getEasyConnectString(array $params)
121
    {
122
        return (string) EasyConnectString::fromConnectionParameters($params);
123
    }
124
}
125