Container::has()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 2
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-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