Passed
Branch v0.1 (e1d14a)
by Nestor
01:33
created

MySQLConfiguration::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cozy\Database\Relational\Configuration;
6
7
class MySQLConfiguration implements ConfigurationInterface
8
{
9
    use TCPConfigurationTrait;
0 ignored issues
show
Bug introduced by
The trait Cozy\Database\Relational...n\TCPConfigurationTrait requires the property $errorInfo which is not provided by Cozy\Database\Relational...tion\MySQLConfiguration.
Loading history...
10
11
    /**
12
     *  Creates a configuration set representing a connection to a database.
13
     *
14
     * @param string $host The hostname on which the database server resides.
15
     * @param int $port The port number where the database server is listening (default is 3306).
16
     * @param string $database The name of the database.
17
     * @param string $username The user name for the DSN string. This parameter is optional for some PDO drivers.
18
     * @param string $password The password for the DSN string. This parameter is optional for some PDO drivers.
19
     * @param string $charset The character set.
20
     * @param array $options A key=>value array of PDO driver-specific connection options.
21
     */
22
    public function __construct(
23
        string $host,
24
        int $port,
25
        string $database,
26
        string $username,
27
        string $password,
28
        string $charset = null,
29
        array $options = []
30
    ) {
31
        $dsn = "mysql:host={$host};port={$port};dbname={$database}";
32
33
        if (isset($charset)) {
34
            $dsn .= ";charset={$charset}";
35
        }
36
37
        $this->dsn = $dsn;
38
        $this->host = $host;
39
        $this->port = $port;
40
        $this->username = $username;
41
        $this->password = $password;
42
        $this->options = array_merge($this->options, $options);
43
    }
44
}
45