Completed
Push — master ( 62abe7...0c1f67 )
by Nikola
01:14
created

Extension::empty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.032

2 Methods

Rating   Name   Duplication   Size   Complexity  
Extension::validate() 0 1 ?
A Extension::from() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Version\Extension;
6
7
use Version\Exception\InvalidVersion;
8
9
abstract class Extension
10
{
11
    protected const IDENTIFIERS_SEPARATOR = '.';
12
13
    private $identifiers;
14
15 38
    protected function __construct(string ...$identifiers)
16
    {
17 38
        foreach ($identifiers as $identifier) {
18 38
            $this->validate($identifier);
19
        }
20
21 34
        $this->identifiers = $identifiers;
22 34
    }
23
24
    /**
25
     * @throws InvalidVersion
26
     */
27
    abstract protected function validate(string $identifier): void;
28
29 8
    public static function from(string $identifier, string ...$identifiers)
30
    {
31 8
        return new static($identifier, ...$identifiers);
32
    }
33
34 30
    public static function fromString(string $extension)
35
    {
36 30
        return new static(...explode(self::IDENTIFIERS_SEPARATOR, $extension));
37
    }
38
39 29
    public function getIdentifiers(): array
40
    {
41 29
        return $this->identifiers;
42
    }
43
44 9
    public function toString(): string
45
    {
46 9
        return implode(self::IDENTIFIERS_SEPARATOR, $this->identifiers);
47
    }
48
49
    public function __toString(): string
50
    {
51
        return $this->toString();
52
    }
53
}
54