adasd
This commit is contained in:
@@ -406,23 +406,32 @@ final class FxRatesService
|
||||
return $this->normalizeCurrencyApiComLatestPayload($payload, $baseCurrency, $currencies);
|
||||
}
|
||||
|
||||
$resolvedBase = $baseCurrency;
|
||||
$rates = [];
|
||||
if ($this->provider() === 'currencyapi') {
|
||||
$resolvedBase = $this->normalizeCurrency((string) ($payload['base'] ?? $payload['base_currency'] ?? ($payload['query']['base_currency'] ?? 'USD')));
|
||||
if ($resolvedBase === '') {
|
||||
$resolvedBase = 'USD';
|
||||
}
|
||||
if (($payload['valid'] ?? false) !== true || !is_array($payload['rates'] ?? null)) {
|
||||
throw new \RuntimeException($this->extractProviderError($payload, 'FX-Kurse konnten nicht geladen werden.'));
|
||||
}
|
||||
foreach ($payload['rates'] as $code => $rate) {
|
||||
$code = $this->normalizeCurrency((string) $code);
|
||||
if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) {
|
||||
if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) {
|
||||
continue;
|
||||
}
|
||||
$rates[$code] = (float) $rate;
|
||||
}
|
||||
} else {
|
||||
$resolvedBase = $this->normalizeCurrency((string) ($payload['base'] ?? $payload['base_currency'] ?? $baseCurrency));
|
||||
if ($resolvedBase === '') {
|
||||
$resolvedBase = $baseCurrency;
|
||||
}
|
||||
$rawRates = is_array($payload['rates'] ?? null) ? $payload['rates'] : [];
|
||||
foreach ($rawRates as $code => $rate) {
|
||||
$code = $this->normalizeCurrency((string) $code);
|
||||
if ($code === '' || $code === $baseCurrency || !is_numeric($rate)) {
|
||||
if ($code === '' || $code === $resolvedBase || !is_numeric($rate)) {
|
||||
continue;
|
||||
}
|
||||
$rates[$code] = (float) $rate;
|
||||
@@ -441,7 +450,7 @@ final class FxRatesService
|
||||
}
|
||||
|
||||
return [
|
||||
'base' => $baseCurrency,
|
||||
'base' => $resolvedBase,
|
||||
'date' => $payload['updated'] ?? $payload['date'] ?? null,
|
||||
'rates' => $rates,
|
||||
];
|
||||
@@ -706,7 +715,7 @@ final class FxRatesService
|
||||
{
|
||||
$fromAt = $this->normalizeTimestamp($from);
|
||||
$toAt = $this->normalizeTimestamp($to);
|
||||
$candidates = array_reverse($this->repository->listRecentFetches(max($limit * 4, 50)));
|
||||
$candidates = $this->repository->listRecentFetches(max($limit * 4, 50));
|
||||
$result = [];
|
||||
|
||||
foreach ($candidates as $fetch) {
|
||||
|
||||
@@ -272,7 +272,7 @@ final class FxRatesRepository
|
||||
$params['to_at'] = $to;
|
||||
}
|
||||
|
||||
$sql .= ' ORDER BY f.fetched_at ASC, r.id ASC LIMIT :limit';
|
||||
$sql .= ' ORDER BY f.fetched_at DESC, r.id DESC LIMIT :limit';
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
foreach ($params as $key => $value) {
|
||||
$stmt->bindValue(':' . $key, $value);
|
||||
|
||||
Reference in New Issue
Block a user