Version::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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