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

Driver::getDatabasePlatform()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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\Schema\AbstractSchemaManager;
31
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...
32
33
class Driver implements \Doctrine\DBAL\Driver
34
{
35
    const VERSION = '4.0.3';
36
    const NAME = 'crate';
37
38
    private const VERSION_057 = '0.57.0';
39
    private const VERSION_4 = '4.0.0';
40
41
    /**
42
     * {@inheritDoc}
43
     * @return PDOConnection The database connection.
44
     */
45 12
    public function connect(
46
        #[SensitiveParameter]
47
        array $params
48
    ): PDOConnection {
49 12
        $username = $params['user'] ?? null;
50 12
        $password = $params['password'] ?? null;
51 12
        $driverOptions = $params['driver_options'] ?? [];
52 12
        return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
53
    }
54
55
    /**
56
     * Constructs the Crate PDO DSN.
57
     *
58
     * @return string The DSN.
59
     */
60 12
    private function constructPdoDsn(array $params): string
61
    {
62 12
        $dsn = self::NAME . ':';
63 12
        if (isset($params['host']) && $params['host'] != '') {
64 12
            $dsn .= $params['host'];
65
        } else {
66
            $dsn .= 'localhost';
67
        }
68 12
        $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200');
69
70 12
        return $dsn;
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76 6
    public function getDatabasePlatform(): AbstractPlatform
77
    {
78 6
        return new CratePlatform4();
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84 98
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
85
    {
86
        // Added by Doctrine 3.
87 98
        return new CrateSchemaManager($conn, $platform);
88
    }
89
90
    /**
91
     * {@inheritDoc}
92
     */
93
    public function getName(): string
94
    {
95
        return self::NAME;
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101
    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

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