Passed
Push — master ( 9b125d...f5b0c0 )
by Alexander
11:25 queued 07:35
created

Dsn::asString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
final class Dsn
8
{
9
    private string $databaseName;
10
    private string $driver;
11
    private string $server;
12
    private string $port;
13
14 3
    public function __construct(string $driver, string $server, string $databaseName, string $port = '1433')
15
    {
16 3
        $this->driver = $driver;
17 3
        $this->server = $server;
18 3
        $this->databaseName = $databaseName;
19 3
        $this->port = $port;
20
    }
21
22
    /**
23
     * @return string the Data Source Name, or DSN, contains the information required to connect to the database.
24
     * Please refer to the [PHP manual](http://php.net/manual/en/pdo.construct.php) on the format of the DSN string.
25
     *
26
     * The `driver` array key is used as the driver prefix of the DSN, all further key-value pairs are rendered as
27
     * `key=value` and concatenated by `;`. For example:
28
     *
29
     * ```php
30
     * $dsn = new MssqlDsn('sqlsrv', 'localhost', 'yiitest', '1433');
31
     * $connection = new MssqlConnection($this->cache, $this->logger, $this->profiler, $dsn->asString());
32
     * ```
33
     *
34
     * Will result in the DSN string `sqlsrv:Server=localhost,1433;Database=yiitest`.
35
     */
36 2
    public function asString(): string
37
    {
38 2
        return "$this->driver:" . "Server=$this->server," . "$this->port" . ";Database=$this->databaseName";
39
    }
40
41 1
    public function __toString(): string
42
    {
43 1
        return $this->asString();
44
    }
45
46 1
    public function getDriver(): string
47
    {
48 1
        return $this->driver;
49
    }
50
}
51