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

Container::has()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 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