SingletonsPool   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 6
eloc 5
c 5
b 0
f 1
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __wakeup() 0 2 1
A __construct() 0 2 1
A __clone() 0 2 1
A getInstance() 0 7 2
A __sleep() 0 2 1
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