| Total Complexity | 11 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 76% |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 7 | final class ConnectionManager |
||
| 8 | { |
||
| 9 | private static $defaultConnection; |
||
| 10 | /** @var Connection[] */ |
||
| 11 | private static $connections = []; |
||
| 12 | |||
| 13 | 49 | public static function release(): void |
|
| 21 | 49 | } |
|
| 22 | |||
| 23 | 49 | public static function register(Connection $connection, string $name = 'default'): void |
|
| 24 | { |
||
| 25 | 49 | if (!self::hasDefault()) { |
|
| 26 | 49 | self::$defaultConnection = $connection; |
|
| 27 | } |
||
| 28 | |||
| 29 | 49 | if (self::has($name)) { |
|
| 30 | throw StorageException::forAlreadyExistingConnection($name); |
||
| 31 | } |
||
| 32 | |||
| 33 | 49 | self::$connections[$name] = $connection; |
|
| 34 | 49 | } |
|
| 35 | |||
| 36 | 49 | public static function has(string $name): bool |
|
| 37 | { |
||
| 38 | 49 | return isset(self::$connections[$name]); |
|
| 39 | } |
||
| 40 | |||
| 41 | 49 | public static function hasDefault(): bool |
|
| 42 | { |
||
| 43 | 49 | return self::$defaultConnection !== null; |
|
| 44 | } |
||
| 45 | |||
| 46 | public static function getDefault(): Connection |
||
| 52 | } |
||
| 53 | |||
| 54 | 22 | public static function get(string $name): Connection |
|
| 61 | } |
||
| 62 | } |
||
| 63 |