mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Code cleanup
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Binder;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
|
@@ -26,7 +26,6 @@ namespace FireflyIII\Support\Form;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use Form;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
/**
|
||||
* Class RuleForm
|
||||
|
@@ -26,10 +26,7 @@ namespace FireflyIII\Support\Http\Api;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTimeInterface;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
|
||||
/**
|
||||
* Trait ConvertsExchangeRates
|
||||
|
@@ -58,7 +58,7 @@ class Navigation
|
||||
*/
|
||||
public function addPeriod(Carbon $theDate, string $repeatFreq, int $skip = 0): Carbon
|
||||
{
|
||||
$date = clone $theDate;
|
||||
$date = clone $theDate;
|
||||
$functionMap = [
|
||||
'1D' => Periodicity::Daily,
|
||||
'daily' => Periodicity::Daily,
|
||||
@@ -351,8 +351,13 @@ class Navigation
|
||||
*/
|
||||
public function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int
|
||||
{
|
||||
app('log')->debug(sprintf('diffInPeriods: %s (skip: %d), between %s and %s.',
|
||||
$period, $skip, $beginning->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
app('log')->debug(sprintf(
|
||||
'diffInPeriods: %s (skip: %d), between %s and %s.',
|
||||
$period,
|
||||
$skip,
|
||||
$beginning->format('Y-m-d'),
|
||||
$end->format('Y-m-d')
|
||||
));
|
||||
$map = [
|
||||
'daily' => 'floatDiffInDays',
|
||||
'weekly' => 'floatDiffInWeeks',
|
||||
@@ -370,11 +375,11 @@ class Navigation
|
||||
$diff = $beginning->$func($end);
|
||||
|
||||
// then correct for quarterly or half-year
|
||||
if('quarterly' === $period) {
|
||||
if ('quarterly' === $period) {
|
||||
app('log')->debug(sprintf('Q: Corrected %f to %f', $diff, $diff / 3));
|
||||
$diff = $diff / 3;
|
||||
}
|
||||
if('half-year' === $period) {
|
||||
if ('half-year' === $period) {
|
||||
app('log')->debug(sprintf('H: Corrected %f to %f', $diff, $diff / 6));
|
||||
$diff = $diff / 6;
|
||||
}
|
||||
@@ -384,11 +389,15 @@ class Navigation
|
||||
|
||||
app('log')->debug(sprintf('Diff is %f (%d)', $beginning->$func($end), $diff));
|
||||
|
||||
if($skip > 0) {
|
||||
if ($skip > 0) {
|
||||
$parameter = $skip + 1;
|
||||
$diff = ceil($diff / $parameter) * $parameter;
|
||||
app('log')->debug(sprintf('diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
|
||||
$skip, $parameter, $diff));
|
||||
$diff = ceil($diff / $parameter) * $parameter;
|
||||
app('log')->debug(sprintf(
|
||||
'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',
|
||||
$skip,
|
||||
$parameter,
|
||||
$diff
|
||||
));
|
||||
}
|
||||
|
||||
return (int)$diff;
|
||||
|
@@ -60,7 +60,7 @@ class Preferences
|
||||
*/
|
||||
public function get(string $name, $default = null): ?Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
/** @var User|null $user */
|
||||
@@ -85,7 +85,7 @@ class Preferences
|
||||
*/
|
||||
public function getForUser(User $user, string $name, $default = null): ?Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']);
|
||||
@@ -114,7 +114,7 @@ class Preferences
|
||||
*/
|
||||
public function delete(string $name): bool
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$fullName = sprintf('preference%s%s', auth()->user()->id, $name);
|
||||
@@ -132,7 +132,7 @@ class Preferences
|
||||
*/
|
||||
public function forget(User $user, string $name): void
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$key = sprintf('preference%s%s', $user->id, $name);
|
||||
@@ -150,7 +150,7 @@ class Preferences
|
||||
*/
|
||||
public function setForUser(User $user, string $name, $value): Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$fullName = sprintf('preference%s%s', $user->id, $name);
|
||||
@@ -200,7 +200,7 @@ class Preferences
|
||||
*/
|
||||
public function findByName(string $name): Collection
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
return Preference::where('name', $name)->get();
|
||||
@@ -238,7 +238,7 @@ class Preferences
|
||||
*/
|
||||
public function getFresh(string $name, $default = null): ?Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
/** @var User|null $user */
|
||||
@@ -264,7 +264,7 @@ class Preferences
|
||||
*/
|
||||
public function getFreshForUser(User $user, string $name, $default = null): ?Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
return $this->getForUser($user, $name, $default);
|
||||
@@ -307,7 +307,7 @@ class Preferences
|
||||
*/
|
||||
public function set(string $name, $value): Preference
|
||||
{
|
||||
if('currencyPreference' === $name) {
|
||||
if ('currencyPreference' === $name) {
|
||||
throw new FireflyException('No longer supports "currencyPreference", please refactor me.');
|
||||
}
|
||||
$user = auth()->user();
|
||||
|
@@ -34,8 +34,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\User;
|
||||
use Gdbots\QueryParser\Enum\BoolOperator;
|
||||
|
Reference in New Issue
Block a user