Passed
Push — master ( 829500...1175ab )
by Kevin
08:08
created

StoryManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 41
ccs 18
cts 18
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 3 1
A setGlobalState() 0 4 1
A globalReset() 0 3 1
A set() 0 3 1
A has() 0 3 2
A get() 0 7 2
1
<?php
2
3
namespace Zenstruck\Foundry;
4
5
/**
6
 * @internal
7
 *
8
 * @author Kevin Bond <[email protected]>
9
 */
10
final class StoryManager
11
{
12
    /** @var array<string, Story> */
13
    private static array $globalInstances = [];
14
15
    /** @var array<string, Story> */
16
    private static array $instances = [];
17
18 38
    public static function has(string $story): bool
19
    {
20 38
        return \array_key_exists($story, self::$globalInstances) || \array_key_exists($story, self::$instances);
21
    }
22
23 4
    public static function get(string $story): Story
24
    {
25 4
        if (\array_key_exists($story, self::$globalInstances)) {
26 2
            return self::$globalInstances[$story];
27
        }
28
29 2
        return self::$instances[$story];
30
    }
31
32 38
    public static function set(Story $story): void
33
    {
34 38
        self::$instances[\get_class($story)] = $story;
35 38
    }
36
37 38
    public static function setGlobalState(): void
38
    {
39 38
        self::$globalInstances = self::$instances;
40 38
        self::$instances = [];
41 38
    }
42
43 38
    public static function reset(): void
44
    {
45 38
        self::$instances = [];
46 38
    }
47
48 38
    public static function globalReset(): void
49
    {
50 38
        self::$globalInstances = self::$instances = [];
51 38
    }
52
}
53