chore: code cleanup.

This commit is contained in:
James Cole
2023-05-29 13:56:55 +02:00
parent 7f7644c92f
commit 1b52147a05
295 changed files with 12418 additions and 12324 deletions

View File

@@ -92,6 +92,16 @@ class DownloadExchangeRates implements ShouldQueue
}
}
/**
* @param Carbon $date
*/
public function setDate(Carbon $date): void
{
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
}
/**
* @param TransactionCurrency $currency
* @return void
@@ -100,12 +110,12 @@ class DownloadExchangeRates implements ShouldQueue
private function downloadRates(TransactionCurrency $currency): void
{
Log::debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code));
$base = sprintf('%s/%s/%s', (string)config('cer.url'), $this->date->year, $this->date->isoWeek);
$client = new Client();
$url = sprintf('%s/%s.json', $base, $currency->code);
$base = sprintf('%s/%s/%s', (string)config('cer.url'), $this->date->year, $this->date->isoWeek);
$client = new Client();
$url = sprintf('%s/%s.json', $base, $currency->code);
try {
$res = $client->get($url);
} catch(RequestException $e) {
} catch (RequestException $e) {
app('log')->warning(sprintf('Trying to grab "%s" resulted in error "%d".', $url, $e->getMessage()));
return;
}
@@ -124,19 +134,6 @@ class DownloadExchangeRates implements ShouldQueue
$this->saveRates($currency, $date, $json['rates']);
}
private function saveRates(TransactionCurrency $currency, Carbon $date, array $rates): void
{
foreach ($rates as $code => $rate) {
$to = $this->getCurrency($code);
if (null === $to) {
Log::debug(sprintf('Currency %s is not in use, do not save rate.', $code));
continue;
}
Log::debug(sprintf('Currency %s is in use.', $code));
$this->saveRate($currency, $to, $date, $rate);
}
}
/**
* @param string $code
* @return TransactionCurrency|null
@@ -178,13 +175,16 @@ class DownloadExchangeRates implements ShouldQueue
}
}
/**
* @param Carbon $date
*/
public function setDate(Carbon $date): void
private function saveRates(TransactionCurrency $currency, Carbon $date, array $rates): void
{
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
foreach ($rates as $code => $rate) {
$to = $this->getCurrency($code);
if (null === $to) {
Log::debug(sprintf('Currency %s is not in use, do not save rate.', $code));
continue;
}
Log::debug(sprintf('Currency %s is in use.', $code));
$this->saveRate($currency, $to, $date, $rate);
}
}
}