Passed
Push — master ( 12c564...fbc502 )
by Petr
08:15
created

MultitonInstances::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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
    protected static ?MultitonInstances $instance = null;
17
    protected Multiton $multi;
18
19 1
    public static function init(?Interfaces\IStTranslations $lang = null): void
20
    {
21 1
        static::$instance = new self($lang);
22
    }
23
24 2
    public static function getInstance(?Interfaces\IStTranslations $lang = null): Multiton
25
    {
26 2
        if (empty(static::$instance)) {
27 2
            static::$instance = new self($lang);
28
        }
29 2
        return static::$instance->multi;
30
    }
31
32 2
    protected function __construct(?Interfaces\IStTranslations $lang = null)
33
    {
34 2
        $this->multi = new Multiton($lang);
35
    }
36
37
    /**
38
     * @codeCoverageIgnore singleton
39
     */
40
    private function __clone()
41
    {
42
        // cannot run
43
    }
44
}
45