Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetRateHandler | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Currency\Application\Query; |
| 6 | |
| 7 | use App\Currency\Application\ExchangeRateProvider; |
| 8 | use App\Shared\Domain\ValueObject\Currency; |
| 9 | use App\Shared\Domain\ValueObject\IsoDate; |
| 10 | use DateTimeImmutable; |
| 11 | |
| 12 | class GetRateHandler |
| 13 | { |
| 14 | public function __construct( |
| 15 | private readonly ExchangeRateProvider $rates, |
| 16 | ) { |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @return array{from: string, to: string, rate: float, date: string} |
| 21 | */ |
| 22 | public function handle(GetRateQuery $query): array |
| 23 | { |
| 24 | $from = new Currency($query->from); |
| 25 | $to = new Currency($query->to); |
| 26 | $on = $query->on !== null ? IsoDate::parse($query->on) : new DateTimeImmutable('today'); |
| 27 | |
| 28 | return [ |
| 29 | 'from' => $from->code(), |
| 30 | 'to' => $to->code(), |
| 31 | 'rate' => $this->rates->rate($from, $to, $on), |
| 32 | 'date' => $on->format('Y-m-d'), |
| 33 | ]; |
| 34 | } |
| 35 | } |