Passed
Push — 6.0 ( 4ac4e1...87e1d7 )
by Olivier
01:56
created

TimeFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve_pattern() 0 8 2
1
<?php
2
3
namespace ICanBoogie\CLDR\Dates;
4
5
/**
6
 * Time formatter.
7
 *
8
 * ```php
9
 * <?php
10
 *
11
 * namespace ICanBoogie\CLDR;
12
 *
13
 * $datetime = '2013-11-05 21:22:23';
14
 *
15
 * $format = new TimeFormatter($repository->locales['en'])->format(...);
16
 *
17
 * echo $format($datetime, DateTimeFormatLength::FULL);   // 9:22:23 PM CET
18
 * echo $format($datetime, DateTimeFormatLength::LONG);   // 9:22:23 PM CET
19
 * echo $format($datetime, DateTimeFormatLength::MEDIUM); // 9:22:23 PM
20
 * echo $format($datetime, DateTimeFormatLength::SHORT);  // 9:22 PM
21
 *
22
 * $format = new TimeFormatter($repository->locales['fr'])->format(...);
23
 *
24
 * echo $format($datetime, DateTimeFormatLength::FULL);   // 21:22:23 CET
25
 * echo $format($datetime, DateTimeFormatLength::LONG);   // 21:22:23 CET
26
 * echo $format($datetime, DateTimeFormatLength::MEDIUM); // 21:22:23
27
 * echo $format($datetime, DateTimeFormatLength::SHORT);  // 21:22
28
 * ```
29
 */
30
final class TimeFormatter extends DateTimeFormatter
31
{
32
    /**
33
     * Resolves length defined in `timeFormats` into a pattern.
34
     */
35
    protected function resolve_pattern(
36
        string|DateTimeFormatLength|DateTimeFormatId $pattern_or_length_or_id
37
    ): string {
38
        if ($pattern_or_length_or_id instanceof DateTimeFormatLength) {
39
            return $this->calendar['timeFormats'][$pattern_or_length_or_id->value];
40
        }
41
42
        return parent::resolve_pattern($pattern_or_length_or_id);
43
    }
44
}
45