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