Passed
Pull Request — main (#122)
by Andreas
02:03
created

Driver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
eloc 24
c 3
b 0
f 0
dl 0
loc 89
ccs 20
cts 25
cp 0.8
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchemaManager() 0 4 1
A createDatabasePlatformForVersion() 0 8 3
A getExceptionConverter() 0 4 1
A constructPdoDsn() 0 11 4
A getDatabase() 0 3 1
A connect() 0 3 1
A getName() 0 3 1
A getDatabasePlatform() 0 3 1
1
<?php
2
/**
3
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4
 * license agreements.  See the NOTICE file distributed with this work for
5
 * additional information regarding copyright ownership.  Crate licenses
6
 * this file to you under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.  You may
8
 * obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15
 * License for the specific language governing permissions and limitations
16
 * under the License.
17
 *
18
 * However, if you have executed another commercial license agreement
19
 * with Crate these terms will supersede the license and you may use the
20
 * software solely pursuant to the terms of the relevant commercial agreement.
21
 */
22
namespace Crate\DBAL\Driver\PDOCrate;
23
24
use Crate\DBAL\Platforms\CratePlatform1;
25
use Crate\DBAL\Platforms\CratePlatform;
26
use Crate\DBAL\Platforms\CratePlatform4;
27
use Crate\DBAL\Schema\CrateSchemaManager;
28
use Doctrine\DBAL\Connection;
29
use Doctrine\DBAL\Platforms\AbstractPlatform;
30
use Doctrine\DBAL\VersionAwarePlatformDriver;
31
32
class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver
0 ignored issues
show
Deprecated Code introduced by
The interface Doctrine\DBAL\VersionAwarePlatformDriver has been deprecated: All drivers will have to be aware of the server version in the next major release. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

32
class Driver implements \Doctrine\DBAL\Driver, /** @scrutinizer ignore-deprecated */ VersionAwarePlatformDriver

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
33
{
34
    const VERSION = '4.0.3';
35
    const NAME = 'crate';
36
37
    private const VERSION_057 = '0.57.0';
38
    private const VERSION_4 = '4.0.0';
39
40
    /**
41
     * {@inheritDoc}
42
     * @return PDOConnection The database connection.
43
     */
44 12
    public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
45
    {
46 12
        return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
47
    }
48
49
    /**
50
     * Constructs the Crate PDO DSN.
51
     *
52
     * @return string The DSN.
53
     */
54 12
    private function constructPdoDsn(array $params)
55
    {
56 12
        $dsn = self::NAME . ':';
57 12
        if (isset($params['host']) && $params['host'] != '') {
58 12
            $dsn .= $params['host'];
59
        } else {
60
            $dsn .= 'localhost';
61
        }
62 12
        $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200');
63
64 12
        return $dsn;
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70 6
    public function getDatabasePlatform()
71
    {
72 6
        return new CratePlatform4();
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 4
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
79
    {
80
        // Added by Doctrine 3.
81 4
        return new CrateSchemaManager($conn, $conn->getDatabasePlatform());
82
    }
83
84
    /**
85
     * {@inheritDoc}
86
     */
87
    public function getName()
88
    {
89
        return self::NAME;
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function getDatabase(Connection $conn)
0 ignored issues
show
Unused Code introduced by
The parameter $conn is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

95
    public function getDatabase(/** @scrutinizer ignore-unused */ Connection $conn)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        return null;
98
    }
99
100
    /**
101
     * {@inheritDoc}
102
     */
103 238
    public function createDatabasePlatformForVersion($version)
104
    {
105 238
        if (version_compare($version, self::VERSION_057, "<")) {
106 2
            return new CratePlatform();
107 236
        } elseif (version_compare($version, self::VERSION_4, "<")) {
108 2
            return new CratePlatform1();
109
        } else {
110 234
            return new CratePlatform4();
111
        }
112
    }
113
114
    /**
115
     * {@inheritDoc}
116
     */
117 2
    public function getExceptionConverter(): ExceptionConverter
118
    {
119
        // Added by Doctrine 3.
120 2
        return new ExceptionConverter();
121
    }
122
}
123