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

BaseIdentifier   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1
ccs 12
cts 14
cp 0.8571
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 10 2
A validate() 0 3 1
A getValue() 0 4 1
A __toString() 0 4 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