Multiton   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __sleep() 0 2 1
A getInstance() 0 9 2
A __wakeup() 0 2 1
A __construct() 0 2 1
A __clone() 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\Multiton;
11
12
class Multiton
13
{
14
    protected static array $instances = [];
15
16
    /**
17
     * Gets an object instance
18
     * --------------------------
19
     * Получает экземпляр объекта
20
     *
21
     * @return self
22
     */
23
    public static function getInstance(): self
24
    {
25
        $that = get_called_class();
26
27
        if (!array_key_exists($that, static::$instances)){
28
            static::$instances[$that] = new static();
29
        }
30
31
        return static::$instances[$that];
32
    }
33
34
    public function __construct()
35
    {
36
    }
37
38
    /**
39
     * @codeCoverageIgnore
40
     */
41
    public function __sleep()
42
    {
43
    }
44
45
    /**
46
     * @codeCoverageIgnore
47
     */
48
    public function __wakeup()
49
    {
50
    }
51
52
    /**
53
     * @codeCoverageIgnore
54
     */
55
    public function __clone()
56
    {
57
    }
58
}
59