Completed
Push — develop ( f8d1c0...c6d734 )
by Baptiste
02:31
created

Set   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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