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

SplEnumSingletonTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 7 2
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