Completed
Push — master ( edda02...71f62c )
by Beñat
02:05
created

ConnectionFactory::createConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Infrastructure\Persistence\Sql;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
final class ConnectionFactory
18
{
19
    private $driver;
20
    private $dbName;
21
    private $host;
22
    private $port;
23
    private $username;
24
    private $password;
25
26
    public function __construct($driver, $dbName, $host, $port, $username, $password)
27
    {
28
        $this->driver = $driver;
29
        $this->dbName = $dbName;
30
        $this->host = $host;
31
        $this->port = $port;
32
        $this->username = $username;
33
        $this->password = $password;
34
    }
35
36
    public function createConnection()
37
    {
38
        $dsn = sprintf('%s:dbname=%s;host=%s;port=%s', $this->driver, $this->dbName, $this->host, $this->port);
39
40
        return new \PDO($dsn, $this->username, $this->password);
41
    }
42
}
43