AbstractPeriods   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

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