Total Complexity | 2 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | final class Granularity extends Enum |
||
|
|||
14 | { |
||
15 | public const ALL = 'all'; |
||
16 | public const NONE = 'none'; |
||
17 | public const SECOND = 'second'; |
||
18 | public const MINUTE = 'minute'; |
||
19 | public const FIFTEEN_MINUTE = 'fifteen_minute'; |
||
20 | public const THIRTY_MINUTE = 'thirty_minute'; |
||
21 | public const HOUR = 'hour'; |
||
22 | public const DAY = 'day'; |
||
23 | public const WEEK = 'week'; |
||
24 | public const MONTH = 'month'; |
||
25 | public const QUARTER = 'quarter'; |
||
26 | public const YEAR = 'year'; |
||
27 | |||
28 | /** |
||
29 | * @param string $granularity |
||
30 | * |
||
31 | * @return string |
||
32 | * @throws InvalidArgumentException |
||
33 | */ |
||
34 | 376 | public static function validate(string $granularity): string |
|
35 | { |
||
36 | 376 | $granularity = strtolower($granularity); |
|
37 | 376 | if (!Granularity::isValidValue($granularity)) { |
|
38 | 5 | throw new InvalidArgumentException( |
|
39 | 5 | 'The given granularity is invalid: ' . $granularity . '. ' . |
|
40 | 5 | 'Allowed are: ' . implode(',', Granularity::values()) |
|
41 | ); |
||
42 | } |
||
43 | |||
44 | 372 | return $granularity; |
|
45 | } |
||
46 | } |