Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
20.00% |
1 / 5 |
CRAP | |
63.64% |
7 / 11 |
App\Models\DatabaseConfiguration | |
0.00% |
0 / 1 |
|
20.00% |
1 / 5 |
7.73 | |
63.64% |
7 / 11 |
__construct | |
0.00% |
0 / 1 |
2.01 | |
85.71% |
6 / 7 |
|||
getHost | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getUsername | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getPassword | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getDatabaseName | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
<?php | |
/* | |
* Possible Design Pattern to struture Database configurations | |
* | |
*/ | |
namespace App\Models; | |
class DatabaseConfiguration { | |
/** | |
* | |
* @var string | |
*/ | |
private $host; | |
/** | |
* | |
* @var string | |
*/ | |
private $username; | |
/** | |
* | |
* @var string | |
*/ | |
private $password; | |
/** | |
* | |
* @var string | |
*/ | |
private $databaseName; | |
private $settings = [ | |
'mysql' => [ | |
'host' => 'aa1rrnd1rg2act5.cndne0sg2du0.eu-west-1.rds.amazonaws.com', | |
'user' => 'azubiopfers', | |
'password' => 'burnbabyburn', | |
'name' => 'azubi-shop' | |
] | |
]; | |
/** | |
* | |
* @param string $connectionName | |
*/ | |
public function __construct($connectionName) { | |
if (!isset($this->settings[$connectionName])) { | |
throw new Exception('Wrong connection name!'); | |
} | |
$this->host = $this->settings[$connectionName]['host']; | |
$this->password = $this->settings[$connectionName]['password']; | |
$this->username = $this->settings[$connectionName]['user']; | |
$this->databaseName = $this->settings[$connectionName]['name']; | |
} | |
public function getHost() { | |
return $this->host; | |
} | |
public function getUsername() { | |
return $this->username; | |
} | |
public function getPassword() { | |
return $this->password; | |
} | |
public function getDatabaseName() { | |
return $this->databaseName; | |
} | |
} |