Skip to content

Firefly III: a personal finances manager

Fix all errors.

James Cole41ed65033646
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index d145b09f80..6ec2134679 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -9,10 +9,55 @@ parameters:
- Illuminate\Database\Eloquent\Model
reportUnmatchedIgnoredErrors: true
ignoreErrors:
+ # these are actually interesting but not right now:
+ - identifier: notIdentical.alwaysTrue
+ - identifier: method.notFound
+ - identifier: nullsafe.neverNull
+ - identifier: identical.alwaysFalse
+ - identifier: if.condNotBoolean
+ # - identifier: booleanNot.exprNotBoolean
+ - identifier: method.nonObject
+ - identifier: function.impossibleType
+ - identifier: booleanNot.exprNotBoolean
+ - identifier: ternary.condNotBoolean
+ - identifier: booleanNot.alwaysFalse
+ - identifier: booleanAnd.alwaysFalse
+ - identifier: greater.alwaysTrue
+ - identifier: function.alreadyNarrowedType
+ - identifier: booleanNot.alwaysTrue
+ - identifier: property.phpDocType
+ - identifier: nullCoalesce.offset
+ - identifier: nullCoalesce.variable
+ - identifier: larastan.noUnnecessaryCollectionCall
+ - identifier: varTag.differentVariable
+ - identifier: identical.alwaysTrue
+ - identifier: clone.nonObject
+ - identifier: assign.propertyReadOnly
+ - identifier: property.nonObject
+ - identifier: varTag.nativeType
+ - identifier: booleanAnd.leftAlwaysFalse
+ - identifier: property.onlyWritten
+ - identifier: parameter.phpDocType
+ - identifier: property.dynamicName
+ - identifier: property.unusedType
+ - identifier: staticMethod.deprecated
+ - identifier: greater.invalid
+ - identifier: instanceof.alwaysTrue
+ # ignore everything but things that BREAK
+ - identifier: property.deprecated
+ - identifier: method.deprecated
+ - identifier: cast.useless
+ - identifier: parameter.deprecatedClass
+ - identifier: method.deprecatedClass
+ - identifier: argument.type
+ - identifier: return.type
+ - identifier: assign.propertyType
+ - identifier: return.unusedType
+ - identifier: return.phpDocType
# all errors below I will never fix.
- - '#expects view-string\|null, string given#'
- - '#expects view-string, string given#'
- - "#Parameter \\#[1-2] \\$num[1-2] of function bc[a-z]+ expects numeric-string, [a-z\\-|&]+ given#"
+ # - '#expects view-string\|null, string given#'
+ # - '#expects view-string, string given#'
+ # - "#Parameter \\#[1-2] \\$num[1-2] of function bc[a-z]+ expects numeric-string, [a-z\\-|&]+ given#"
- identifier: missingType.generics # not interesting enough to fix.
-
identifier: larastan.noEnvCallsOutsideOfConfig
@@ -20,11 +65,11 @@ parameters:
- identifier: missingType.iterableValue # not interesting enough to fix.
- identifier: varTag.type # needs a custom extension for every repository, not gonna happen.
- '#Dynamic call to static method Illuminate#'
- - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#' # is custom scope
- - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#' # is custom scope
- - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#' # is to allow soft delete
- - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#' # is a custom scope
- - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#' # is to allow soft delete
+ # - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::before#' # is custom scope
+ # - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::after#' # is custom scope
+ # - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::withTrashed#' # is to allow soft delete
+ # - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\HasMany::accountTypeIn#' # is a custom scope
+ # - '#Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::withTrashed#' # is to allow soft delete
# The level 8 is the highest level. original was 5
# 7 is more than enough, higher just leaves NULL things.
diff --git a/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php b/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php
index f25a8d2cff..521b1e271c 100644
--- a/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php
+++ b/app/Listeners/Model/BudgetLimit/ProcessesBudgetLimits.php
@@ -35,6 +35,7 @@ use FireflyIII\Support\Models\AvailableBudgetCalculator;
use FireflyIII\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Log;
class ProcessesBudgetLimits implements ShouldQueue
{
diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php
index fbd4e2796f..5871f052ac 100644
--- a/app/Services/Internal/Support/CreditRecalculateService.php
+++ b/app/Services/Internal/Support/CreditRecalculateService.php
@@ -120,26 +120,6 @@ class CreditRecalculateService
}
}
- /**
- * @throws FireflyException
- */
- private function getAccountByDirection(TransactionJournal $journal, string $direction): Account
- {
- /** @var null|Transaction $transaction */
- $transaction = $journal->transactions()->where('amount', $direction, '0')->first();
- if (null === $transaction) {
- throw new FireflyException(sprintf('Cannot find "%s"-transaction of journal #%d', $direction, $journal->id));
- }
-
- /** @var null|Account $foundAccount */
- $foundAccount = $transaction->account;
- if (null === $foundAccount) {
- throw new FireflyException(sprintf('Cannot find "%s"-account of transaction #%d of journal #%d', $direction, $transaction->id, $journal->id));
- }
-
- return $foundAccount;
- }
-
private function getAmountToUse(Transaction $transaction, TransactionCurrency $accountCurrency, ?TransactionCurrency $foreignCurrency): string
{
$usedAmount = $transaction->amount;
diff --git a/app/Support/Logging/AuditProcessor.php b/app/Support/Logging/AuditProcessor.php
index 5f8f823c13..309cf46766 100644
--- a/app/Support/Logging/AuditProcessor.php
+++ b/app/Support/Logging/AuditProcessor.php
@@ -36,7 +36,7 @@ class AuditProcessor
if (auth()->check()) {
$message = sprintf(
'AUDIT: %s (%s (%s) -> %s:%s)',
- $record['message'], // @phpstan-ignore-line
+ $record['message'],
app('request')->ip(),
auth()->user()->email,
request()->method(),
@@ -48,7 +48,7 @@ class AuditProcessor
$message = sprintf(
'AUDIT: %s (%s -> %s:%s)',
- $record['message'], // @phpstan-ignore-line
+ $record['message'],
app('request')->ip(),
request()->method(),
request()->url()
diff --git a/app/Support/Observers/RecalculatesAvailableBudgetsTrait.php b/app/Support/Observers/RecalculatesAvailableBudgetsTrait.php
deleted file mode 100644
index 40cac2373c..0000000000
--- a/app/Support/Observers/RecalculatesAvailableBudgetsTrait.php
+++ /dev/null
@@ -1,232 +0,0 @@
-<?php
-
-/*
- * RecalculatesAvailableBudgetsTrait.php
- * Copyright (c) 2025 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace FireflyIII\Support\Observers;
-
-use FireflyIII\Models\AvailableBudget;
-use FireflyIII\Models\Budget;
-use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
-use FireflyIII\Support\Facades\Navigation;
-use FireflyIII\Support\Facades\Preferences;
-use FireflyIII\Support\Facades\Steam;
-use FireflyIII\User;
-use Illuminate\Support\Facades\Log;
-use Psr\Container\ContainerExceptionInterface;
-use Psr\Container\NotFoundExceptionInterface;
-use Spatie\Period\Boundaries;
-use Spatie\Period\Period;
-use Spatie\Period\Precision;
-
-trait RecalculatesAvailableBudgetsTrait
-{
- private function calculateAmount(AvailableBudget $availableBudget): void
- {
- $repository = app(BudgetLimitRepositoryInterface::class);
- $repository->setUser($availableBudget->user);
- $newAmount = '0';
- $abPeriod = Period::make($availableBudget->start_date, $availableBudget->end_date, Precision::DAY());
- Log::debug(sprintf(
- 'Now at AB #%d, ("%s" to "%s")',
- $availableBudget->id,
- $availableBudget->start_date->format('Y-m-d'),
- $availableBudget->end_date->format('Y-m-d')
- ));
- // have to recalculate everything just in case.
- $set = $repository->getAllBudgetLimitsByCurrency($availableBudget->transactionCurrency, $availableBudget->start_date, $availableBudget->end_date);
- Log::debug(sprintf('Found %d interesting budget limit(s).', $set->count()));
-
- /** @var BudgetLimit $budgetLimit */
- foreach ($set as $budgetLimit) {
- Log::debug(sprintf(
- 'Found interesting budget limit #%d ("%s" to "%s")',
- $budgetLimit->id,
- $budgetLimit->start_date->format('Y-m-d'),
- $budgetLimit->end_date->format('Y-m-d')
- ));
- // overlap in days:
- $limitPeriod = Period::make($budgetLimit->start_date, $budgetLimit->end_date, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
- // if both equal each other, amount from this BL must be added to the AB
- if ($limitPeriod->equals($abPeriod)) {
- Log::debug('This budget limit is equal to the available budget period.');
- $newAmount = bcadd($newAmount, (string) $budgetLimit->amount);
- }
- // if budget limit period is inside AB period, it can be added in full.
- if (!$limitPeriod->equals($abPeriod) && $abPeriod->contains($limitPeriod)) {
- Log::debug('This budget limit is smaller than the available budget period.');
- $newAmount = bcadd($newAmount, (string) $budgetLimit->amount);
- }
- if (!$limitPeriod->equals($abPeriod) && !$abPeriod->contains($limitPeriod) && $abPeriod->overlapsWith($limitPeriod)) {
- Log::debug('This budget limit is something else entirely!');
- $overlap = $abPeriod->overlap($limitPeriod);
- if ($overlap instanceof Period) {
- $length = $overlap->length();
- $daily = bcmul($this->getDailyAmount($budgetLimit), (string) $length);
- $newAmount = bcadd($newAmount, $daily);
- }
- }
- }
- if (0 === bccomp('0', $newAmount)) {
- Log::debug('New amount is zero, deleting AB.');
- $availableBudget->delete();
-
- return;
- }
- Log::debug(sprintf('Concluded new amount for this AB must be %s', $newAmount));
- $availableBudget->amount = Steam::bcround($newAmount, $availableBudget->transactionCurrency->decimal_places);
- $availableBudget->save();
- }
-
- private function getDailyAmount(BudgetLimit $budgetLimit): string
- {
- if (0 === $budgetLimit->id) {
- return '0';
- }
- $limitPeriod = Period::make($budgetLimit->start_date, $budgetLimit->end_date, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
- $days = $limitPeriod->length();
- $amount = bcdiv($budgetLimit->amount, (string) $days, 12);
- Log::debug(sprintf(
- 'Total amount for budget limit #%d is %s. Nr. of days is %d. Amount per day is %s',
- $budgetLimit->id,
- $budgetLimit->amount,
- $days,
- $amount
- ));
-
- return $amount;
- }
-
- private function updateAvailableBudget(BudgetLimit $budgetLimit): void
- {
- Log::debug(sprintf('Now in updateAvailableBudget(limit #%d)', $budgetLimit->id));
-
- /** @var null|Budget $budget */
- $budget = Budget::find($budgetLimit->budget_id);
- if (null === $budget) {
- Log::warning('Budget is null, probably deleted, find deleted version.');
-
- /** @var null|Budget $budget */
- $budget = Budget::withTrashed()->find($budgetLimit->budget_id);
- }
- if (null === $budget) {
- Log::warning('Budget is still null, cannot continue, will delete budget limit.');
- $budgetLimit->forceDelete();
-
- return;
- }
-
- /** @var null|User $user */
- $user = $budget->user;
-
- // sanity check. It happens when the budget has been deleted so the original user is unknown.
- if (null === $user) {
- Log::warning('User is null, cannot continue.');
- $budgetLimit->forceDelete();
-
- return;
- }
-
- // based on the view range of the user (month week quarter etc) the budget limit could
- // either overlap multiple available budget periods or be contained in a single one.
- // all have to be created or updated.
- try {
- $viewRange = Preferences::getForUser($user, 'viewRange', '1M')->data;
- } catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
- Log::error($e->getMessage());
- $viewRange = '1M';
- }
- // safety catch
- if (null === $viewRange || is_array($viewRange)) {
- $viewRange = '1M';
- }
- $viewRange = (string) $viewRange;
-
- $start = Navigation::startOfPeriod($budgetLimit->start_date, $viewRange);
- $end = Navigation::startOfPeriod($budgetLimit->end_date, $viewRange);
- $end = Navigation::endOfPeriod($end, $viewRange);
- if ($end < $start) {
- [$start, $end] = [$end, $start];
- $budgetLimit->start_date = $start;
- $budgetLimit->end_date = $end;
- $budgetLimit->saveQuietly(); // FIXME needs to be removed here, put in repository.
- }
-
- // limit period in total is:
- $limitPeriod = Period::make($start, $end, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
- Log::debug(sprintf('Limit period is from %s to %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
-
- // from the start until the end of the budget limit, need to loop!
- $current = clone $start;
- while ($current <= $end) {
- $currentEnd = Navigation::endOfPeriod($current, $viewRange);
-
- // create or find AB for this particular period, and set the amount accordingly.
- /** @var null|AvailableBudget $availableBudget */
- $availableBudget = $user
- ->availableBudgets()
- ->where('start_date', $current->format('Y-m-d'))
- ->where('end_date', $currentEnd->format('Y-m-d'))
- ->where('transaction_currency_id', $budgetLimit->transaction_currency_id)
- ->first()
- ;
-
- if (null !== $availableBudget) {
- Log::debug('Found 1 AB, will update.');
- $this->calculateAmount($availableBudget);
- }
- if (null === $availableBudget && $currentEnd->gte($current)) {
- $currentPeriod = Period::make($current, $currentEnd, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
- $daily = $this->getDailyAmount($budgetLimit);
- $amount = bcmul((string) $daily, (string) $currentPeriod->length(), 12);
-
- // no need to calculate if period is equal.
- if ($currentPeriod->equals($limitPeriod)) {
- $amount = 0 === $budgetLimit->id ? '0' : $budgetLimit->amount;
- }
- if (0 === bccomp($amount, '0')) {
- Log::debug('Amount is zero, will not create AB.');
- }
- if (0 !== bccomp($amount, '0')) {
- Log::debug(sprintf('Will create AB for period %s to %s', $current->format('Y-m-d'), $currentEnd->format('Y-m-d')));
- $availableBudget = new AvailableBudget([
- 'user_id' => $user->id,
- 'user_group_id' => $user->user_group_id,
- 'transaction_currency_id' => $budgetLimit->transaction_currency_id,
- 'start_date' => $current,
- 'start_date_tz' => $current->format('e'),
- 'end_date' => $currentEnd,
- 'end_date_tz' => $currentEnd->format('e'),
- 'amount' => $amount,
- ]);
- $availableBudget->save();
- Log::debug(sprintf('ID of new AB is #%d', $availableBudget->id));
- $this->calculateAmount($availableBudget);
- }
- }
-
- // prep for next loop
- $current = Navigation::addPeriod($current, $viewRange);
- }
- }
-}
diff --git a/app/Support/Search/QueryParser/QueryParser.php b/app/Support/Search/QueryParser/QueryParser.php
index 2ad2809611..ce9cf4c8ee 100644
--- a/app/Support/Search/QueryParser/QueryParser.php
+++ b/app/Support/Search/QueryParser/QueryParser.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Search\QueryParser;
use SensitiveParameter;
+use function Safe\preg_split;
/**
* Single-pass parser that processes query strings into structured nodes.
@@ -144,7 +145,7 @@ class QueryParser implements QueryParserInterface
$tokenUnderConstruction .= $char;
$skipNext = true;
}
- if ('' !== $tokenUnderConstruction && !$skipNext) { // @phpstan-ignore-line
+ if ('' !== $tokenUnderConstruction && !$skipNext) {
// Log::debug(sprintf('Turns out that "%s" is a field name. Reset the token.', $tokenUnderConstruction));
// If we meet a colon with a left-hand side string, we know we're in a field and are about to set up the value
$fieldName = $tokenUnderConstruction;
diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php
index dfb7896faf..c4de34ee09 100644
--- a/app/Support/Twig/General.php
+++ b/app/Support/Twig/General.php
@@ -398,7 +398,7 @@ class General extends AbstractExtension
});
}
- private function fireflyIIIConfig()
+ private function fireflyIIIConfig(): TwigFunction
{
return new TwigFunction('fireflyiiiconfig', static fn (string $string, mixed $default): mixed => FireflyConfig::get($string, $default)->data);
}
diff --git a/app/Support/Twig/Rule.php b/app/Support/Twig/Rule.php
index 2842a2510d..33335e85df 100644
--- a/app/Support/Twig/Rule.php
+++ b/app/Support/Twig/Rule.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig;
-use Config;
use Override;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -37,7 +36,7 @@ class Rule extends AbstractExtension
{
return new TwigFunction('allRuleActions', static function (): array {
// array of valid values for actions
- $ruleActions = array_keys(Config::get('firefly.rule-actions'));
+ $ruleActions = array_keys(config('firefly.rule-actions'));
$possibleActions = [];
foreach ($ruleActions as $key) {
$possibleActions[$key] = (string) trans('firefly.rule_action_'.$key.'_choice');
diff --git a/app/TransactionRules/Factory/ActionFactory.php b/app/TransactionRules/Factory/ActionFactory.php
index ca5823f478..cb0b0db334 100644
--- a/app/TransactionRules/Factory/ActionFactory.php
+++ b/app/TransactionRules/Factory/ActionFactory.php
@@ -50,7 +50,7 @@ class ActionFactory
$class = self::getActionClass($action->action_type);
Log::debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class));
- return new $class($action); // @phpstan-ignore-line
+ return new $class($action);
}
/**
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 46582c6d07..9a129baf23 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Validation;
-use Config;
use ErrorException;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -52,7 +51,6 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Safe\Exceptions\JsonException;
use ValueError;
-
use function Safe\iconv;
use function Safe\json_encode;
use function Safe\preg_match;
@@ -80,7 +78,7 @@ class FireflyValidator extends Validator
if (!is_string($value) || 6 !== strlen($value)) {
return false;
}
- $user = auth()->user();
+ $user = auth()->user();
if (null === $user) {
Log::error('No user during validate2faCode');
@@ -91,9 +89,9 @@ class FireflyValidator extends Validator
if (is_array($secret)) {
$secret = '';
}
- $secret = (string) $secret;
+ $secret = (string)$secret;
- return (bool) Facade::verifyKey($secret, $value);
+ return (bool)Facade::verifyKey($secret, $value);
}
/**
@@ -107,14 +105,13 @@ class FireflyValidator extends Validator
{
$field = $parameters[1] ?? 'id';
- if (0 === (int) $value) {
+ if (0 === (int)$value) {
return true;
}
$count = DB::table($parameters[0])
- ->where('user_id', auth()->user()->id)
- ->where($field, $value)
- ->count()
- ;
+ ->where('user_id', auth()->user()->id)
+ ->where($field, $value)
+ ->count();
return 1 === $count;
}
@@ -138,15 +135,15 @@ class FireflyValidator extends Validator
if (!is_string($value) || 6 !== strlen($value)) {
return false;
}
- $user = auth()->user();
+ $user = auth()->user();
if (null === $user) {
Log::error('No user during validate2faCode');
return false;
}
- $secret = (string) $user->mfa_secret;
+ $secret = (string)$user->mfa_secret;
- return (bool) Facade::verifyKey($secret, $value);
+ return (bool)Facade::verifyKey($secret, $value);
}
/**
@@ -253,10 +250,10 @@ class FireflyValidator extends Validator
];
// take
- $first = substr($value, 0, 4);
- $last = substr($value, 4);
- $iban = $last.$first;
- $iban = trim(str_replace($search, $replace, $iban));
+ $first = substr($value, 0, 4);
+ $last = substr($value, 4);
+ $iban = $last . $first;
+ $iban = trim(str_replace($search, $replace, $iban));
if ('' === $iban) {
return false;
}
@@ -271,7 +268,7 @@ class FireflyValidator extends Validator
return false;
}
- return 1 === (int) $checksum;
+ return 1 === (int)$checksum;
}
/**
@@ -286,7 +283,7 @@ class FireflyValidator extends Validator
/** @var mixed $compare */
$compare = $parameters[0] ?? '0';
- return bccomp((string) $value, (string) $compare) < 0;
+ return bccomp((string)$value, (string)$compare) < 0;
}
/**
@@ -301,7 +298,7 @@ class FireflyValidator extends Validator
/** @var mixed $compare */
$compare = $parameters[0] ?? '0';
- return bccomp((string) $value, (string) $compare) > 0;
+ return bccomp((string)$value, (string)$compare) > 0;
}
/**
@@ -315,7 +312,7 @@ class FireflyValidator extends Validator
{
$field = $parameters[1] ?? 'id';
- if (0 === (int) $value) {
+ if (0 === (int)$value) {
return true;
}
$count = DB::table($parameters[0])->where($field, $value)->count();
@@ -327,8 +324,8 @@ class FireflyValidator extends Validator
{
// first, get the index from this string:
$value ??= '';
- $parts = explode('.', $attribute);
- $index = (int) ($parts[1] ?? '0');
+ $parts = explode('.', $attribute);
+ $index = (int)($parts[1] ?? '0');
// get the name of the trigger from the data array:
$actionType = $this->data['actions'][$index]['type'] ?? 'invalid';
@@ -394,8 +391,8 @@ class FireflyValidator extends Validator
public function validateRuleTriggerValue(string $attribute, ?string $value = null): bool
{
// first, get the index from this string:
- $parts = explode('.', $attribute);
- $index = (int) ($parts[1] ?? '0');
+ $parts = explode('.', $attribute);
+ $index = (int)($parts[1] ?? '0');
// get the name of the trigger from the data array:
$triggerType = $this->data['triggers'][$index]['type'] ?? 'invalid';
@@ -406,14 +403,14 @@ class FireflyValidator extends Validator
}
// these trigger types need a numerical check:
- $numerical = ['amount_less', 'amount_more', 'amount_exactly'];
+ $numerical = ['amount_less', 'amount_more', 'amount_exactly'];
if (in_array($triggerType, $numerical, true)) {
return is_numeric($value);
}
// these triggers need just the word "true":
// TODO create a helper to automatically return these.
- $needTrue = [
+ $needTrue = [
'reconciled',
'has_attachments',
'has_any_category',
@@ -442,7 +439,7 @@ class FireflyValidator extends Validator
// these trigger types need a simple strlen check:
// TODO create a helper to automatically return these.
- $length = [
+ $length = [
'source_account_starts',
'source_account_ends',
'source_account_is',
@@ -471,13 +468,13 @@ class FireflyValidator extends Validator
// check if it's an existing account.
// TODO create a helper to automatically return these.
if (in_array($triggerType, ['destination_account_id', 'source_account_id'], true)) {
- return is_numeric($value) && (int) $value > 0;
+ return is_numeric($value) && (int)$value > 0;
}
// check transaction type.
// TODO create a helper to automatically return these.
if ('transaction_type' === $triggerType) {
- $count = TransactionType::where('type', ucfirst((string) $value))->count();
+ $count = TransactionType::where('type', ucfirst((string)$value))->count();
return 1 === $count;
}
@@ -508,10 +505,10 @@ class FireflyValidator extends Validator
*/
public function validateSecurePassword($attribute, ?string $value): bool
{
- $value = (string) $value;
+ $value = (string)$value;
$verify = false;
if (array_key_exists('verify_password', $this->data)) {
- $verify = 1 === (int) $this->data['verify_password'];
+ $verify = 1 === (int)$this->data['verify_password'];
}
if ($verify) {
/** @var Verifier $service */
@@ -551,7 +548,7 @@ class FireflyValidator extends Validator
if (array_key_exists('type', $this->data) && !is_array($this->data['type'])) {
Log::debug('validateUniqueAccountForUser::typeString');
- return $this->validateByAccountTypeString($value, $parameters, (string) $this->data['type']);
+ return $this->validateByAccountTypeString($value, $parameters, (string)$this->data['type']);
}
if (array_key_exists('account_type_id', $this->data)) {
Log::debug('validateUniqueAccountForUser::typeId');
@@ -562,7 +559,7 @@ class FireflyValidator extends Validator
if (null !== $parameterId) {
Log::debug('validateUniqueAccountForUser::paramId');
- return $this->validateByParameterId((int) $parameterId, $value);
+ return $this->validateByParameterId((int)$parameterId, $value);
}
if (array_key_exists('id', $this->data)) {
Log::debug('validateUniqueAccountForUser::accountId');
@@ -587,24 +584,23 @@ class FireflyValidator extends Validator
*/
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
{
- $accountId = (int) ($this->data['id'] ?? 0.0);
+ $accountId = (int)($this->data['id'] ?? 0.0);
if (0 === $accountId) {
- $accountId = (int) ($parameters[0] ?? 0.0);
+ $accountId = (int)($parameters[0] ?? 0.0);
}
- $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
- ->whereNull('accounts.deleted_at')
- ->where('accounts.user_id', auth()->user()->id)
- ->where('account_meta.name', 'account_number')
- ->where('account_meta.data', json_encode($value))
- ;
+ $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
+ ->whereNull('accounts.deleted_at')
+ ->where('accounts.user_id', auth()->user()->id)
+ ->where('account_meta.name', 'account_number')
+ ->where('account_meta.data', json_encode($value));
if ($accountId > 0) {
// exclude current account from check.
$query->where('account_meta.account_id', '!=', $accountId);
}
- $set = $query->get(['account_meta.*']);
- $count = $set->count();
+ $set = $query->get(['account_meta.*']);
+ $count = $set->count();
if (0 === $count) {
return true;
}
@@ -612,7 +608,7 @@ class FireflyValidator extends Validator
// pretty much impossible but still.
return false;
}
- $type = $this->data['objectType'] ?? 'unknown';
+ $type = $this->data['objectType'] ?? 'unknown';
if ('expense' !== $type && 'revenue' !== $type) {
Log::warning(sprintf('Account number "%s" is not unique and account type "%s" cannot share its account number.', $value, $type));
@@ -624,7 +620,7 @@ class FireflyValidator extends Validator
/** @var AccountMeta $entry */
foreach ($set as $entry) {
$otherAccount = $entry->account;
- $otherType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type));
+ $otherType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type));
if (('expense' === $otherType || 'revenue' === $otherType) && $otherType !== $type) {
Log::debug(sprintf('The other account with this account number is a "%s" so return true.', $otherType));
@@ -642,10 +638,9 @@ class FireflyValidator extends Validator
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
{
return 0 === DB::table('transaction_currencies')
- ->where($field, $value)
- ->whereNull('deleted_at')
- ->count()
- ;
+ ->where($field, $value)
+ ->whereNull('deleted_at')
+ ->count();
}
/**
@@ -653,17 +648,17 @@ class FireflyValidator extends Validator
*/
public function validateUniqueCurrencyCode(?string $attribute, ?string $value): bool
{
- return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
+ return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
}
public function validateUniqueCurrencyName(?string $attribute, ?string $value): bool
{
- return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
+ return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
}
public function validateUniqueCurrencySymbol(?string $attribute, ?string $value): bool
{
- return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
+ return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
}
/**
@@ -675,7 +670,7 @@ class FireflyValidator extends Validator
*/
public function validateUniqueExistingWebhook($value, $parameters, $something): bool
{
- $existingId = (int) ($something[0] ?? 0);
+ $existingId = (int)($something[0] ?? 0);
$trigger = 0;
$response = 0;
$delivery = 0;
@@ -686,7 +681,7 @@ class FireflyValidator extends Validator
// get existing webhook value:
if (0 !== $existingId) {
/** @var null|Webhook $webhook */
- $webhook = auth()->user()->webhooks()->find($existingId);
+ $webhook = auth()->user()->webhooks()->find($existingId);
if (null === $webhook) {
return false;
}
@@ -704,13 +699,12 @@ class FireflyValidator extends Validator
$userId = auth()->user()->id;
return 0 === Webhook::whereUserId($userId)
- ->where('trigger', $trigger)
- ->where('response', $response)
- ->where('delivery', $delivery)
- ->where('id', '!=', $existingId)
- ->where('url', $url)
- ->count()
- ;
+ ->where('trigger', $trigger)
+ ->where('response', $response)
+ ->where('delivery', $delivery)
+ ->where('id', '!=', $existingId)
+ ->where('url', $url)
+ ->count();
}
return false;
@@ -732,24 +726,23 @@ class FireflyValidator extends Validator
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
{
[$table, $field] = $parameters;
- $exclude = (int) ($parameters[2] ?? 0.0);
+ $exclude = (int)($parameters[2] ?? 0.0);
/*
* If other data (in $this->getData()) contains
* ID field, set that field to be the $exclude.
*/
- $data = $this->getData();
- if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int) $data['id'] > 0) {
- $exclude = (int) $data['id'];
+ $data = $this->getData();
+ if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
+ $exclude = (int)$data['id'];
}
// get entries from table
- $result = DB::table($table)
- ->where('user_id', auth()->user()->id)
- ->whereNull('deleted_at')
- ->where('id', '!=', $exclude)
- ->where($field, $value)
- ->first([$field])
- ;
+ $result = DB::table($table)
+ ->where('user_id', auth()->user()->id)
+ ->whereNull('deleted_at')
+ ->where('id', '!=', $exclude)
+ ->where($field, $value)
+ ->first([$field]);
if (null === $result) {
return true; // not found, so true.
}
@@ -769,12 +762,11 @@ class FireflyValidator extends Validator
{
$exclude = $parameters[0] ?? null;
$query = DB::table('object_groups')
- ->whereNull('object_groups.deleted_at')
- ->where('object_groups.user_id', auth()->user()->id)
- ->where('object_groups.title', $value)
- ;
+ ->whereNull('object_groups.deleted_at')
+ ->where('object_groups.user_id', auth()->user()->id)
+ ->where('object_groups.title', $value);
if (null !== $exclude) {
- $query->where('object_groups.id', '!=', (int) $exclude);
+ $query->where('object_groups.id', '!=', (int)$exclude);
}
return 0 === $query->count();
@@ -791,11 +783,10 @@ class FireflyValidator extends Validator
{
$exclude = $parameters[0] ?? null;
$query = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
- ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
- ->where('accounts.user_id', auth()->user()->id)
- ;
+ ->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
+ ->where('accounts.user_id', auth()->user()->id);
if (null !== $exclude) {
- $query->where('piggy_banks.id', '!=', (int) $exclude);
+ $query->where('piggy_banks.id', '!=', (int)$exclude);
}
$query->where('piggy_banks.name', $value);
@@ -816,19 +807,18 @@ class FireflyValidator extends Validator
$deliveries = Webhook::getDeliveriesForValidation();
// integers
- $trigger = $triggers[$this->data['trigger']] ?? 0;
- $response = $responses[$this->data['response']] ?? 0;
- $delivery = $deliveries[$this->data['delivery']] ?? 0;
- $url = $this->data['url'];
- $userId = auth()->user()->id;
+ $trigger = $triggers[$this->data['trigger']] ?? 0;
+ $response = $responses[$this->data['response']] ?? 0;
+ $delivery = $deliveries[$this->data['delivery']] ?? 0;
+ $url = $this->data['url'];
+ $userId = auth()->user()->id;
return 0 === Webhook::whereUserId($userId)
- ->where('trigger', $trigger)
- ->where('response', $response)
- ->where('delivery', $delivery)
- ->where('url', $url)
- ->count()
- ;
+ ->where('trigger', $trigger)
+ ->where('response', $response)
+ ->where('delivery', $delivery)
+ ->where('url', $url)
+ ->count();
}
return false;
@@ -841,9 +831,9 @@ class FireflyValidator extends Validator
}
/** @var User $user */
- $user = User::find($this->data['user_id']);
- $type = AccountType::find($this->data['account_type_id'])->first();
- $value = $this->data['name'];
+ $user = User::find($this->data['user_id']);
+ $type = AccountType::find($this->data['account_type_id'])->first();
+ $value = $this->data['name'];
/** @var null|Account $result */
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
@@ -859,10 +849,10 @@ class FireflyValidator extends Validator
/** @var Account $existingAccount */
$existingAccount = Account::find($this->data['id']);
- $type = $existingAccount->accountType;
- $ignore = $existingAccount->id;
+ $type = $existingAccount->accountType;
+ $ignore = $existingAccount->id;
- $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->where('name', $value)->first();
+ $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->where('name', $value)->first();
return null === $entry;
}
@@ -879,7 +869,7 @@ class FireflyValidator extends Validator
private function validateByAccountTypeId($value, $parameters): bool
{
$type = AccountType::find($this->data['account_type_id'])->first();
- $ignore = (int) ($parameters[0] ?? 0.0);
+ $ignore = (int)($parameters[0] ?? 0.0);
/** @var null|Account $result */
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->where('name', $value)->first();
@@ -890,18 +880,18 @@ class FireflyValidator extends Validator
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
{
/** @var null|array $search */
- $search = Config::get('firefly.accountTypeByIdentifier.'.$type);
+ $search = config('firefly.accountTypeByIdentifier.' . $type);
if (null === $search) {
return false;
}
$accountTypes = AccountType::whereIn('type', $search)->get();
- $ignore = (int) ($parameters[0] ?? 0.0);
+ $ignore = (int)($parameters[0] ?? 0.0);
$accountTypeIds = $accountTypes->pluck('id')->toArray();
/** @var null|Account $result */
- $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->where('name', $value)->first();
+ $result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->where('name', $value)->first();
return null === $result;
}
@@ -914,10 +904,10 @@ class FireflyValidator extends Validator
/** @var Account $existingAccount */
$existingAccount = Account::find($accountId);
- $type = $existingAccount->accountType;
- $ignore = $existingAccount->id;
+ $type = $existingAccount->accountType;
+ $ignore = $existingAccount->id;
- $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->where('name', $value)->first();
+ $entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->where('name', $value)->first();
return null === $entry;
}
diff --git a/mago.toml b/mago.toml
index 5d5ccb402f..3855a2e4b9 100644
--- a/mago.toml
+++ b/mago.toml
@@ -41,9 +41,7 @@ no-boolean-flag-parameter = { enabled = false }
prefer-static-closure = { enabled = false }
no-literal-password = { enabled = false }
too-many-enum-cases = { enabled = false }
-no-assign-in-condition = { enabled = false }
tagged-fixme = { enabled = false }
-no-empty-catch-clause = { enabled = false }
excessive-parameter-list = { enabled = false }
no-redundant-math={ enabled = false }
prefer-first-class-callable={ enabled = false }