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

BaseIdentifier::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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