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

Driver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 82.14%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
eloc 27
c 3
b 0
f 0
dl 0
loc 94
ccs 23
cts 28
cp 0.8214
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 8 1
A getName() 0 3 1
A getDatabasePlatform() 0 3 1
1
<?php
2
3
/**
4
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
5
 * license agreements.  See the NOTICE file distributed with this work for
6
 * additional information regarding copyright ownership.  Crate licenses
7
 * this file to you under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.  You may
9
 * obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
16
 * License for the specific language governing permissions and limitations
17
 * under the License.
18
 *
19
 * However, if you have executed another commercial license agreement
20
 * with Crate these terms will supersede the license and you may use the
21
 * software solely pursuant to the terms of the relevant commercial agreement.
22
 */
23
24
namespace Crate\DBAL\Driver\PDOCrate;
25
26
use Crate\DBAL\Platforms\CratePlatform;
27
use Crate\DBAL\Platforms\CratePlatform1;
28
use Crate\DBAL\Platforms\CratePlatform4;
29
use Crate\DBAL\Schema\CrateSchemaManager;
30
use Doctrine\DBAL\Connection;
31
use Doctrine\DBAL\Platforms\AbstractPlatform;
32
use Doctrine\DBAL\Schema\AbstractSchemaManager;
33
use SensitiveParameter;
0 ignored issues
show
Bug introduced by
The type SensitiveParameter 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...
34
35
class Driver implements \Doctrine\DBAL\Driver
36
{
37
    public const VERSION = '4.0.3';
38
    public const NAME = 'crate';
39
40
    private const VERSION_057 = '0.57.0';
41
    private const VERSION_4 = '4.0.0';
42
43
    /**
44
     * {@inheritDoc}
45
     * @return PDOConnection The database connection.
46
     */
47 12
    public function connect(
48
        #[SensitiveParameter]
49
        array $params
50
    ): PDOConnection {
51 12
        $username = $params['user'] ?? null;
52 12
        $password = $params['password'] ?? null;
53 12
        $driverOptions = $params['driver_options'] ?? [];
54 12
        return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
55
    }
56
57
    /**
58
     * Constructs the Crate PDO DSN.
59
     *
60
     * @return string The DSN.
61
     */
62 12
    private function constructPdoDsn(array $params): string
63
    {
64 12
        $dsn = self::NAME . ':';
65 12
        if (isset($params['host']) && $params['host'] != '') {
66 12
            $dsn .= $params['host'];
67
        } else {
68
            $dsn .= 'localhost';
69
        }
70 12
        $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200');
71
72 12
        return $dsn;
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 6
    public function getDatabasePlatform(): AbstractPlatform
79
    {
80 6
        return new CratePlatform4();
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86 96
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
87
    {
88
        // Added by Doctrine 3.
89 96
        return new CrateSchemaManager($conn, $platform);
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function getName(): string
96
    {
97
        return self::NAME;
98
    }
99
100
    /**
101
     * {@inheritDoc}
102
     */
103
    public function getDatabase(Connection $conn): string|null
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

103
    public function getDatabase(/** @scrutinizer ignore-unused */ Connection $conn): string|null

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...
104
    {
105
        return null;
106
    }
107
108
    /**
109
     * {@inheritDoc}
110
     */
111 238
    public function createDatabasePlatformForVersion($version): AbstractPlatform
112
    {
113 238
        if (version_compare($version, self::VERSION_057, "<")) {
114 2
            return new CratePlatform();
115 236
        } elseif (version_compare($version, self::VERSION_4, "<")) {
116 2
            return new CratePlatform1();
117
        } else {
118 234
            return new CratePlatform4();
119
        }
120
    }
121
122
    /**
123
     * {@inheritDoc}
124
     */
125 2
    public function getExceptionConverter(): ExceptionConverter
126
    {
127
        // Added by Doctrine 3.
128 2
        return new ExceptionConverter();
129
    }
130
}
131