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

Extension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 45
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
validate() 0 1 ?
A from() 0 4 1
A fromString() 0 4 1
A getIdentifiers() 0 4 1
A toString() 0 4 1
A __toString() 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