Completed
Push — master ( 4966ad...2cf3a8 )
by Derek Stephen
02:07
created

DbCredentials::__construct()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 8.8571
cc 5
eloc 6
nc 16
nop 1
crap 5
1
<?php
2
3
4
namespace Del\Common\Config;
5
6
use Del\Common\Container\RegistrationInterface;
7
use Pimple\Container;
8
9
class DbCredentials implements RegistrationInterface
10
{
11
    /** @var  array */
12
    private $credentials;
13
    
14 6
    public function __construct(array $array = null)
15
    {
16 6
        $this->credentials = [];
17 6
        $this->credentials['driver'] = $array['driver'] ?: 'pdo_mysql';
18 6
        $this->credentials['dbname'] = $array['dbname'] ?: 'delboy1978uk';
19 6
        $this->credentials['user'] = $array['user'] ?: 'dbuser';
20 6
        $this->credentials['password'] = $array['password'] ?: '[123456]';
21 6
    }
22
23
    /**
24
     * @return string
25
     */
26 1
    public function getPassword()
27
    {
28 1
        return $this->credentials['password'];
29
    }
30
31
    /**
32
     * @param string $password
33
     * @return DbCredentials
34
     */
35 1
    public function setPassword($password)
36
    {
37 1
        $this->credentials['password'] = $password;
38 1
        return $this;
39
    }
40
41
    /**
42
     * @return string
43
     */
44 1
    public function getUser()
45
    {
46 1
        return $this->credentials['user'];
47
    }
48
49
    /**
50
     * @param string $user
51
     * @return DbCredentials
52
     */
53 2
    public function setUser($user)
54
    {
55 2
        $this->credentials['user'] = $user;
56 2
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 1
    public function getDatabase()
63
    {
64 1
        return $this->credentials['dbname'];
65
    }
66
67
    /**
68
     * @param string $database
69
     * @return DbCredentials
70
     */
71 1
    public function setDatabase($database)
72
    {
73 1
        $this->credentials['dbname'] = $database;
74 1
        return $this;
75
    }
76
77
    /**
78
     * @return string
79
     */
80 1
    public function getDriver()
81
    {
82 1
        return $this->credentials['driver'];
83
    }
84
85
    /**
86
     * @param string $driver
87
     * @return DbCredentials
88
     */
89 1
    public function setDriver($driver)
90
    {
91 1
        $this->credentials['driver'] = $driver;
92 1
        return $this;
93
    }
94
95
    /**
96
     * @return array
97
     */
98 5
    public function toArray()
99
    {
100 5
        return $this->credentials;
101
    }
102
103
    /**
104
     * @param Container $c
105
     * @return Container
106
     */
107
    public function addToContainer(Container $c)
108
    {
109
        $c['db.credentials'] = $this->toArray();
110
        return $c;
111
    }
112
113
    /**
114
     * @return null
115
     */
116
    function getEntityPath()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
117
    {
118
        return null;
119
    }
120
121
    /**
122
     * @return bool
123
     */
124
    function hasEntityPath()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
125
    {
126
        return false;
127
    }
128
129
130
}