Completed
Push — master ( 8e5216...cac524 )
by Nikola
10s
created

BaseExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
validate() 0 1 ?
A fromIdentifiers() 0 4 1
A fromIdentifiersString() 0 4 1
A getIdentifiers() 0 4 1
A isEmpty() 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\InvalidIdentifierException;
8
9
abstract class BaseExtension
10
{
11
    protected const IDENTIFIERS_SEPARATOR = '.';
12
13
    /**
14
     * @var array
15
     */
16
    private $identifiers;
17
18 90
    protected function __construct(string ...$identifiers)
19
    {
20 90
        foreach ($identifiers as $identifier) {
21 41
            $this->validate($identifier);
22
        }
23
24 87
        $this->identifiers = $identifiers;
25 87
    }
26
27
    /**
28
     * @param string $identifier
29
     * @throws InvalidIdentifierException
30
     * @return void
31
     */
32
    abstract protected function validate(string $identifier) : void;
33
34 8
    public static function fromIdentifiers(string $firstIdentifier, string ...$identifiers)
35
    {
36 8
        return new static(...array_merge([$firstIdentifier], $identifiers));
37
    }
38
39 33
    public static function fromIdentifiersString(string $identifiers)
40
    {
41 33
        return new static(...explode(self::IDENTIFIERS_SEPARATOR, $identifiers));
42
    }
43
44 35
    public function getIdentifiers() : array
45
    {
46 35
        return $this->identifiers;
47
    }
48
49 53
    public function isEmpty() : bool
50
    {
51 53
        return empty($this->identifiers);
52
    }
53
54 16
    public function __toString() : string
55
    {
56 16
        return implode(self::IDENTIFIERS_SEPARATOR, $this->identifiers);
57
    }
58
}
59