Completed
Push — master ( 0c1f67...42600e )
by Nikola
01:14
created

Extension::from()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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 40
    final protected function __construct(array $identifiers)
16
    {
17 40
        $this->validate($identifiers);
18
19 34
        $this->identifiers = $identifiers;
20 34
    }
21
22
    /**
23
     * @throws InvalidVersion
24
     */
25
    abstract protected function validate(array $identifiers): void;
26
27 8
    public static function from(string $identifier, string ...$identifiers)
0 ignored issues
show
Unused Code introduced by
The parameter $identifier is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $identifiers is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29 8
        return new static(func_get_args());
30
    }
31
32 4
    public static function fromArray(array $identifiers)
33
    {
34 4
        return new static($identifiers);
35
    }
36
37 28
    public static function fromString(string $extension)
38
    {
39 28
        return new static(explode(self::IDENTIFIERS_SEPARATOR, trim($extension)));
40
    }
41
42 29
    public function getIdentifiers(): array
43
    {
44 29
        return $this->identifiers;
45
    }
46
47 9
    public function toString(): string
48
    {
49 9
        return implode(self::IDENTIFIERS_SEPARATOR, $this->identifiers);
50
    }
51
}
52