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

Driver::getSchemaManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
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
32
class Driver implements \Doctrine\DBAL\Driver
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(
45
        array $params,
46
        $username = null,
47
        $password = null,
48
        array $driverOptions = array(),
49
    ): PDOConnection {
50 12
        return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
51
    }
52
53
    /**
54
     * Constructs the Crate PDO DSN.
55
     *
56
     * @return string The DSN.
57
     */
58 12
    private function constructPdoDsn(array $params): string
59
    {
60 12
        $dsn = self::NAME . ':';
61 12
        if (isset($params['host']) && $params['host'] != '') {
62 12
            $dsn .= $params['host'];
63
        } else {
64
            $dsn .= 'localhost';
65
        }
66 12
        $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200');
67
68 12
        return $dsn;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 6
    public function getDatabasePlatform(): AbstractPlatform
75
    {
76 6
        return new CratePlatform4();
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82 98
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
83
    {
84
        // Added by Doctrine 3.
85 98
        return new CrateSchemaManager($conn, $platform);
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91
    public function getName(): string
92
    {
93
        return self::NAME;
94
    }
95
96
    /**
97
     * {@inheritDoc}
98
     */
99
    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

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