Completed
Push — develop ( 15ec3c...8b62a8 )
by Baptiste
02:19
created

Tunnel::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Compose\Definition\Service\Argument;
5
6
use Innmind\Compose\{
7
    Definition\Name,
8
    Definition\Service\Argument,
9
    Definition\Service\Arguments,
10
    Services,
11
    Compilation\Service\Argument as CompiledArgument,
12
    Compilation\Service\Argument\Tunnel as CompiledTunnel,
13
    Exception\LogicException
14
};
15
use Innmind\Immutable\StreamInterface;
16
17
final class Tunnel implements Argument
18
{
19
    private $dependency;
20
    private $argument;
21
22 13
    public function __construct(Name $dependency, Argument $argument)
23
    {
24 13
        $this->dependency = $dependency;
25 13
        $this->argument = $argument;
26 13
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public static function fromValue($value, Arguments $arguments): Argument
32
    {
33 1
        throw new LogicException('Can\'t be used outside Service::tunnel()');
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function resolve(
40
        StreamInterface $built,
41
        Services $services
42
    ): StreamInterface {
43
        return $services
44 2
            ->dependencies()
45 2
            ->extract($this->dependency, $built, $this->argument);
46
    }
47
48 3
    public function compile(): CompiledArgument
49
    {
50 3
        return new CompiledTunnel(
51 3
            $this->dependency->root(),
52 3
            $this->argument->compile()->method()
53
        );
54
    }
55
}
56