Container   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A __construct() 0 3 1
A get() 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-2019 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 64
    public function __construct(iterable $config = [], ?ContainerInterface $parent = null)
29
    {
30 64
        $this->container = new RuntimeContainer($config, $parent, $this);
31 64
    }
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 59
    public function get($name)
45
    {
46 59
        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