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

GlobalState::flush()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Zenstruck\Foundry\Test;
4
5
use Doctrine\Persistence\ManagerRegistry;
6
use Zenstruck\Foundry\PersistenceManager;
7
use Zenstruck\Foundry\StoryManager;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class GlobalState
13
{
14
    private static array $callbacks = [];
15
16
    public static function add(callable $callback): void
17
    {
18
        self::$callbacks[] = $callback;
19
    }
20
21
    /**
22
     * @internal
23
     */
24 38
    public static function flush(ManagerRegistry $registry): void
25
    {
26 38
        StoryManager::globalReset();
27
28 38
        PersistenceManager::register($registry);
29
30 38
        foreach (self::$callbacks as $callback) {
31 38
            $callback();
32
        }
33
34 38
        StoryManager::setGlobalState();
35 38
    }
36
}
37