| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 85.71% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class DatabaseSingleton |
||
| 15 | { |
||
| 16 | /** @var self|null */ |
||
| 17 | protected static $instance = null; |
||
| 18 | /** @var ADatabase[] */ |
||
| 19 | private $database = []; |
||
| 20 | |||
| 21 | 52 | public static function getInstance(): self |
|
| 27 | } |
||
| 28 | |||
| 29 | 1 | protected function __construct() |
|
| 30 | { |
||
| 31 | 1 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * @codeCoverageIgnore why someone would run that?! |
||
| 35 | */ |
||
| 36 | private function __clone() |
||
| 37 | { |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param Config $config |
||
| 42 | * @throws MapperException |
||
| 43 | * @return ADatabase |
||
| 44 | */ |
||
| 45 | 52 | final public function getDatabase(Config $config): ADatabase |
|
| 46 | { |
||
| 47 | 52 | if (empty($this->database[$config->getDriver()])) { |
|
| 48 | 4 | $this->database[$config->getDriver()] = $this->getFactory()->getDatabase($config); |
|
| 49 | } |
||
| 50 | 52 | return $this->database[$config->getDriver()]; |
|
| 51 | } |
||
| 52 | |||
| 53 | 4 | protected function getFactory(): Factory |
|
| 56 | } |
||
| 57 | } |
||
| 58 |