Completed
Pull Request — master (#13)
by Nikola
01:52
created

BaseIdentifier::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Version\Identifier;
6
7
use Version\Exception\InvalidIdentifierValueException;
8
9
/**
10
 * @author Nikola Posa <[email protected]>
11
 */
12
abstract class BaseIdentifier implements Identifier
13
{
14
    /**
15
     * @var string
16
     */
17
    private $value;
18
19 40
    protected function __construct(string $value)
20
    {
21 40
        $this->value = $value;
22 40
    }
23
24
    /**
25
     * @param string $value
26
     * @return static
27
     * @throws InvalidIdentifierValueException
28
     */
29 42
    public static function create(string $value) : Identifier
30
    {
31 42
        if ('' === $value) {
32 1
            throw new InvalidIdentifierValueException('Identifier must not be empty');
33
        }
34
35 42
        static::validate($value);
36
37 40
        return new static($value);
38
    }
39
40
    /**
41
     * @param string $value
42
     * @throws InvalidIdentifierValueException
43
     */
44
    protected static function validate(string $value) : void
45
    {
46
    }
47
48 42
    public function getValue() : string
49
    {
50 42
        return $this->value;
51
    }
52
53 16
    public function __toString() : string
54
    {
55 16
        return $this->getValue();
56
    }
57
}
58