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

StoryManager::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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