From edbac66576c8b63dcae26476bfe06e224a754253 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 18 Sep 2023 17:59:10 +0200 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/7973 --- app/Validation/AccountValidator.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Validation/AccountValidator.php b/app/Validation/AccountValidator.php index c1544f5cfb..89e65455f3 100644 --- a/app/Validation/AccountValidator.php +++ b/app/Validation/AccountValidator.php @@ -265,9 +265,10 @@ class AccountValidator // find by ID if (null !== $accountId && $accountId > 0) { - $first = $this->accountRepository->find($accountId); - $check = in_array($first->accountType->type, $validTypes, true); - $check = $inverse ? !$check : $check; // reverse the validation check if necessary. + $first = $this->accountRepository->find($accountId); + $accountType = null === $first ? 'invalid' : $first->accountType->type; + $check = in_array($accountType, $validTypes, true); + $check = $inverse ? !$check : $check; // reverse the validation check if necessary. if ((null !== $first) && $check) { app('log')->debug(sprintf('ID: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban')); return $first; @@ -276,9 +277,10 @@ class AccountValidator // find by iban if (null !== $accountIban && '' !== (string)$accountIban) { - $first = $this->accountRepository->findByIbanNull($accountIban, $validTypes); - $check = in_array($first->accountType->type, $validTypes, true); - $check = $inverse ? !$check : $check; // reverse the validation check if necessary. + $first = $this->accountRepository->findByIbanNull($accountIban, $validTypes); + $accountType = null === $first ? 'invalid' : $first->accountType->type; + $check = in_array($accountType, $validTypes, true); + $check = $inverse ? !$check : $check; // reverse the validation check if necessary. if ((null !== $first) && $check) { app('log')->debug(sprintf('Iban: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban')); return $first; @@ -287,9 +289,10 @@ class AccountValidator // find by number if (null !== $accountNumber && '' !== (string)$accountNumber) { - $first = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes); - $check = in_array($first->accountType->type, $validTypes, true); - $check = $inverse ? !$check : $check; // reverse the validation check if necessary. + $first = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes); + $accountType = null === $first ? 'invalid' : $first->accountType->type; + $check = in_array($accountType, $validTypes, true); + $check = $inverse ? !$check : $check; // reverse the validation check if necessary. if ((null !== $first) && $check) { app('log')->debug(sprintf('Number: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban')); return $first;