Completed
Push — master ( 240c2a...797df5 )
by Nikola
02:38
created

BaseIdentifier   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 7
c 5
b 0
f 0
lcom 0
cbo 1
dl 0
loc 50
ccs 14
cts 16
cp 0.875
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 3 1
A getValue() 0 4 1
A __toString() 0 4 1
A create() 0 14 3
1
<?php
2
3
/**
4
 * This file is part of the Version package.
5
 *
6
 * Copyright (c) Nikola Posa <[email protected]>
7
 *
8
 * For full copyright and license information, please refer to the LICENSE file,
9
 * located at the package root folder.
10
 */
11
12
namespace Version\Identifier;
13
14
use Version\Exception\InvalidIdentifierValueException;
15
16
/**
17
 * @author Nikola Posa <[email protected]>
18
 */
19
abstract class BaseIdentifier implements Identifier
20
{
21
    /**
22
     * @var string
23
     */
24
    private $value;
25
26 49
    private function __construct($value)
27
    {
28 49
        $this->value = $value;
29 49
    }
30
31
    /**
32
     * @param string $value
33
     * @return static
34
     * @throws InvalidIdentifierValueException
35
     */
36 52
    public static function create($value)
37
    {
38 52
        if (!is_string($value)) {
39 1
            throw new InvalidIdentifierValueException('Identifier value must be of type string');
40
        }
41
42 51
        if ($value === '') {
43 1
            throw new InvalidIdentifierValueException('Identifier must not be empty');
44
        }
45
46 51
        static::validate($value);
47
48 49
        return new static($value);
49
    }
50
51
    /**
52
     * @param string $value
53
     * @throws InvalidIdentifierValueException
54
     */
55
    protected static function validate($value)
56
    {
57
    }
58
59 49
    public function getValue()
60
    {
61 49
        return $this->value;
62
    }
63
64 24
    public function __toString()
65
    {
66 24
        return $this->getValue();
67
    }
68
}
69