Skip to content

Firefly III: a personal finances manager

Correct phpstan errors.

James Cole695f990236bd
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index 3e782c4393..e5a1985153 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -34,13 +34,9 @@ parameters:
reportUnmatchedIgnoredErrors: true
ignoreErrors:
# these are actually interesting but not right now:
- - identifier: method.notFound
- - identifier: identical.alwaysFalse
- identifier: function.impossibleType
- identifier: booleanNot.exprNotBoolean
- identifier: ternary.condNotBoolean
- - identifier: booleanNot.alwaysFalse
- - identifier: booleanAnd.alwaysFalse
- identifier: greater.alwaysTrue
- identifier: function.alreadyNarrowedType
- identifier: booleanNot.alwaysTrue
@@ -52,13 +48,11 @@ parameters:
- identifier: identical.alwaysTrue
- identifier: assign.propertyReadOnly
- identifier: varTag.nativeType
- - identifier: booleanAnd.leftAlwaysFalse
- identifier: property.onlyWritten
- identifier: parameter.phpDocType
- identifier: property.dynamicName
- identifier: property.unusedType
- identifier: staticMethod.deprecated
- - identifier: greater.invalid
# ignore everything but things that BREAK
- identifier: property.deprecated
- identifier: method.deprecated
@@ -71,6 +65,7 @@ parameters:
- identifier: return.unusedType
- identifier: return.phpDocType
# all errors below I will (probably) never fix.
+ - identifier: method.notFound # way too many false positives
- identifier: catch.neverThrown # plenty of errors that are thrown undocumented
- identifier: staticMethod.dynamicName # dont care
- identifier: arguments.count # one false positive
diff --git a/app/Console/Commands/Correction/CorrectsIbans.php b/app/Console/Commands/Correction/CorrectsIbans.php
index 5749665e45..8b3ae9da56 100644
--- a/app/Console/Commands/Correction/CorrectsIbans.php
+++ b/app/Console/Commands/Correction/CorrectsIbans.php
@@ -35,9 +35,9 @@ class CorrectsIbans extends Command
{
use ShowsFriendlyMessages;
- protected $description = 'Removes spaces from IBANs';
- protected $signature = 'correction:ibans';
- private int $count = 0;
+ protected $description = 'Removes spaces from IBANs';
+ protected $signature = 'correction:ibans';
+ private int $count = 0;
/**
* Execute the console command.
@@ -57,31 +57,29 @@ class CorrectsIbans extends Command
/** @var Account $account */
foreach ($accounts as $account) {
- $userId = $account->user_id;
+ $userId = $account->user_id;
$set[$userId] ??= [];
- $iban = (string) $account->iban;
+ $iban = (string)$account->iban;
if ('' === $iban) {
continue;
}
- $type = $account->accountType->type;
+ $type = $account->accountType->type;
if (in_array($type, [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value], true)) {
$type = 'liabilities';
}
- // iban already in use! two exceptions exist:
- if (
- array_key_exists($iban, $set[$userId]) && (
- !AccountTypeEnum::EXPENSE->value === $set[$userId][$iban]
- && AccountTypeEnum::REVENUE->value === $type
- && !(AccountTypeEnum::REVENUE->value === $set[$userId][$iban] && AccountTypeEnum::EXPENSE->value === $type)
- )
- ) {
- $this->friendlyWarning(sprintf(
- 'IBAN "%s" is used more than once and will be removed from %s #%d ("%s")',
- $iban,
- $account->accountType->type,
- $account->id,
- $account->name
- ));
+ $showWarningAndCorrect = false;
+ if (array_key_exists($iban, $set[$userId])) {
+ // the type is a revenue account, and the existing IBAN is NOT an expense account.
+ if (AccountTypeEnum::REVENUE->value === $type && AccountTypeEnum::EXPENSE->value !== $set[$userId][$iban]) {
+ $showWarningAndCorrect = true;
+ }
+ // the type is an expense account, and the existing IBAN is NOT a revenue account
+ if (AccountTypeEnum::EXPENSE->value === $type && AccountTypeEnum::REVENUE->value !== $set[$userId][$iban]) {
+ $showWarningAndCorrect = true;
+ }
+ }
+ if ($showWarningAndCorrect) {
+ $this->friendlyWarning(sprintf('IBAN "%s" is used more than once and will be removed from %s #%d ("%s")', $iban, $account->accountType->type, $account->id, $account->name));
$account->iban = null;
$account->save();
++$this->count;
@@ -97,8 +95,8 @@ class CorrectsIbans extends Command
{
/** @var Account $account */
foreach ($accounts as $account) {
- $iban = (string) $account->iban;
- $newIban = Steam::filterSpaces($iban);
+ $iban = (string)$account->iban;
+ $newIban = Steam::filterSpaces($iban);
if ('' !== $iban && $iban !== $newIban) {
$account->iban = $newIban;
$account->save();
@@ -108,7 +106,7 @@ class CorrectsIbans extends Command
// same for account number:
$accountNumber = $account->accountMeta->where('name', 'account_number')->first();
if (null !== $accountNumber) {
- $number = (string) $accountNumber->value;
+ $number = (string)$accountNumber->value;
$newNumber = Steam::filterSpaces($number);
if ('' !== $number && $number !== $newNumber) {
$accountNumber->value = $newNumber;
diff --git a/app/Console/Commands/Correction/CorrectsUnevenAmount.php b/app/Console/Commands/Correction/CorrectsUnevenAmount.php
index cb5602ec16..c26de356ce 100644
--- a/app/Console/Commands/Correction/CorrectsUnevenAmount.php
+++ b/app/Console/Commands/Correction/CorrectsUnevenAmount.php
@@ -322,7 +322,7 @@ class CorrectsUnevenAmount extends Command
foreach ($journals as $entry) {
$sum = (string) $entry->the_sum;
$sum = Steam::floatalize($sum);
- if (!is_numeric($sum) || '' === $sum || str_contains($sum, 'e') || str_contains($sum, ',')) {
+ if (!is_numeric($sum) || str_contains($sum, 'e') || str_contains($sum, ',')) {
$message = sprintf('Journal #%d has an invalid sum ("%s"). No sure what to do.', $entry->transaction_journal_id, $entry->the_sum);
$this->friendlyWarning($message);
Log::warning($message);
diff --git a/app/Models/Preference.php b/app/Models/Preference.php
index 33d769c704..93721624be 100644
--- a/app/Models/Preference.php
+++ b/app/Models/Preference.php
@@ -30,6 +30,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+/**
+ * @property mixed $data
+ */
class Preference extends Model
{
use ReturnsIntegerIdTrait;
diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.php
index 89d4cb6131..f484165ec7 100644
--- a/app/Support/Binder/BudgetList.php
+++ b/app/Support/Binder/BudgetList.php
@@ -43,14 +43,12 @@ class BudgetList implements BinderInterface
if ('allBudgets' === $value) {
return auth()->user()->budgets()->where('active', true)->orderBy('order', 'ASC')->orderBy('name', 'ASC')->get();
}
-
- $list = array_unique(array_map(\intval(...), explode(',', $value)));
-
- if (0 === count($list)) {
+ if('' === $value) {
Log::warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException();
}
+ $list = array_unique(array_map(\intval(...), explode(',', $value)));
/** @var Collection $collection */
$collection = auth()->user()->budgets()->where('active', true)->whereIn('id', $list)->get();
diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php
index 3f7ecffac9..23fc5f0c6a 100644
--- a/app/Support/Binder/CategoryList.php
+++ b/app/Support/Binder/CategoryList.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Binder;
use FireflyIII\Models\Category;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -42,11 +43,12 @@ class CategoryList implements BinderInterface
if ('allCategories' === $value) {
return auth()->user()->categories()->orderBy('name', 'ASC')->get();
}
+ if('' === $value) {
+ Log::warning('Category list count is zero, return 404.');
- $list = array_unique(array_map(\intval(...), explode(',', $value)));
- if (0 === count($list)) {
throw new NotFoundHttpException();
}
+ $list = array_unique(array_map(\intval(...), explode(',', $value)));
/** @var Collection $collection */
$collection = auth()->user()->categories()->whereIn('id', $list)->get();
diff --git a/app/Support/Binder/JournalList.php b/app/Support/Binder/JournalList.php
index 2afa514696..d24f662cd7 100644
--- a/app/Support/Binder/JournalList.php
+++ b/app/Support/Binder/JournalList.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Binder;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use Illuminate\Routing\Route;
+use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -65,11 +66,11 @@ class JournalList implements BinderInterface
protected static function parseList(string $value): array
{
- $list = array_unique(array_map(\intval(...), explode(',', $value)));
- if (0 === count($list)) {
+ if('' === $value) {
+ Log::warning('Category list count is zero, return 404.');
+
throw new NotFoundHttpException();
}
-
- return $list;
+ return array_unique(array_map(\intval(...), explode(',', $value)));
}
}
diff --git a/app/Support/Binder/TagList.php b/app/Support/Binder/TagList.php
index d8fff00a01..0ab2bc5691 100644
--- a/app/Support/Binder/TagList.php
+++ b/app/Support/Binder/TagList.php
@@ -44,15 +44,15 @@ class TagList implements BinderInterface
if ('allTags' === $value) {
return auth()->user()->tags()->orderBy('tag', 'ASC')->get();
}
- $list = array_unique(array_map(\strtolower(...), explode(',', $value)));
- Log::debug('List of tags is', $list);
-
- if (0 === count($list)) {
- Log::error('Tag list is empty.');
+ if('' === $value) {
+ Log::warning('Category list count is zero, return 404.');
throw new NotFoundHttpException();
}
+ $list = array_unique(array_map(\strtolower(...), explode(',', $value)));
+ Log::debug('List of tags is', $list);
+
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$repository->setUser(auth()->user());