Passed
Push — master ( a1d984...241d4d )
by Raffael
04:27
created

Container   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 47
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
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 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
     * @param iterable           $config
29
     * @param ContainerInterface $parent
30
     */
31 47
    public function __construct(Iterable $config = [], ?ContainerInterface $parent = null)
32
    {
33 47
        $this->container = new RuntimeContainer($config, $parent);
34 47
    }
35
36
    /**
37
     * Get service.
38
     *
39
     * @param string $name
40
     *
41
     * @return mixed
42
     */
43 45
    public function get($name)
44
    {
45 45
        return $this->container->get($name);
46
    }
47
48
    /**
49
     * Check if service is registered.
50
     *
51
     * @param string $name
52
     *
53
     * @return bool
54
     */
55 3
    public function has($name): bool
56
    {
57
        try {
58 3
            $this->container->get($name);
59
60 2
            return true;
61 1
        } catch (\Exception $e) {
62 1
            return false;
63
        }
64
    }
65
}
66