Passed
Pull Request — master (#14)
by Wilmer
25:49 queued 10:47
created

MssqlDsn   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

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