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 ( e37998...5f8196 )
by Benjamin
02:57
created

Connection   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createDsn() 0 9 3
A __construct() 0 11 1
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 1
    public function __construct()
13
    {
14 1
        $parser = new Parser();
15 1
        $config = $parser->parseFile(__DIR__.'/../../../../config/config.yml')['database'];
16 1
        $params = $this->createParams($config);
17 1
        parent::__construct(
18 1
            $params['dsn'],
19 1
            $params['username'] ?? '',
20 1
            $params['password'] ?? '',
21
            [
22 1
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
23
            ]
24
        );
25 1
    }
26
27
28 1
    private function createParams($config)
29
    {
30
        $params = [
31 1
            'dsn' => ($config['type'] ?? 'mysql').':'
32
        ];
33
34 1
        foreach ($config as $key => $val) {
35 1
            if (!\in_array($key, self::KEYS)) {
36 1
                if (\in_array($key, ['username', 'password'])) {
37 1
                    $params[$key] = $val;
38
                }
39 1
                unset($config[$key]);
40
            }
41
        }
42 1
        $params['dsn'] .= $this->createDsn($config);
43 1
        return $params;
44
    }
45
46 1
    private function createDsn($config)
47
    {
48 1
        $dsn = '';
49 1
        foreach (self::KEYS as $key) {
50 1
            if (isset($config[$key])) {
51 1
                $dsn .= "{$key}={$config[$key]};";
52
            }
53
        }
54 1
        return $dsn;
55
    }
56
}
57