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

Driver::getDatabasePlatform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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\Driver\API\ExceptionConverter;
30
use Doctrine\DBAL\Platforms\AbstractPlatform;
31
use Doctrine\DBAL\VersionAwarePlatformDriver;
32
33
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

33
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...
34
{
35
    const VERSION = '4.0.2';
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 12
     * @return PDOConnection The database connection.
44
     */
45 12
    public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
46
    {
47
        return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions);
48
    }
49
50
    /**
51
     * Constructs the Crate PDO DSN.
52
     *
53 12
     * @return string The DSN.
54
     */
55 12
    private function constructPdoDsn(array $params)
56 12
    {
57 12
        $dsn = self::NAME . ':';
58
        if (isset($params['host']) && $params['host'] != '') {
59
            $dsn .= $params['host'];
60
        } else {
61 12
            $dsn .= 'localhost';
62
        }
63 12
        $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200');
64
65
        return $dsn;
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function getDatabasePlatform()
72
    {
73
        return new CratePlatform();
74
    }
75
76
    /**
77 4
     * {@inheritDoc}
78
     */
79 4
    public function getSchemaManager(Connection $conn, AbstractPlatform $platform)
80
    {
81
        // TODO: `$platform` added when upgrading to Doctrine3 - what to do with it?
82
        return new CrateSchemaManager($conn);
0 ignored issues
show
Bug introduced by
The call to Crate\DBAL\Schema\CrateS...aManager::__construct() has too few arguments starting with platform. ( Ignorable by Annotation )

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

82
        return /** @scrutinizer ignore-call */ new CrateSchemaManager($conn);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    public function getName()
89
    {
90
        return self::NAME;
91
    }
92
93 10
    /**
94
     * {@inheritDoc}
95 10
     */
96
    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

96
    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...
97
    {
98
        return null;
99
    }
100
101 238
    /**
102
     * {@inheritDoc}
103 238
     */
104 2
    public function createDatabasePlatformForVersion($version)
105 236
    {
106 2
        if (version_compare($version, self::VERSION_057, "<")) {
107
            return new CratePlatform();
108 234
        } elseif (version_compare($version, self::VERSION_4, "<")) {
109
            return new CratePlatform1();
110
        } else {
111
            return new CratePlatform4();
112
        }
113
    }
114
115
    /**
116
     * {@inheritDoc}
117
     */
118
    public function getExceptionConverter(): ExceptionConverter
119
    {
120
        // TODO: Implement getExceptionConverter() method.
121
        //       Added when upgrading to Doctrine3.
122
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Doctrine\DBAL\Driver\API\ExceptionConverter. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
123
}
124