Total Complexity | 7 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | final class DefaultFormatter extends ChainableFormatter |
||
11 | { |
||
12 | private const DATE_FORMATS = [ |
||
13 | // Year |
||
14 | ['Y'], // 2018 |
||
15 | |||
16 | // Year month |
||
17 | ['y', 'n'], // 18 8 |
||
18 | ['y', 'm'], // 18 08 |
||
19 | ['y', 'M'], // 18 Aug |
||
20 | ['y', 'F'], // 18 August |
||
21 | |||
22 | // Month year |
||
23 | ['n', 'y'], // 8 18 |
||
24 | ['M', 'y'], // Aug 18 |
||
25 | ['F', 'y'], // August 18 |
||
26 | |||
27 | // Day month |
||
28 | ['j', 'n'], // 4 8 |
||
29 | ['j', 'm'], // 4 08 |
||
30 | ['j', 'M'], // 4 Aug |
||
31 | ['j', 'F'], // 4 August |
||
32 | |||
33 | // Month day |
||
34 | ['n', 'j'], // 8 4 |
||
35 | ['n', 'd'], // 8 04 |
||
36 | ['M', 'j'], // Aug 4 |
||
37 | ['M', 'd'], // Aug 04 |
||
38 | ['F', 'j'], // August 4 |
||
39 | ['F', 'd'], // August 04 |
||
40 | ]; |
||
41 | |||
42 | private const DATE_SEPARATORS = [ |
||
43 | '', |
||
44 | '-', |
||
45 | ' ', |
||
46 | '/', |
||
47 | '.', |
||
48 | ',', |
||
49 | '. ', |
||
50 | ', ', |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * @var string[] |
||
55 | */ |
||
56 | private $formats = []; |
||
57 | |||
58 | 2 | public function __construct() |
|
59 | { |
||
60 | 2 | foreach (self::DATE_FORMATS as $format) { |
|
61 | 2 | if (count($format) === 1) { |
|
62 | 2 | $this->formats[] = reset($format); |
|
63 | } else { |
||
64 | 2 | foreach (self::DATE_SEPARATORS as $separator) { |
|
65 | 2 | $this->formats[] = implode($separator, $format); |
|
66 | } |
||
67 | } |
||
68 | } |
||
69 | 2 | } |
|
70 | |||
71 | /** |
||
72 | * @param iterable<DateTimeInterface> $dates Dates to format. |
||
73 | * @return Traversable<string> The formatted dates. |
||
74 | */ |
||
75 | 2 | protected function applyCurrent(iterable $dates): Traversable |
|
80 | } |
||
81 | } |
||
84 |