Code cleanup

This commit is contained in:
James Cole
2023-10-28 15:03:33 +02:00
parent fa920fed4e
commit 0133a7c5db
77 changed files with 575 additions and 594 deletions

View File

@@ -31,8 +31,6 @@ use FireflyIII\User;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Collection;
use NumberFormatter;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class Amount.
@@ -140,7 +138,7 @@ class Amount
return $cache->get();
}
$default = $user->currencies()->where('user_default', true)->first();
if(null === $default) {
if (null === $default) {
$default = $this->getSystemCurrency();
$user->currencies()->sync([$default->id => ['user_default' => true]]);
}
@@ -148,6 +146,15 @@ class Amount
return $default;
}
/**
* @return TransactionCurrency
*/
public function getSystemCurrency(): TransactionCurrency
{
return TransactionCurrency::where('code', 'EUR')->first();
}
/**
* @param User $user
*
@@ -162,7 +169,7 @@ class Amount
return $cache->get();
}
$default = $userGroup->currencies()->where('group_default', true)->first();
if(null === $default) {
if (null === $default) {
$default = $this->getSystemCurrency();
$userGroup->currencies()->sync([$default->id => ['group_default' => true]]);
}
@@ -171,22 +178,6 @@ class Amount
return $default;
}
/**
* @param string $value
*
* @return string
*/
private function tryDecrypt(string $value): string
{
try {
$value = Crypt::decrypt($value); // verified
} catch (DecryptException $e) {
// @ignoreException
}
return $value;
}
/**
* This method returns the correct format rules required by accounting.js,
* the library used to format amounts in charts.
@@ -328,10 +319,18 @@ class Amount
}
/**
* @return TransactionCurrency
* @param string $value
*
* @return string
*/
public function getSystemCurrency(): TransactionCurrency
private function tryDecrypt(string $value): string
{
return TransactionCurrency::where('code', 'EUR')->first();
try {
$value = Crypt::decrypt($value); // verified
} catch (DecryptException $e) {
// @ignoreException
}
return $value;
}
}