GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b49a60...8078cd )
by Benjamin
02:46
created

Connection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createDsn() 0 9 3
A createParams() 0 16 4
1
<?php
2
3
namespace Lib\Db\Dbal;
4
5
use PDO;
6
use Symfony\Component\Yaml\Parser;
7
8
class Connection extends PDO
9
{
10
    const KEYS = ['host', 'port', 'dbname', 'unix_socket', 'charset'];
11
12
    public function __construct()
13
    {
14
        $parser = new Parser();
15
        $config = $parser->parseFile(__DIR__.'/../../../../config/config.yml')['database'];
16
        $params = $this->createParams($config);
17
        parent::__construct($params['dsn'], $params['username'], $params['password'], []);
18
    }
19
20
21
    public function createParams($config)
22
    {
23
        $params = [
24
            'dsn' => $config['type'].';'
25
        ];
26
27
        foreach ($config as $key => $val) {
28
            if (!\in_array($key, self::KEYS)) {
29
                if (\in_array($key, ['username', 'password'])) {
30
                    $params[$key] = $val;
31
                }
32
                unset($config[$key]);
33
            }
34
        }
35
        $params['dsn'] .= $this->createDsn($config);
36
        return $params;
37
    }
38
39
    public function createDsn($config)
40
    {
41
        $dsn = '';
42
        foreach (self::KEYS as $key) {
43
            if (isset($config[$key])) {
44
                $dsn .= "{$key}={$config[$key]};";
45
            }
46
        }
47
        return $dsn;
48
    }
49
}
50