Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

StorageSingleton   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getInstance() 0 6 2
A __clone() 0 2 1
A getStorage() 0 9 2
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Storage;
4
5
6
use kalanis\kw_storage\Interfaces\IStorage;
7
use kalanis\kw_storage\Storage as Store;
8
9
10
/**
11
 * Class StorageSingleton
12
 * @package kalanis\kw_mapper\Storage\Storage
13
 * Singleton to access storage across the mappers
14
 */
15
class StorageSingleton
16
{
17
    /** @var self|null */
18
    protected static $instance = null;
19
    /** @var IStorage|null */
20
    private $storage = null;
21
22 13
    public static function getInstance(): self
23
    {
24 13
        if (empty(static::$instance)) {
25 1
            static::$instance = new self();
26
        }
27 13
        return static::$instance;
28
    }
29
30 1
    protected function __construct()
31
    {
32 1
    }
33
34
    /**
35
     * @codeCoverageIgnore why someone would run that?!
36
     */
37
    private function __clone()
38
    {
39
    }
40
41 13
    public function getStorage(): IStorage
42
    {
43 13
        if (empty($this->storage)) {
44 1
            $this->storage = new Store\Storage(
45 1
                new Store\Key\DefaultKey(),
46 1
                new Store\Target\Volume()
47 1
            );
48
        }
49 13
        return $this->storage;
50
    }
51
}
52