Skip to content

Firefly III: a personal finances manager

Fix phpstan issues (or ignore them).

James Cole6172d60e00e2
diff --git a/app/Handlers/Observer/AccountObserver.php b/app/Handlers/Observer/AccountObserver.php
index 1ec19fbbbd..6adbe9fcd6 100644
--- a/app/Handlers/Observer/AccountObserver.php
+++ b/app/Handlers/Observer/AccountObserver.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
use FireflyIII\Models\Account;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
@@ -81,6 +82,7 @@ class AccountObserver
foreach ($account->piggyBanks()->get() as $piggy) {
$piggy->accounts()->detach($account);
}
+ /** @var Attachment $attachment */
foreach ($account->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/BillObserver.php b/app/Handlers/Observer/BillObserver.php
index 709d8b25ae..4c3bc8441c 100644
--- a/app/Handlers/Observer/BillObserver.php
+++ b/app/Handlers/Observer/BillObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Support\Facades\Amount;
@@ -46,6 +47,7 @@ class BillObserver
$repository->setUser($bill->user);
// app('log')->debug('Observe "deleting" of a bill.');
+ /** @var Attachment $attachment */
foreach ($bill->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/BudgetObserver.php b/app/Handlers/Observer/BudgetObserver.php
index 01fc2a937e..9a697c79ea 100644
--- a/app/Handlers/Observer/BudgetObserver.php
+++ b/app/Handlers/Observer/BudgetObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
@@ -39,6 +40,7 @@ class BudgetObserver
$repository = app(AttachmentRepositoryInterface::class);
$repository->setUser($budget->user);
+ /** @var Attachment $attachment */
foreach ($budget->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/CategoryObserver.php b/app/Handlers/Observer/CategoryObserver.php
index 76decd000d..24f7edf792 100644
--- a/app/Handlers/Observer/CategoryObserver.php
+++ b/app/Handlers/Observer/CategoryObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
@@ -38,6 +39,7 @@ class CategoryObserver
$repository = app(AttachmentRepositoryInterface::class);
$repository->setUser($category->user);
+ /** @var Attachment $attachment */
foreach ($category->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/PiggyBankObserver.php b/app/Handlers/Observer/PiggyBankObserver.php
index e2a88158b4..c1495eea3d 100644
--- a/app/Handlers/Observer/PiggyBankObserver.php
+++ b/app/Handlers/Observer/PiggyBankObserver.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
@@ -50,6 +51,7 @@ class PiggyBankObserver
$repository = app(AttachmentRepositoryInterface::class);
$repository->setUser($piggyBank->accounts()->first()->user);
+ /** @var Attachment $attachment */
foreach ($piggyBank->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/RecurrenceObserver.php b/app/Handlers/Observer/RecurrenceObserver.php
index cf6a8f6e97..ff2e4218f8 100644
--- a/app/Handlers/Observer/RecurrenceObserver.php
+++ b/app/Handlers/Observer/RecurrenceObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
@@ -38,6 +39,7 @@ class RecurrenceObserver
$repository = app(AttachmentRepositoryInterface::class);
$repository->setUser($recurrence->user);
+ /** @var Attachment $attachment */
foreach ($recurrence->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/TagObserver.php b/app/Handlers/Observer/TagObserver.php
index 4892ce2ccb..71090e6ef3 100644
--- a/app/Handlers/Observer/TagObserver.php
+++ b/app/Handlers/Observer/TagObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
@@ -38,6 +39,7 @@ class TagObserver
$repository = app(AttachmentRepositoryInterface::class);
$repository->setUser($tag->user);
+ /** @var Attachment $attachment */
foreach ($tag->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Handlers/Observer/TransactionJournalObserver.php b/app/Handlers/Observer/TransactionJournalObserver.php
index 4b6986b468..adaed2b902 100644
--- a/app/Handlers/Observer/TransactionJournalObserver.php
+++ b/app/Handlers/Observer/TransactionJournalObserver.php
@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Observer;
+use FireflyIII\Models\Attachment;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
@@ -45,6 +46,7 @@ class TransactionJournalObserver
$transaction->delete();
}
});
+ /** @var Attachment $attachment */
foreach ($transactionJournal->attachments()->get() as $attachment) {
$repository->destroy($attachment);
}
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
index 89fa7a80ca..60b5b8a9af 100644
--- a/app/Http/Controllers/DebugController.php
+++ b/app/Http/Controllers/DebugController.php
@@ -259,7 +259,7 @@ class DebugController extends Controller
$system = $this->getSystemInformation();
$docker = $this->getBuildInfo();
$app = $this->getAppInfo();
- $user = $this->getuserInfo();
+ $user = $this->getUserInfo();
return (string) view('partials.debug-table', compact('system', 'docker', 'app', 'user'));
}
diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php
index 207ba625af..6aad82a390 100644
--- a/app/Jobs/CreateRecurringTransactions.php
+++ b/app/Jobs/CreateRecurringTransactions.php
@@ -419,9 +419,7 @@ class CreateRecurringTransactions implements ShouldQueue
/** @var RecurrenceTransaction $transaction */
foreach ($transactions as $index => $transaction) {
$single = [
- 'type' => null === $transaction?->transactionType?->type ?
- strtolower($recurrence->transactionType->type) :
- strtolower($transaction->transactionType->type),
+ 'type' => null === $transaction?->transactionType?->type ? strtolower($recurrence->transactionType->type) : strtolower($transaction->transactionType->type), // @phpstan-ignore-line
'date' => $date,
'user' => $recurrence->user_id,
'currency_id' => $transaction->transaction_currency_id,
diff --git a/app/Support/Search/QueryParser/Node.php b/app/Support/Search/QueryParser/Node.php
index 8aa102cff2..e00f513585 100644
--- a/app/Support/Search/QueryParser/Node.php
+++ b/app/Support/Search/QueryParser/Node.php
@@ -63,13 +63,9 @@ abstract class Node
return false;
}
- if ($compare instanceof NodeGroup) {
+ if ($compare instanceof NodeGroup && $this instanceof NodeGroup) {
if (count($compare->getNodes()) !== count($this->getNodes())) {
Log::debug(sprintf('Return false because node count is different. Original is %d, compare is %d', count($this->getNodes()), count($compare->getNodes())));
-
- // var_dump($this);
- // var_dump($compare);
- // exit;
return false;
}
@@ -80,11 +76,6 @@ abstract class Node
foreach ($this->getNodes() as $index => $node) {
if (false === $node->equals($compare->getNodes()[$index])) {
Log::debug('Return false because nodes are different!');
- var_dump($this);
- var_dump($compare);
-
- exit;
-
return false;
}
}
diff --git a/app/Support/Search/QueryParser/QueryParser.php b/app/Support/Search/QueryParser/QueryParser.php
index 1085536559..cdca33c415 100644
--- a/app/Support/Search/QueryParser/QueryParser.php
+++ b/app/Support/Search/QueryParser/QueryParser.php
@@ -152,12 +152,12 @@ class QueryParser implements QueryParserInterface
case ':':
$skipNext = false;
- if ('' === $tokenUnderConstruction) { // @phpstan-ignore-line
+ if ('' === $tokenUnderConstruction) {
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
$skipNext = true;
}
- if ('' !== $tokenUnderConstruction && !$skipNext) {
+ if ('' !== $tokenUnderConstruction && !$skipNext) { // @phpstan-ignore-line
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/AmountFormat.php b/app/Support/Twig/AmountFormat.php
index dce53dd769..62a5694f87 100644
--- a/app/Support/Twig/AmountFormat.php
+++ b/app/Support/Twig/AmountFormat.php
@@ -114,7 +114,7 @@ class AmountFormat extends AbstractExtension
static function (string $amount, string $code, ?bool $coloured = null): string {
$coloured ??= true;
- /** @var TransactionCurrency $currency */
+ /** @var TransactionCurrency|null $currency */
$currency = TransactionCurrency::whereCode($code)->first();
if (null === $currency) {
Log::error(sprintf('Could not find currency with code "%s". Fallback to native currency.', $code));
diff --git a/database/migrations/2024_11_30_075826_multi_piggy.php b/database/migrations/2024_11_30_075826_multi_piggy.php
index 56639a463e..19442cd051 100644
--- a/database/migrations/2024_11_30_075826_multi_piggy.php
+++ b/database/migrations/2024_11_30_075826_multi_piggy.php
@@ -159,7 +159,7 @@ return new class () extends Migration {
Schema::dropIfExists('account_piggy_bank');
}
- protected static function hasForeign(string $table, string $column)
+ protected static function hasForeign(string $table, string $column): bool
{
$foreignKeysDefinitions = Schema::getForeignKeys($table);