Passed
Push — master ( aa1e46...8f73fe )
by n
01:50
created

ContainerBagLocator::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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