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

ContainerBagLocator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 34
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 2
A flush() 0 3 1
A get() 0 7 2
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