Version   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 34
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A buildFromString() 0 14 3
A __toString() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace CompoLab\Domain\ValueObject;
4
5
final class Version
6
{
7
    /** @var string */
8
    private $value;
9
10 13
    public function __construct(string $value)
11
    {
12 13
        $this->value = $value;
13 13
    }
14
15
    public function getValue(): string
16
    {
17
        return $this->value;
18
    }
19
20 6
    public static function buildFromString(string $string): self
21
    {
22
        // Keep tag names (eg. "v1.2.3") for versioning
23 6
        if (preg_match('/^v?\d+\.\d+\.\d+$/', $string)) {
24 3
            return new self($string);
25
        }
26
27
        // Transform version branch (eg. "2.0") to composer style (eg. "2.0.x-dev")
28 4
        if (preg_match('/^\d+\.\d+$/', $string)) {
29 2
            return new self(sprintf('%s.x-dev', $string));
30
        }
31
32
        // Transform feature branch (eg. "master") to composer style (eg. "dev-master")
33 2
        return new self(sprintf('dev-%s', $string));
34
    }
35
36 12
    public function __toString()
37
    {
38 12
        return $this->value;
39
    }
40
}
41