Completed
Push — develop ( 15ec3c...8b62a8 )
by Baptiste
02:19
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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Compose\Compilation;
5
6
use Innmind\Compose\{
7
    Compilation\Service\Constructor,
8
    Definition\Service as Definition,
9
    Definition\Name
10
};
11
12
final class Service
13
{
14
    private $definition;
15
    private $constructor;
16
    private $property;
17
    private $method;
18
19 10
    public function __construct(Definition $service, Constructor $constructor)
20
    {
21 10
        $this->definition = $service;
22 10
        $this->constructor = $constructor;
23 10
        $this->property = new PropertyName($service->name());
24 10
        $this->method = new MethodName($service->name());
25 10
    }
26
27 5
    public function accessible(): bool
28
    {
29 5
        return $this->definition->exposed();
30
    }
31
32 5
    public function name(): Name
33
    {
34 5
        return $this->definition->exposedAs();
35
    }
36
37 5
    public function property(): PropertyName
38
    {
39 5
        return $this->property;
40
    }
41
42 5
    public function method(): MethodName
43
    {
44 5
        return $this->method;
45
    }
46
47 5
    public function __toString(): string
48
    {
49
        $code = <<<PHP
50 5
    public function {$this->method}(): object
51
    {
52 5
        return \$this->{$this->property} ?? \$this->{$this->property} = {$this->constructor};
53
    }
54
PHP;
55
56 5
        return $code;
57
    }
58
}
59