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

StorageSingleton::getStorage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 2
rs 10
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