Passed
Push — master ( 2f76b9...67ec7f )
by Aleksandr
56:58 queued 21:55
created

Connection::getNativeConnection()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 * @author    Alex Kuperwood <[email protected]>
5
 * @copyright 2025 Alex Kuperwood
6
 * @license   https://opensource.org/license/mit  The MIT License
7
 */
8
declare(strict_types=1);
9
10
namespace Kuperwood\Eav\Database;
11
12
use Kuperwood\Eav\Exception\ConnectionException;
13
use PDO;
14
15
class Connection
16
{
17
    protected static ?PDO $conn = null;
18
19
    public static function reset() : void
20
    {
21 1
        self::$conn = null;
22
    }
23 1
24
    /**
25
     * @throws ConnectionException
26
     */
27
    public static function get(?PDO $pdo = null) : PDO
28
    {
29 3
        if(self::$conn instanceof PDO) {
30
            return self::$conn;
31 3
        }
32 1
        if($pdo instanceof PDO) {
33
            self::$conn = $pdo;
34 3
            return self::$conn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::conn returns the type null which is incompatible with the type-hinted return PDO.
Loading history...
35 2
        }
36 2
        ConnectionException::undefined();
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 PDO. 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...
37
    }
38
39
}