Passed
Push — master ( ccb7a3...c8f838 )
by Gabriel
01:35
created

Container::detect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace Nip\Utility;
4
5
use Exception;
6
use Psr\Container\ContainerInterface;
7
use Nip\Container\Container as NipContainer;
8
9
/**
10
 * Class Container
11
 * @package Nip\Utility
12
 */
13
class Container
14
{
15
    /**
16
     * @return false|ContainerInterface|NipContainer
17
     * @noinspection PhpDocMissingThrowsInspection
18
     */
19 1
    public static function container()
20
    {
21 1
        static $instance;
22 1
        if (!($instance instanceof ContainerInterface)) {
23
            /** @noinspection PhpUnhandledExceptionInspection */
24 1
            $instance = static::detect();
25
        }
26 1
        return $instance;
27
    }
28
29
    /**
30
     * @return ContainerInterface
31
     * @throws Exception
32
     */
33 1
    public static function detect()
34
    {
35 1
        if (class_exists(NipContainer::class)) {
36 1
            return NipContainer::getInstance();
37
        }
38
        throw new Exception("No valid container found");
39
    }
40
41
    /**
42
     * @param null $make
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $make is correct as it would always require null to be passed?
Loading history...
43
     * @param array $parameters
44
     * @return false|ContainerInterface
45
     */
46
    public static function get($make = null, $parameters = [])
47
    {
48
        if (is_null($make)) {
0 ignored issues
show
introduced by
The condition is_null($make) is always true.
Loading history...
49
            return static::container();
50
        }
51
52
        return static::container()->get($make, $parameters);
53
    }
54
}
55