Test Failed
Push — master ( 2d1715...3b11bb )
by Raffael
03:29
created

Container   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 3 1
A make() 0 3 1
A has() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Micro\Container
7
 *
8
 * @copyright   Copryright (c) 2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     MIT https://opensource.org/licenses/MIT
10
 */
11
12
namespace Micro\Container;
13
14
use Psr\Container\ContainerInterface;
15
16
class Container implements ContainerInterface
17
{
18
    /**
19
     * Container.
20
     *
21
     * @var RuntimeContainer
22
     */
23
    protected $container;
24
25
    /**
26
     * Create container.
27
     */
28 54
    public function __construct(array $config = [], ?ContainerInterface $parent = null)
29
    {
30 54
        $this->container = new RuntimeContainer($config, $parent, $this);
31 54
    }
32
33
    /**
34
     * Build an entry of the container by its name.
35
     */
36 3
    public function make(string $name, array $parameters = [])
37
    {
38 3
        return $this->container->get($name, $parameters);
39
    }
40
41
    /**
42
     * Get service.
43
     */
44 49
    public function get($name)
45
    {
46 49
        return $this->container->get($name);
47
    }
48
49
    /**
50
     * Check if service is registered.
51
     */
52 3
    public function has($name): bool
53
    {
54
        try {
55 3
            $this->container->get($name);
56
57 2
            return true;
58 1
        } catch (\Exception $e) {
59 1
            return false;
60
        }
61
    }
62
}
63