Completed
Push — develop ( dd2af7...2c61cc )
by Baptiste
09:23 queued 01:14
created

Service::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Compose\Definition;
5
6
use Innmind\Compose\{
7
    Definition\Service\Constructor,
8
    Definition\Service\Argument,
9
    Exception\ServiceCannotDecorateMultipleServices
10
};
11
use Innmind\Immutable\{
12
    StreamInterface,
13
    Stream
14
};
15
16
final class Service
17
{
18
    private $name;
19
    private $constructor;
20
    private $arguments;
21
    private $exposeName;
22
23 14
    public function __construct(
24
        Name $name,
25
        Constructor $constructor,
26
        Argument ...$arguments
27
    ) {
28 14
        $this->name = $name;
29 14
        $this->constructor = $constructor;
30 14
        $this->arguments = Stream::of(Argument::class, ...$arguments);
31
32 14
        $decorates = $this->arguments->filter(static function(Argument $argument): bool {
33 10
            return $argument->decorates();
34 14
        });
35
36 14
        if ($decorates->size() > 1) {
37 1
            throw new ServiceCannotDecorateMultipleServices((string) $name);
38
        }
39 13
    }
40
41 12
    public function exposeAs(Name $name): self
42
    {
43 12
        $self = clone $this;
44 12
        $self->exposeName = $name;
45
46 12
        return $self;
47
    }
48
49 12
    public function exposed(): bool
50
    {
51 12
        return $this->exposeName instanceof Name;
52
    }
53
54 12
    public function exposedAs(): Name
55
    {
56 12
        return $this->exposeName;
57
    }
58
59 4
    public function isExposedAs(Name $name): bool
60
    {
61 4
        return (string) $this->exposeName === (string) $name;
62
    }
63
64 13
    public function name(): Name
65
    {
66 13
        return $this->name;
67
    }
68
69 5
    public function constructor(): Constructor
70
    {
71 5
        return $this->constructor;
72
    }
73
74
    /**
75
     * @return StreamInterface<Argument>
76
     */
77 5
    public function arguments(): StreamInterface
78
    {
79 5
        return $this->arguments;
80
    }
81
}
82