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

Factory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 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\Str;
11
12
final class Factory implements Constructor
13
{
14
    private $class;
15
    private $method;
16
17 2
    private function __construct(string $class, string $method)
18
    {
19 2
        $this->class = $class;
20 2
        $this->method = $method;
21 2
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 8
    public static function fromString(Str $value): Constructor
27
    {
28 8
        if (!$value->matches('~^\S+::\S+$~')) {
29 6
            throw new ValueNotSupported((string) $value);
30
        }
31
32 2
        [$class, $method] = $value->split('::');
33
34 2
        return new self((string) $class, (string) $method);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function __invoke(...$arguments): object
41
    {
42 1
        return [$this->class, $this->method](...$arguments);
43
    }
44
}
45