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

Container::resolve()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8.0231

Importance

Changes 0
Metric Value
cc 8
eloc 13
nc 8
nop 1
dl 0
loc 27
ccs 13
cts 14
cp 0.9286
crap 8.0231
rs 5.3846
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Container::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