Passed
Push — env_slave ( 983dee...2fb48c )
by Akihito
01:46
created

Connection::isSame()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ExtendedPdo;
8
9
class Connection
10
{
11
    private string $dsn;
12
    private string $username;
13
    private string $password;
14
15
    /** @var array<string> */
16
    private array $options;
17
18
    /** @var array<string> */
19
    private array $queries;
20
    private ?ExtendedPdo $pdo = null;
21
22
    /**
23
     * @phpstan-param array<string> $options
24
     * @phpstan-param array<string> $queries
25
     */
26
    public function __construct(
27
        string $dsn,
28
        string $username = '',
29
        string $password = '',
30
        array $options = [],
31
        array $queries = []
32
    ) {
33
        $this->dsn = $dsn;
34
        $this->username = $username;
35
        $this->password = $password;
36
        $this->options = $options;
37
        $this->queries = $queries;
38
    }
39
40
    public function __invoke(): ExtendedPdo
41
    {
42
        if ($this->pdo instanceof ExtendedPdo) {
43
            return $this->pdo;
44
        }
45
46
        $this->pdo = new ExtendedPdo($this->dsn, $this->username, $this->password, $this->options, $this->queries);
47
48
        return $this->pdo;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->pdo returns the type null which is incompatible with the type-hinted return Aura\Sql\ExtendedPdo.
Loading history...
49
    }
50
51
    public function isSame(string $dsn, string $username, string $password): bool
52
    {
53
        return $dsn === $this->dsn &&
54
            $username === $this->username &&
55
            $password === $this->password;
56
    }
57
}
58