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

BaseIdentifier::create()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 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