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

Dependencies::__toString()   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\Definition\{
7
    Dependency as Definition,
8
    Name
9
};
10
use Innmind\Immutable\{
11
    Sequence,
12
    Stream,
13
    Str
14
};
15
16
final class Dependencies
17
{
18
    private $dependencies;
19
20 8
    public function __construct(Definition ...$dependencies)
21
    {
22 8
        $this->dependencies = Stream::of(Definition::class, ...$dependencies)->reduce(
23 8
            Stream::of(Dependency::class),
24 8
            static function(Stream $dependencies, Definition $dependency): Stream {
25 5
                return $dependencies->add($dependency->compile());
26 8
            }
27
        );
28 8
    }
29
30 5
    public function properties(): string
31
    {
32
        return (string) $this
33 5
            ->dependencies
34 5
            ->reduce(
35 5
                new Sequence,
36 5
                static function(Sequence $properties, Dependency $dependency): Sequence {
37 3
                    return $properties->add((string) new PropertyName($dependency->name()));
38 5
                }
39
            )
40 5
            ->map(static function(string $property): string {
41 3
                return (string) Str::of($property)
42 3
                    ->prepend('    private $')
43 3
                    ->append(';');
44 5
            })
45 5
            ->join("\n");
46
    }
47
48 5
    public function exposed(): string
49
    {
50
        return (string) $this
51 5
            ->dependencies
52 5
            ->reduce(
53 5
                new Sequence,
54 5
                static function(Sequence $exposed, Dependency $dependency): Sequence {
55 3
                    return $exposed->add($dependency->exposed());
56 5
                }
57
            )
58 5
            ->join("\n\n");
59
    }
60
61 4
    public function __toString(): string
62
    {
63 4
        return (string) $this->dependencies->join("\n");
64
    }
65
}
66