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

ConnectionFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A createConnection() 0 6 1
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