Completed
Push — develop ( f8d1c0...c6d734 )
by Baptiste
02:31
created

Container::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Compose;
5
6
use Innmind\Compose\{
7
    Definition\Name,
8
    Exception\NotFound
9
};
10
use Innmind\Immutable\Map;
11
use Psr\Container\ContainerInterface;
12
13
final class Container implements ContainerInterface
14
{
15
    private $definitions;
16
17 7
    public function __construct(Definitions $definitions)
18
    {
19 7
        $this->definitions = $definitions;
20 7
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 5
    public function get($id): object
26
    {
27 5
        if (!$this->has($id)) {
28 3
            throw new NotFound($id);
29
        }
30
31 2
        return $this->definitions->build(new Name($id));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 6
    public function has($id): bool
38
    {
39 6
        $name = new Name($id);
40
41 6
        if (!$this->definitions->has($name)) {
42 2
            return false;
43
        }
44
45
        $definition = $this
46 5
            ->definitions
47 5
            ->get($name);
48
49 5
        if (!$definition->exposed()) {
50 2
            return false;
51
        }
52
53 4
        return $definition->isExposedAs($name);
54
    }
55
}
56