Passed
Push — master ( 96eda9...4e4eee )
by Petr
07:51
created

MultitonInstances::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace kalanis\kw_storage\Access;
4
5
6
use kalanis\kw_storage\Interfaces;
7
8
9
/**
10
 * Class MultitonInstances
11
 * @package kalanis\kw_storage\Access
12
 * Multiple storages via one access point; Instances of each
13
 */
14
class MultitonInstances
15
{
16
    /** @var MultitonInstances|null */
17
    protected static $instance = null;
18
    /** @var Multiton */
19
    protected $multi = null;
20
21 1
    public static function init(?Interfaces\IStTranslations $lang = null): void
22
    {
23 1
        static::$instance = new self($lang);
24 1
    }
25
26 1
    public static function getInstance(): Multiton
27
    {
28 1
        if (empty(static::$instance)) {
29 1
            static::$instance = new self();
30
        }
31 1
        return static::$instance->multi;
32
    }
33
34 1
    protected function __construct(?Interfaces\IStTranslations $lang = null)
35
    {
36 1
        $this->multi = new Multiton($lang);
37 1
    }
38
39
    /**
40
     * @codeCoverageIgnore singleton
41
     */
42
    private function __clone()
43
    {
44
        // cannot run
45
    }
46
}
47