1 | <?php |
||
2 | /* |
||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
14 | * |
||
15 | * This software consists of voluntary contributions made by many individuals |
||
16 | * and is licensed under the MIT license. For more information, see |
||
17 | * <http://www.doctrine-project.org>. |
||
18 | */ |
||
19 | |||
20 | namespace Doctrine\DBAL\Driver; |
||
21 | |||
22 | use Doctrine\DBAL\DBALException; |
||
23 | use Doctrine\DBAL\Driver; |
||
24 | use Doctrine\DBAL\Platforms\SQLServer2005Platform; |
||
25 | use Doctrine\DBAL\Platforms\SQLServer2008Platform; |
||
26 | use Doctrine\DBAL\Platforms\SQLServer2012Platform; |
||
27 | use Doctrine\DBAL\Platforms\SQLServerPlatform; |
||
28 | use Doctrine\DBAL\Schema\SQLServerSchemaManager; |
||
29 | use Doctrine\DBAL\VersionAwarePlatformDriver; |
||
30 | |||
31 | /** |
||
32 | * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. |
||
33 | * |
||
34 | * @author Steve Müller <[email protected]> |
||
35 | * @link www.doctrine-project.org |
||
36 | * @since 2.5 |
||
37 | */ |
||
38 | abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver |
||
39 | { |
||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | 6 | View Code Duplication | public function createDatabasePlatformForVersion($version) |
0 ignored issues
–
show
|
|||
44 | { |
||
45 | 6 | if ( ! preg_match( |
|
46 | 6 | '/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', |
|
47 | 6 | $version, |
|
48 | 6 | $versionParts |
|
49 | )) { |
||
50 | 3 | throw DBALException::invalidPlatformVersionSpecified( |
|
51 | 3 | $version, |
|
52 | 3 | '<major_version>.<minor_version>.<patch_version>.<build_version>' |
|
53 | ); |
||
54 | } |
||
55 | |||
56 | 3 | $majorVersion = $versionParts['major']; |
|
57 | 3 | $minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0; |
|
58 | 3 | $patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0; |
|
59 | 3 | $buildVersion = isset($versionParts['build']) ? $versionParts['build'] : 0; |
|
60 | 3 | $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; |
|
61 | |||
62 | switch(true) { |
||
63 | 3 | case version_compare($version, '11.00.2100', '>='): |
|
64 | 3 | return new SQLServer2012Platform(); |
|
65 | 3 | case version_compare($version, '10.00.1600', '>='): |
|
66 | 3 | return new SQLServer2008Platform(); |
|
67 | 3 | case version_compare($version, '9.00.1399', '>='): |
|
68 | 3 | return new SQLServer2005Platform(); |
|
69 | default: |
||
70 | 3 | return new SQLServerPlatform(); |
|
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 3 | View Code Duplication | public function getDatabase(\Doctrine\DBAL\Connection $conn) |
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
78 | { |
||
79 | 3 | $params = $conn->getParams(); |
|
80 | |||
81 | 3 | if (isset($params['dbname'])) { |
|
82 | 3 | return $params['dbname']; |
|
83 | } |
||
84 | |||
85 | return $conn->query('SELECT DB_NAME()')->fetchColumn(); |
||
0 ignored issues
–
show
|
|||
86 | } |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | 4 | public function getDatabasePlatform() |
|
92 | { |
||
93 | 4 | return new SQLServer2008Platform(); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | |||
100 | 3 | public function getSchemaManager(\Doctrine\DBAL\Connection $conn) |
|
101 | { |
||
102 | 3 | return new SQLServerSchemaManager($conn); |
|
103 | } |
||
104 | } |
||
105 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.