| Total Complexity | 8 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 88.24% |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class StorageSingleton |
||
| 17 | { |
||
| 18 | /** @var self|null */ |
||
| 19 | protected static $instance = null; |
||
| 20 | /** @var Store\Factory */ |
||
| 21 | private $factory = null; |
||
| 22 | /** @var IStorage|null */ |
||
| 23 | private $storage = null; |
||
| 24 | |||
| 25 | 15 | public static function getInstance(): self |
|
| 26 | { |
||
| 27 | 15 | if (empty(static::$instance)) { |
|
| 28 | 1 | static::$instance = new self(); |
|
| 29 | } |
||
| 30 | 15 | return static::$instance; |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | protected function __construct() |
|
| 36 | 1 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @codeCoverageIgnore why someone would run that?! |
||
| 40 | */ |
||
| 41 | private function __clone() |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param object|array<string, string|object>|string $storageParams |
||
| 47 | * @throws StorageException |
||
| 48 | * @return IStorage |
||
| 49 | */ |
||
| 50 | 15 | public function getStorage($storageParams): IStorage |
|
| 51 | { |
||
| 52 | 15 | if (empty($this->storage)) { |
|
| 53 | 4 | if (empty($storageParams)) { |
|
| 54 | 1 | throw new StorageException('Storage cannot be empty!'); |
|
| 55 | } |
||
| 56 | 3 | $this->storage = $this->factory->getStorage($storageParams); |
|
| 57 | } |
||
| 58 | 14 | return $this->storage; |
|
| 59 | } |
||
| 60 | |||
| 61 | 2 | public function clearStorage(): void |
|
| 64 | 2 | } |
|
| 65 | } |
||
| 66 |