Passed
Pull Request — master (#671)
by Wilmer
14:35 queued 12:26
created

AbstractPdoDriver::getDsn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Driver\Pdo;
6
7
use PDO;
8
9
/**
10
 * Serves as the base class for creating PDO (PHP Data Objects) drivers.
11
 *
12
 * It provides a set of common methods and properties that are implemented by the specific PDO driver classes, such as
13
 * MSSQL, Mysql, MariaDb, Oracle, PostgreSQL, and SQLite.
14
 *
15
 * @link https://www.php.net/manual/en/book.pdo.php
16
 */
17
abstract class AbstractPdoDriver implements PdoDriverInterface
18
{
19
    protected string|null $charset = null;
20
21
    public function __construct(
22
        protected string $dsn,
23
        protected string $username = '',
24
        protected string $password = '',
25
        protected array $attributes = []
26
    ) {
27
    }
28
29
    public function attributes(array $attributes): void
30
    {
31
        $this->attributes = $attributes;
32
    }
33
34
    public function createConnection(): PDO
35
    {
36
        return new PDO($this->dsn, $this->username, $this->password, $this->attributes);
37
    }
38
39
    public function charset(string|null $charset): void
40
    {
41
        $this->charset = $charset;
42
    }
43
44
    public function getCharset(): string|null
45
    {
46
        return $this->charset;
47
    }
48
49
    public function getDsn(): string
50
    {
51
        return $this->dsn;
52
    }
53
54
    public function getPassword(): string
55
    {
56
        return $this->password;
57
    }
58
59
    public function getUsername(): string
60
    {
61
        return $this->username;
62
    }
63
64
    public function password(string $password): void
65
    {
66
        $this->password = $password;
67
    }
68
69
    public function username(string $username): void
70
    {
71
        $this->username = $username;
72
    }
73
}
74