Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
19 / 19 |
Config | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
9 | |
100.00% |
19 / 19 |
__construct | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
__get | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
__set | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
toArray | |
100.00% |
1 / 1 |
2 | |
100.00% |
8 / 8 |
|||
setKey | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
1 | <?php |
2 | namespace Qmp\Laravel\DBConnector; |
3 | |
4 | class Config |
5 | { |
6 | private $connection = [ |
7 | 'host' => null, |
8 | 'port' => null, |
9 | 'user' => null, |
10 | 'password' => null, |
11 | 'database' => null |
12 | ]; |
13 | |
14 | public function __construct(array $connection = []) |
15 | { |
16 | foreach($connection as $key => $value) { |
17 | $this->setKey($key, $value); |
18 | } |
19 | } |
20 | |
21 | public function __get($key) |
22 | { |
23 | if (array_key_exists ($key, $this->connection)) { |
24 | return $this->connection[$key]; |
25 | } |
26 | |
27 | return null; |
28 | } |
29 | |
30 | public function __set($key, $value) |
31 | { |
32 | $this->setKey($key, $value); |
33 | } |
34 | |
35 | public function toArray(array $array = []) |
36 | { |
37 | if (empty($array)) { |
38 | return $this->connection; |
39 | } |
40 | |
41 | return array_filter( |
42 | $this->connection, |
43 | function ($key) use ($array) { |
44 | return in_array($key, $array); |
45 | }, |
46 | ARRAY_FILTER_USE_KEY |
47 | ); |
48 | } |
49 | |
50 | private function setKey($key, $value) |
51 | { |
52 | if (array_key_exists ($key, $this->connection)) { |
53 | $this->connection[$key] = $value; |
54 | } |
55 | } |
56 | } |