SingletonsPool::getInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author  : Jagepard <[email protected]>
7
 * @license https://mit-license.org/ MIT
8
 */
9
10
namespace AntiPatterns\SingletonsPool;
11
12
final class SingletonsPool
13
{
14
    private static array $instances = [];
15
16
    /**
17
     * Gets an object instance
18
     * --------------------------
19
     * Получает экземпляр объекта
20
     *
21
     * @param  string $name
22
     * @return self
23
     */
24
    public static function getInstance(string $name): self
25
    {
26
        if (!array_key_exists($name, static::$instances)) {
0 ignored issues
show
Bug introduced by
Since $instances is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $instances to at least protected.
Loading history...
27
            static::$instances[$name] = new static;
28
        }
29
30
        return static::$instances[$name];
31
    }
32
33
    public function __construct()
34
    {
35
    }
36
37
    /**
38
     * @codeCoverageIgnore
39
     */
40
    public function __sleep()
41
    {
42
    }
43
44
    /**
45
     * @codeCoverageIgnore
46
     */
47
    public function __wakeup()
48
    {
49
    }
50
51
    /**
52
     * @codeCoverageIgnore
53
     */
54
    public function __clone()
55
    {
56
    }
57
}
58