Skip to content

Firefly III: a personal finances manager

Fix moar phpstan issues.

James Cole91b7ee06d829
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index aa7b492cc2..d36293328b 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -37,10 +37,7 @@ parameters:
- 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
# all errors below I will (probably) never fix.
diff --git a/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php b/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php
index eb2ccbdf9c..aeff2c01d0 100644
--- a/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php
+++ b/app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers\Models\BudgetLimit;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\SameDateRequest;
+use FireflyIII\Api\V1\Requests\DateRangeRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
@@ -118,12 +119,14 @@ final class ShowController extends Controller
*
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
- public function indexAll(SameDateRequest $request): JsonResponse
+ public function indexAll(DateRangeRequest $request): JsonResponse
{
$manager = $this->getManager();
$manager->parseIncludes('budget');
$pageSize = $this->parameters->get('limit');
- $collection = $this->blRepository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end'));
+ $collection = $this->blRepository->getAllBudgetLimits(
+ $request->attributes->get('start'),
+ $request->attributes->get('end'));
$count = $collection->count();
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
diff --git a/app/Api/V1/Controllers/Models/Recurrence/TriggerController.php b/app/Api/V1/Controllers/Models/Recurrence/TriggerController.php
index 898b43525b..47e4f8e5f5 100644
--- a/app/Api/V1/Controllers/Models/Recurrence/TriggerController.php
+++ b/app/Api/V1/Controllers/Models/Recurrence/TriggerController.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Models\Recurrence;
use FireflyIII\Api\V1\Controllers\Controller;
+use FireflyIII\Api\V1\Requests\DateRequest;
use FireflyIII\Api\V1\Requests\Generic\SingleDateRequest;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\CreateRecurringTransactions;
@@ -59,12 +60,12 @@ final class TriggerController extends Controller
});
}
- public function trigger(SingleDateRequest $request, Recurrence $recurrence): JsonResponse
+ public function trigger(DateRequest $request, Recurrence $recurrence): JsonResponse
{
// find recurrence occurrence for this date and trigger it.
// grab the date from the last time the recurrence fired:
$backupDate = $recurrence->latest_date;
- $date = $request->getDate();
+ $date = $request->attributes->get('date');
// fire the recurring cron job on the given date, then post-date the created transaction.
Log::info(sprintf('Trigger: will now fire recurring cron job task for date "%s".', $date->format('Y-m-d H:i:s')));
diff --git a/app/Console/Commands/Correction/CorrectsAccountTypes.php b/app/Console/Commands/Correction/CorrectsAccountTypes.php
index 0bd3a59877..ae45828486 100644
--- a/app/Console/Commands/Correction/CorrectsAccountTypes.php
+++ b/app/Console/Commands/Correction/CorrectsAccountTypes.php
@@ -229,12 +229,22 @@ class CorrectsAccountTypes extends Command
private function getDestinationTransaction(TransactionJournal $journal): Transaction
{
- return $journal->transactions->firstWhere('amount', '>', 0);
+ /** @var null|Transaction $res */
+ $res = $journal->transactions->firstWhere('amount', '>', 0);
+ if(null === $res) {
+ throw new FireflyException('Could not find transaction.');
+ }
+ return $res;
}
private function getSourceTransaction(TransactionJournal $journal): Transaction
{
- return $journal->transactions->firstWhere('amount', '<', 0);
+ /** @var null|Transaction $res */
+ $res = $journal->transactions->firstWhere('amount', '<', 0);
+ if(null === $res) {
+ throw new FireflyException('Could not find transaction.');
+ }
+ return $res;
}
private function giveNewDestinationAccount(TransactionJournal $journal, Account $newDestination): void
diff --git a/app/Console/Commands/Upgrade/UpgradesToGroups.php b/app/Console/Commands/Upgrade/UpgradesToGroups.php
index 0981af55b4..4dd227e560 100644
--- a/app/Console/Commands/Upgrade/UpgradesToGroups.php
+++ b/app/Console/Commands/Upgrade/UpgradesToGroups.php
@@ -93,7 +93,7 @@ class UpgradesToGroups extends Command
return $amount && $identifier;
});
-
+ /** @var Transaction|null */
return $set->first();
}
diff --git a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php
index 1b886447a0..77dfe0d503 100644
--- a/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php
+++ b/app/Console/Commands/Upgrade/UpgradesVariousCurrencyInformation.php
@@ -106,17 +106,20 @@ class UpgradesVariousCurrencyInformation extends Command
break;
case TransactionTypeEnum::WITHDRAWAL->value:
+ /** @var null|Transaction $lead */
$lead = $journal->transactions()->where('amount', '<', 0)->first();
break;
case TransactionTypeEnum::DEPOSIT->value:
+ /** @var null|Transaction $lead */
$lead = $journal->transactions()->where('amount', '>', 0)->first();
break;
case TransactionTypeEnum::OPENING_BALANCE->value:
// whichever isn't an initial balance account:
+ /** @var null|Transaction $lead */
$lead = $journal
->transactions()
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
@@ -129,6 +132,7 @@ class UpgradesVariousCurrencyInformation extends Command
case TransactionTypeEnum::RECONCILIATION->value:
// whichever isn't the reconciliation account:
+ /** @var null|Transaction $lead */
$lead = $journal
->transactions()
->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index 6065955379..c09eb6fcbd 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -54,17 +54,17 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
- $start = $availableBudget->start_date->format('Y-m-d');
- $end = $availableBudget->end_date->format('Y-m-d');
- $key = sprintf('%s-%s-%s', $availableBudget->transaction_currency_id, $start, $end);
+ $start = $availableBudget->start_date->format('Y-m-d');
+ $end = $availableBudget->end_date->format('Y-m-d');
+ $key = sprintf('%s-%s-%s', $availableBudget->transaction_currency_id, $start, $end);
if (array_key_exists($key, $exists)) {
Log::debug(sprintf(
- 'Found duplicate AB: %s %s, %s-%s. Has been deleted',
- $availableBudget->transaction_currency_id,
- $availableBudget->amount,
- $start,
- $end
- ));
+ 'Found duplicate AB: %s %s, %s-%s. Has been deleted',
+ $availableBudget->transaction_currency_id,
+ $availableBudget->amount,
+ $start,
+ $end
+ ));
$availableBudget->delete();
}
$exists[$key] = true;
@@ -96,19 +96,19 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))
- ->first()
- ;
+ ->first();
}
public function findById(int $id): ?AvailableBudget
{
+ /** @var AvailableBudget|null */
return $this->user->availableBudgets->find($id);
}
#[Override]
public function findInRange(TransactionCurrency $currency, Carbon $start, Carbon $end): Collection
{
- /** @var null|AvailableBudget */
+ /** @var Collection */
return $this->user
->availableBudgets()
->where('transaction_currency_id', $currency->id)
@@ -117,8 +117,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
$q1->whereBetween('start_date', [$start, $end]);
$q1->orWhereBetween('end_date', [$start, $end]);
})
- ->get(['available_budgets.*'])
- ;
+ ->get(['available_budgets.*']);
}
/**
@@ -126,7 +125,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
*/
public function get(?Carbon $start = null, ?Carbon $end = null): Collection
{
- $query = $this->user->availableBudgets()->with(['transactionCurrency']);
+ $query = $this->user->availableBudgets()->with(['transactionCurrency']);
if ($start instanceof Carbon && $end instanceof Carbon) {
$query->where(static function (Builder $q1) use ($start, $end): void {
$q1->where('start_date', '=', $start->format('Y-m-d'));
@@ -142,7 +141,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
#[Deprecated]
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string
{
- $amount = '0';
+ $amount = '0';
/** @var null|AvailableBudget $availableBudget */
$availableBudget = $this->user
@@ -150,8 +149,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))
- ->first()
- ;
+ ->first();
if (null !== $availableBudget) {
return $availableBudget->amount;
}
@@ -167,8 +165,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
return $this->user
->availableBudgets()
->where('transaction_currency_id', $currency->id)
- ->get()
- ;
+ ->get();
}
/**
@@ -197,8 +194,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->availableBudgets()
->where('start_date', '=', $start->format('Y-m-d'))
->where('end_date', '=', $end->format('Y-m-d'))
- ->get()
- ;
+ ->get();
}
public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array
@@ -209,8 +205,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->availableBudgets()
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))
- ->get()
- ;
+ ->get();
Log::debug(sprintf('Found %d available budgets (already converted)', $availableBudgets->count()));
@@ -225,7 +220,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
: $availableBudget->transaction_currency_id;
$field = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id ? 'native_amount' : 'amount';
$return[$currencyId] ??= '0';
- $amount = '' === (string) $availableBudget->{$field} ? '0' : (string) $availableBudget->{$field};
+ $amount = '' === (string)$availableBudget->{$field} ? '0' : (string)$availableBudget->{$field};
$return[$currencyId] = bcadd($return[$currencyId], $amount);
Log::debug(sprintf('Add #%d %s (%s) for a total of %s', $currencyId, $amount, $field, $return[$currencyId]));
}
@@ -241,26 +236,25 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))
- ->first()
- ;
+ ->first();
}
#[Override]
public function recalculateAmount(AvailableBudget $availableBudget): void
{
Log::debug(sprintf('Now in recalculateAmount(#%d)', $availableBudget->id));
- $newAmount = '0';
- $period = Period::make($availableBudget->start_date, $availableBudget->end_date, Precision::DAY());
+ $newAmount = '0';
+ $period = Period::make($availableBudget->start_date, $availableBudget->end_date, Precision::DAY());
Log::debug(sprintf(
- 'Now recalculating available budget #%d, (%s to %s)',
- $availableBudget->id,
- $availableBudget->start_date->format('Y-m-d'),
- $availableBudget->end_date->format('Y-m-d')
- ));
+ 'Now recalculating available budget #%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.
$blRepository = app(BudgetLimitRepositoryInterface::class);
$blRepository->setUser($this->user);
- $set = $blRepository->getAllBudgetLimitsByCurrency($availableBudget->transactionCurrency, $availableBudget->start_date, $availableBudget->end_date);
+ $set = $blRepository->getAllBudgetLimitsByCurrency($availableBudget->transactionCurrency, $availableBudget->start_date, $availableBudget->end_date);
Log::debug(sprintf('Found %d interesting budget limit(s).', $set->count()));
/** @var BudgetLimit $budgetLimit */
@@ -281,15 +275,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget
{
/** @var null|AvailableBudget $availableBudget */
- $availableBudget = $this->user
+ $availableBudget = $this->user
->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))
- ->first()
- ;
+ ->first();
if (null === $availableBudget) {
- $availableBudget = new AvailableBudget();
+ $availableBudget = new AvailableBudget();
$availableBudget->user()->associate($this->user);
$availableBudget->transactionCurrency()->associate($currency);
$availableBudget->start_date = $start->startOfDay();
@@ -309,21 +302,21 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
if ($start instanceof Carbon) {
$start = $data['start']->startOfDay();
}
- $end = $data['end'];
+ $end = $data['end'];
if ($end instanceof Carbon) {
$end = $data['end']->endOfDay();
}
return AvailableBudget::create([
- 'user_id' => $this->user->id,
- 'user_group_id' => $this->user->user_group_id,
- 'transaction_currency_id' => $data['currency_id'],
- 'amount' => $data['amount'],
- 'start_date' => $start,
- 'start_date_tz' => $start->format('e'),
- 'end_date' => $end,
- 'end_date_tz' => $end->format('e'),
- ]);
+ 'user_id' => $this->user->id,
+ 'user_group_id' => $this->user->user_group_id,
+ 'transaction_currency_id' => $data['currency_id'],
+ 'amount' => $data['amount'],
+ 'start_date' => $start,
+ 'start_date_tz' => $start->format('e'),
+ 'end_date' => $end,
+ 'end_date_tz' => $end->format('e'),
+ ]);
}
public function update(AvailableBudget $availableBudget, array $data): AvailableBudget
@@ -375,24 +368,24 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
$blRepository->setUser($this->user);
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')
- ));
+ '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());
+ $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($availableBudgetPeriod)) {
Log::debug('This budget limit is equal to the available budget period.');
- return (string) $budgetLimit->amount;
+ return (string)$budgetLimit->amount;
}
// if budget limit period is inside AB period, it can be added in full.
if ($availableBudgetPeriod->contains($limitPeriod)) {
Log::debug('This budget limit is smaller than the available budget period.');
- return (string) $budgetLimit->amount;
+ return (string)$budgetLimit->amount;
}
if ($availableBudgetPeriod->overlapsWith($limitPeriod)) {
@@ -401,7 +394,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
if ($overlap instanceof Period) {
$length = $overlap->length();
- return bcmul($blRepository->getDailyAmount($budgetLimit), (string) $length);
+ return bcmul($blRepository->getDailyAmount($budgetLimit), (string)$length);
}
}
diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php
index 171db76759..a8cc394082 100644
--- a/app/Repositories/Currency/CurrencyRepository.php
+++ b/app/Repositories/Currency/CurrencyRepository.php
@@ -296,15 +296,14 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
->currencies()
->orderBy('code', 'ASC')
->withPivot(['group_default'])
- ->get()
- ;
+ ->get();
$all->map(static function (TransactionCurrency $current): TransactionCurrency {
$current->userGroupEnabled = true;
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
return $current;
});
-
+ /** @var Collection */
return $all;
}
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index caf0cd61c0..1adc89ce3c 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -129,6 +129,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
*/
public function firstNull(): ?TransactionJournal
{
+ /** @var TransactionJournal|null */
return $this->user
->transactionJournals()
->orderBy('date', 'ASC')
@@ -149,8 +150,12 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
if (null === $transaction) {
throw new FireflyException(sprintf('Your administration is broken. Transaction journal #%d has no destination transaction.', $journal->id));
}
-
- return $transaction->account;
+ /** @var Account|null $res */
+ $res = $transaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
/**
@@ -175,6 +180,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function getLast(): ?TransactionJournal
{
+ /** @var TransactionJournal|null */
return $this->user
->transactionJournals()
->orderBy('date', 'DESC')
@@ -221,7 +227,12 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
throw new FireflyException(sprintf('Your administration is broken. Transaction journal #%d has no source transaction.', $journal->id));
}
- return $transaction->account;
+ /** @var Account|null $res */
+ $res = $transaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
#[Override]
diff --git a/app/TransactionRules/Actions/ConvertToDeposit.php b/app/TransactionRules/Actions/ConvertToDeposit.php
index 3527f1644a..10bd29657d 100644
--- a/app/TransactionRules/Actions/ConvertToDeposit.php
+++ b/app/TransactionRules/Actions/ConvertToDeposit.php
@@ -247,13 +247,18 @@ class ConvertToDeposit implements ActionInterface
*/
private function getDestinationAccount(TransactionJournal $journal): Account
{
- /** @var null|Transaction $destAccount */
- $destAccount = $journal->transactions()->where('amount', '>', 0)->first();
- if (null === $destAccount) {
+ /** @var null|Transaction $destTransaction */
+ $destTransaction = $journal->transactions()->where('amount', '>', 0)->first();
+ if (null === $destTransaction) {
throw new FireflyException(sprintf('Cannot find destination transaction for journal #%d', $journal->id));
}
- return $destAccount->account;
+ /** @var Account|null $res */
+ $res = $destTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
/**
@@ -267,6 +272,11 @@ class ConvertToDeposit implements ActionInterface
throw new FireflyException(sprintf('Cannot find source transaction for journal #%d', $journal->id));
}
- return $sourceTransaction->account;
+ /** @var Account|null $res */
+ $res = $sourceTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
}
diff --git a/app/TransactionRules/Actions/ConvertToTransfer.php b/app/TransactionRules/Actions/ConvertToTransfer.php
index 84efc7a0d5..c48a18a09e 100644
--- a/app/TransactionRules/Actions/ConvertToTransfer.php
+++ b/app/TransactionRules/Actions/ConvertToTransfer.php
@@ -299,13 +299,18 @@ class ConvertToTransfer implements ActionInterface
*/
private function getDestinationAccount(TransactionJournal $journal): Account
{
- /** @var null|Transaction $destAccount */
- $destAccount = $journal->transactions()->where('amount', '>', 0)->first();
- if (null === $destAccount) {
+ /** @var null|Transaction $destTransaction */
+ $destTransaction = $journal->transactions()->where('amount', '>', 0)->first();
+ if (null === $destTransaction) {
throw new FireflyException(sprintf('Cannot find destination transaction for journal #%d', $journal->id));
}
- return $destAccount->account;
+ /** @var Account|null $res */
+ $res = $destTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
private function getDestinationType(int $journalId): string
@@ -332,7 +337,12 @@ class ConvertToTransfer implements ActionInterface
throw new FireflyException(sprintf('Cannot find source transaction for journal #%d', $journal->id));
}
- return $sourceTransaction->account;
+ /** @var Account|null $res */
+ $res = $sourceTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
private function getSourceType(int $journalId): string
diff --git a/app/TransactionRules/Actions/ConvertToWithdrawal.php b/app/TransactionRules/Actions/ConvertToWithdrawal.php
index 73164972e4..096153df8f 100644
--- a/app/TransactionRules/Actions/ConvertToWithdrawal.php
+++ b/app/TransactionRules/Actions/ConvertToWithdrawal.php
@@ -238,13 +238,18 @@ class ConvertToWithdrawal implements ActionInterface
*/
private function getDestinationAccount(TransactionJournal $journal): Account
{
- /** @var null|Transaction $destAccount */
- $destAccount = $journal->transactions()->where('amount', '>', 0)->first();
- if (null === $destAccount) {
+ /** @var null|Transaction $destTransaction */
+ $destTransaction = $journal->transactions()->where('amount', '>', 0)->first();
+ if (null === $destTransaction) {
throw new FireflyException(sprintf('Cannot find destination transaction for journal #%d', $journal->id));
}
- return $destAccount->account;
+ /** @var Account|null $res */
+ $res = $destTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
/**
@@ -258,6 +263,11 @@ class ConvertToWithdrawal implements ActionInterface
throw new FireflyException(sprintf('Cannot find source transaction for journal #%d', $journal->id));
}
- return $sourceTransaction->account;
+ /** @var Account|null $res */
+ $res = $sourceTransaction->account;
+ if(null === $res) {
+ throw new FireflyException('Account is unexpectedly NULL.');
+ }
+ return $res;
}
}
diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php
index 32d9f979e8..123a8a7f16 100644
--- a/app/Transformers/TransactionGroupTransformer.php
+++ b/app/Transformers/TransactionGroupTransformer.php
@@ -182,6 +182,7 @@ class TransactionGroupTransformer extends AbstractTransformer
*/
private function getDestinationTransaction(TransactionJournal $journal): Transaction
{
+ /** @var Transaction|null $result */
$result = $journal->transactions->first(static fn (Transaction $transaction): bool => (float) $transaction->amount > 0);
if (null === $result) {
throw new FireflyException(sprintf('Journal #%d unexpectedly has no destination transaction.', $journal->id));
@@ -224,6 +225,7 @@ class TransactionGroupTransformer extends AbstractTransformer
*/
private function getSourceTransaction(TransactionJournal $journal): Transaction
{
+ /** @var Transaction|null $result */
$result = $journal->transactions->first(static fn (Transaction $transaction): bool => (float) $transaction->amount < 0);
if (null === $result) {
throw new FireflyException(sprintf('Journal #%d unexpectedly has no source transaction.', $journal->id));