Passed
Push — master ( 29ab56...8d88d2 )
by Andy
01:17
created

AbstractPeriod   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 26
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIntervalCode() 0 3 1
A getDateFormat() 0 10 2
A toArray() 0 3 1
1
<?php
2
3
namespace Palmtree\Chrono\Option;
4
5
abstract class AbstractPeriod
6
{
7
    abstract protected static function getIntervalCodes(): array;
8
9
    abstract protected static function getDateFormats(): array;
10
11 4
    public static function getIntervalCode(string $period): string
12
    {
13 4
        return static::getIntervalCodes()[$period];
14
    }
15
16 15
    public static function getDateFormat(string $period): string
17
    {
18 15
        $formats = static::getDateFormats();
19
20 15
        if (!isset($formats[$period])) {
21 1
            $keys = implode("','", array_keys($formats));
22 1
            throw new \InvalidArgumentException("Period must be one of '$keys'. $period given");
23
        }
24
25 14
        return $formats[$period];
26
    }
27
28
    public static function toArray(): array
29
    {
30
        return array_keys(static::getIntervalCodes());
31
    }
32
}
33