ContainerBagLocator::get()   A
last analyzed

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
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace N1215\CakeCandle;
5
6
use N1215\CakeCandle\Invoker\Invoker;
7
use Psr\Container\ContainerInterface;
8
9
final class ContainerBagLocator
10
{
11
    /**
12
     * @var ContainerBagInterface
13
     */
14
    private static $bag;
15
16
    /**
17
     * @param ContainerInterface $container
18
     */
19 7
    public static function init(ContainerInterface $container): void
20
    {
21 7
        if (self::$bag !== null) {
22 1
            throw new \LogicException('ContainerBagLocator has already been initialized.');
23
        }
24
25 7
        self::$bag = new ContainerBag($container, new Invoker($container));
26 7
    }
27
28
    /**
29
     * @return ContainerBagInterface
30
     */
31 7
    public static function get(): ContainerBagInterface
32
    {
33 7
        if (self::$bag === null) {
34 1
            throw new \LogicException('ContainerBagLocator has not been initialized.');
35
        }
36
37 6
        return self::$bag;
38
    }
39
40 8
    public static function flush(): void
41
    {
42 8
        self::$bag = null;
43 8
    }
44
}
45