Various code cleanup

This commit is contained in:
James Cole 2023-11-29 06:36:48 +01:00
parent b9feb0aa71
commit 627db2c2df
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
3 changed files with 7 additions and 4 deletions

View File

@ -81,7 +81,9 @@ trait ModelInformation
// types of liability: // types of liability:
/** @var AccountType $debt */ /** @var AccountType $debt */
$debt = $repository->getAccountTypeByType(AccountType::DEBT); $debt = $repository->getAccountTypeByType(AccountType::DEBT);
/** @var AccountType $loan */
$loan = $repository->getAccountTypeByType(AccountType::LOAN); $loan = $repository->getAccountTypeByType(AccountType::LOAN);
/** @var AccountType $mortgage */
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
$liabilityTypes = [ $liabilityTypes = [
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)), $debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
@ -129,7 +131,7 @@ trait ModelInformation
$result = []; $result = [];
$billTriggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains']; $billTriggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
$values = [ $values = [
$bill->transactionCurrency()->first()->name, $bill->transactionCurrency()->first()?->name,
$bill->amount_min, $bill->amount_min,
$bill->amount_max, $bill->amount_max,
$bill->name, $bill->name,
@ -197,7 +199,7 @@ trait ModelInformation
// currency // currency
$journalTriggers[$index] = 'currency_is'; $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++; $index++;
// amount_exactly: // amount_exactly:

View File

@ -45,7 +45,7 @@ trait OBValidation
app('log')->debug('Now in validateOBDestination', $array); app('log')->debug('Now in validateOBDestination', $array);
// source can be any of the following types. // 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 (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL we return false, // if both values are NULL we return false,
// because the destination of a deposit can't be created. // 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. // set the source to be a (dummy) initial balance account.
$account = new Account(); $account = new Account();
/** @var AccountType $accountType */
$accountType = AccountType::whereType(AccountType::INITIAL_BALANCE)->first(); $accountType = AccountType::whereType(AccountType::INITIAL_BALANCE)->first();
$account->accountType = $accountType; $account->accountType = $accountType;
$this->setSource($account); $this->setSource($account);

View File

@ -54,7 +54,7 @@ trait RecurrenceValidation
if ('invalid' === $transactionType) { if ('invalid' === $transactionType) {
app('log')->debug('Type is invalid but we will search for it.'); app('log')->debug('Type is invalid but we will search for it.');
/** @var Recurrence|null $recurrence */ /** @var Recurrence|null $recurrence */
$recurrence = $this->route()->parameter('recurrence'); $recurrence = $this->route()?->parameter('recurrence');
if (null !== $recurrence) { if (null !== $recurrence) {
app('log')->debug('There is a recurrence in the route.'); app('log')->debug('There is a recurrence in the route.');
// ok so we have a recurrence should be able to extract type somehow. // ok so we have a recurrence should be able to extract type somehow.