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

Set   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromString() 0 9 2
A __invoke() 0 3 1
A __toString() 0 3 1
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