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.

ConnectionConfig::getDsn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Rentgen\Database\Connection;
4
5
class ConnectionConfig implements ConnectionConfigInterface
6
{
7
    private $adapter;
8
    private $username;
9
    private $password;
10
11
    /**
12
     * Constructor.
13
     *
14
     * @param array $config Array config.
15
     */
16
    public function __construct(array $config = array())
17
    {
18
        $this->parseConfiguration($config);
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function changeEnvironment($environment)
25
    {
26
        $this->currentEnvironment = $environment;
0 ignored issues
show
Bug introduced by
The property currentEnvironment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getUsername()
33
    {
34
        return $this->username[$this->currentEnvironment];
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getPassword()
41
    {
42
        return $this->password[$this->currentEnvironment];
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getDsn()
49
    {
50
        return $this->dsn[$this->currentEnvironment];
0 ignored issues
show
Bug introduced by
The property dsn does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51
    }
52
53
    /**
54
     * Get database adapter.
55
     *
56
     * @return string
57
     */
58
    public function getAdapter()
59
    {
60
        return $this->adapter[$this->currentEnvironment];
61
    }
62
63
    /**
64
     * Parse configuration.
65
     *
66
     * @param array $config
67
     * @return void
68
     */
69
    private function parseConfiguration(array $config)
70
    {
71
        $this->currentEnvironment = 'dev';
72
        foreach($config as $environment => $connection) {
73
            if (isset($connection['dsn'])) {
74
                $this->dsn[$environment]  = $connection['dsn'];
75
            } else {
76
                $this->dsn[$environment]= sprintf('pgsql:host=%s; port=%s; dbname=%s;'
77
                    , $connection['host']
78
                    , $connection['port']
79
                    , $connection['database']);
80
81
            }
82
            //$this->adapter[$environment] = $connection['adapter'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
            $this->username[$environment] = $connection['username'];
84
            $this->password[$environment] = $connection['password'];
85
        }
86
    }
87
}
88