ConnectionConfig::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Dms\MySQL\Connection;
4
5
use Janisbiz\LightOrm\Connection\AbstractConnectionConfig;
6
7
class ConnectionConfig extends AbstractConnectionConfig
8
{
9
    const ADAPTER = 'mysql';
10
11
    /**
12
     * @param string $host
13
     * @param string $username
14
     * @param string $password
15
     * @param string $dbname
16
     * @param int $port
17
     */
18
    public function __construct(string $host, string $username, string $password, string $dbname, int $port = 3306)
19
    {
20
        parent::__construct($host, $username, $password, $dbname, static::ADAPTER, $port);
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function generateDsn(): string
27
    {
28
        return \sprintf(
29
            '%s:host=%s;dbname=%s;charset=utf8mb4;port=%d',
30
            $this->adapter,
31
            $this->host,
32
            $this->dbname,
33
            $this->port
34
        );
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getAdapterConnectionClass(): string
41
    {
42
        return Connection::class;
43
    }
44
}
45