Total Complexity | 13 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | final class RegionCurrencies implements IteratorAggregate |
||
13 | { |
||
14 | /** |
||
15 | * @phpstan-ignore-next-line |
||
16 | */ |
||
17 | public static function from(array $data): self |
||
18 | { |
||
19 | $currencies = array_values(array_map(fn($currency) => RegionCurrency::from($currency), $data)); |
||
20 | |||
21 | usort($currencies, function (RegionCurrency $a, RegionCurrency $b) { |
||
22 | if ($a->from && $b->from) { |
||
23 | return $a->from <=> $b->from; |
||
24 | } elseif ($a->to && $b->to) { |
||
25 | return $b->to <=> $a->to; |
||
26 | } |
||
27 | |||
28 | return -1; |
||
29 | }); |
||
30 | |||
31 | return new self($currencies); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param RegionCurrency[] $currencies |
||
36 | */ |
||
37 | private function __construct( |
||
38 | private readonly array $currencies |
||
39 | ) { |
||
40 | } |
||
41 | |||
42 | public function getIterator(): Traversable |
||
45 | } |
||
46 | |||
47 | public function at(string $date): ?RegionCurrency |
||
63 |