From 627db2c2df8567e9a9647757f0a1eba1ac47b6a4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 29 Nov 2023 06:36:48 +0100 Subject: [PATCH] Various code cleanup --- app/Support/Http/Controllers/ModelInformation.php | 6 ++++-- app/Validation/Account/OBValidation.php | 3 ++- app/Validation/RecurrenceValidation.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Support/Http/Controllers/ModelInformation.php b/app/Support/Http/Controllers/ModelInformation.php index 7fce876f08..2dd716f5bd 100644 --- a/app/Support/Http/Controllers/ModelInformation.php +++ b/app/Support/Http/Controllers/ModelInformation.php @@ -81,7 +81,9 @@ trait ModelInformation // types of liability: /** @var AccountType $debt */ $debt = $repository->getAccountTypeByType(AccountType::DEBT); + /** @var AccountType $loan */ $loan = $repository->getAccountTypeByType(AccountType::LOAN); + /** @var AccountType $mortgage */ $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); $liabilityTypes = [ $debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)), @@ -129,7 +131,7 @@ trait ModelInformation $result = []; $billTriggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains']; $values = [ - $bill->transactionCurrency()->first()->name, + $bill->transactionCurrency()->first()?->name, $bill->amount_min, $bill->amount_max, $bill->name, @@ -197,7 +199,7 @@ trait ModelInformation // currency $journalTriggers[$index] = 'currency_is'; - $values[$index] = sprintf('%s (%s)', $journal->transactionCurrency->name, $journal->transactionCurrency->code); + $values[$index] = sprintf('%s (%s)', $journal->transactionCurrency?->name, $journal->transactionCurrency?->code); $index++; // amount_exactly: diff --git a/app/Validation/Account/OBValidation.php b/app/Validation/Account/OBValidation.php index 35c77635df..63b0beb629 100644 --- a/app/Validation/Account/OBValidation.php +++ b/app/Validation/Account/OBValidation.php @@ -45,7 +45,7 @@ trait OBValidation app('log')->debug('Now in validateOBDestination', $array); // source can be any of the following types. - $validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? []; + $validTypes = $this->combinations[$this->transactionType][$this->source?->accountType->type] ?? []; if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the destination of a deposit can't be created. @@ -138,6 +138,7 @@ trait OBValidation // set the source to be a (dummy) initial balance account. $account = new Account(); + /** @var AccountType $accountType */ $accountType = AccountType::whereType(AccountType::INITIAL_BALANCE)->first(); $account->accountType = $accountType; $this->setSource($account); diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index e19dc81013..f318050e5a 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -54,7 +54,7 @@ trait RecurrenceValidation if ('invalid' === $transactionType) { app('log')->debug('Type is invalid but we will search for it.'); /** @var Recurrence|null $recurrence */ - $recurrence = $this->route()->parameter('recurrence'); + $recurrence = $this->route()?->parameter('recurrence'); if (null !== $recurrence) { app('log')->debug('There is a recurrence in the route.'); // ok so we have a recurrence should be able to extract type somehow.