Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -63,11 +63,11 @@ class DownloadExchangeRates implements ShouldQueue
// get all users:
/** @var UserRepositoryInterface $userRepository */
$userRepository = app(UserRepositoryInterface::class);
$this->users = $userRepository->all();
$userRepository = app(UserRepositoryInterface::class);
$this->users = $userRepository->all();
if (null !== $date) {
$newDate = clone $date;
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
app('log')->debug(sprintf('Created new DownloadExchangeRates("%s")', $this->date->format('Y-m-d')));
@@ -90,7 +90,7 @@ class DownloadExchangeRates implements ShouldQueue
public function setDate(Carbon $date): void
{
$newDate = clone $date;
$newDate = clone $date;
$newDate->startOfDay();
$this->date = $newDate;
}
@@ -101,9 +101,9 @@ class DownloadExchangeRates implements ShouldQueue
private function downloadRates(TransactionCurrency $currency): void
{
app('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);
@@ -118,14 +118,14 @@ class DownloadExchangeRates implements ShouldQueue
return;
}
$body = (string)$res->getBody();
$json = json_decode($body, true);
$body = (string)$res->getBody();
$json = json_decode($body, true);
if (false === $json || null === $json) {
app('log')->warning(sprintf('Trying to grab "%s" resulted in bad JSON.', $url));
return;
}
$date = Carbon::createFromFormat('Y-m-d', $json['date'], config('app.timezone'));
$date = Carbon::createFromFormat('Y-m-d', $json['date'], config('app.timezone'));
if (false === $date) {
return;
}
@@ -155,7 +155,7 @@ class DownloadExchangeRates implements ShouldQueue
return $this->active[$code];
}
// find it in the database.
$currency = $this->repository->findByCode($code);
$currency = $this->repository->findByCode($code);
if (null === $currency) {
app('log')->debug(sprintf('Did not find currency %s.', $code));
$this->active[$code] = null;