Test Failed
Push — 7.x ( bea7e1...2b11c5 )
by Adrien
08:51
created

SplEnumSingletonTrait::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
/**
4
 * Part of SplTypes package.
5
 *
6
 * (c) Adrien Loyant <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ducks\Component\SplTypes;
13
14
/**
15
 * Trait used for enum emulation
16
 *
17
 * @psalm-api
18
 */
19
trait SplEnumSingletonTrait
20
{
21
    private static array $instances = [];
22
23
    public static function getInstance(string $name): SplEnumSingletonable
24
    {
25
        if (!isset(self::$instances[$name])) {
26
            self::$instances[$name] = static::$name();
27
        }
28
29
        return self::$instances[$name];
30
    }
31
}
32