Passed
Push — develop ( 7d2249...4ccadf )
by Baptiste
02:09
created

Set::__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\Definition\Service\Constructor;
5
6
use Innmind\Compose\{
7
    Definition\Service\Constructor,
8
    Exception\ValueNotSupported,
9
    Lazy\Set as LazySet
10
};
11
use Innmind\Immutable\Str;
12
13
final class Set implements Constructor
14
{
15
    private $type;
16
17 6
    private function __construct(string $type)
18
    {
19 6
        $this->type = $type;
20 6
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 12
    public static function fromString(Str $value): Constructor
26
    {
27 12
        if (!$value->matches('~^set<\S+>$~')) {
28 9
            throw new ValueNotSupported((string) $value);
29
        }
30
31 6
        $components = $value->capture('~^set<(?<type>\S+)>$~');
32
33 6
        return new self((string) $components->get('type'));
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    public function __invoke(...$arguments): object
40
    {
41 3
        return LazySet::of($this->type, ...$arguments);
42
    }
43
44 2
    public function __toString(): string
45
    {
46 2
        return sprintf('set<%s>', $this->type);
47
    }
48
}
49