Update configuration and fix some files.

This commit is contained in:
James Cole
2025-05-27 17:02:18 +02:00
parent c074fec0a7
commit d8f512ca3a
31 changed files with 154 additions and 111 deletions

View File

@@ -75,7 +75,7 @@ class AccountFactory
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
$type = $this->accountRepository->getAccountTypeByType($accountType);
if (null === $type) {
if (!$type instanceof AccountType) {
throw new FireflyException(sprintf('Cannot find account type "%s"', $accountType));
}
$return = $this->user->accounts->where('account_type_id', $type->id)->where('name', $accountName)->first();
@@ -111,7 +111,7 @@ class AccountFactory
// account may exist already:
$return = $this->find($data['name'], $type->type);
if (null !== $return) {
if ($return instanceof Account) {
return $return;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
@@ -93,7 +94,7 @@ class BillFactory
$objectGroupTitle = $data['object_group_title'] ?? '';
if ('' !== $objectGroupTitle) {
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) {
if ($objectGroup instanceof ObjectGroup) {
$bill->objectGroups()->sync([$objectGroup->id]);
$bill->save();
}
@@ -102,7 +103,7 @@ class BillFactory
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) {
if ($objectGroup instanceof ObjectGroup) {
$bill->objectGroups()->sync([$objectGroup->id]);
$bill->save();
}
@@ -124,7 +125,7 @@ class BillFactory
// then find by name:
if (null === $bill && '' !== $billName) {
$bill = $this->findByName($billName);
return $this->findByName($billName);
}
return $bill;

View File

@@ -53,7 +53,7 @@ class BudgetFactory
if ('' !== $budgetName) {
$budget = $this->findByName($budgetName);
if (null !== $budget) {
if ($budget instanceof Budget) {
return $budget;
}
}

View File

@@ -59,7 +59,7 @@ class CategoryFactory
if ('' !== $categoryName) {
$category = $this->findByName($categoryName);
if (null !== $category) {
if ($category instanceof Category) {
return $category;
}

View File

@@ -37,7 +37,7 @@ class PiggyBankEventFactory
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): void
{
app('log')->debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
if (null === $piggyBank) {
if (!$piggyBank instanceof PiggyBank) {
app('log')->debug('Piggy bank is null');
return;

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\Account;
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\PiggyBank;
@@ -35,6 +37,8 @@ use FireflyIII\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
use function Safe\json_encode;
/**
* Class PiggyBankFactory
*/
@@ -99,7 +103,7 @@ class PiggyBankFactory
$objectGroupTitle = $data['object_group_title'] ?? '';
if ('' !== $objectGroupTitle) {
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) {
if ($objectGroup instanceof ObjectGroup) {
$piggyBank->objectGroups()->sync([$objectGroup->id]);
}
}
@@ -107,7 +111,7 @@ class PiggyBankFactory
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) {
if ($objectGroup instanceof ObjectGroup) {
$piggyBank->objectGroups()->sync([$objectGroup->id]);
}
}
@@ -241,7 +245,7 @@ class PiggyBankFactory
/** @var array $info */
foreach ($accounts as $info) {
$account = $this->accountRepository->find((int) ($info['account_id'] ?? 0));
if (null === $account) {
if (!$account instanceof Account) {
Log::debug(sprintf('Account #%d not found, skipping.', (int) ($info['account_id'] ?? 0)));
continue;
@@ -284,7 +288,7 @@ class PiggyBankFactory
Log::debug(sprintf('Will link account #%d with info: ', $account->id), $toBeLinked[$account->id]);
}
}
Log::debug(sprintf('Link information: %s', \Safe\json_encode($toBeLinked)));
Log::debug(sprintf('Link information: %s', json_encode($toBeLinked)));
if (0 !== count($toBeLinked)) {
$piggyBank->accounts()->sync($toBeLinked);
}

View File

@@ -59,7 +59,7 @@ class TagFactory
'zoom_level' => null,
]
);
if (null === $newTag) {
if (!$newTag instanceof Tag) {
app('log')->error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
return null;

View File

@@ -118,7 +118,7 @@ class TransactionFactory
);
// do foreign currency thing: add foreign currency info to $one and $two if necessary.
if (null !== $this->foreignCurrency
if ($this->foreignCurrency instanceof TransactionCurrency
&& null !== $foreignAmount
&& $this->foreignCurrency->id !== $this->currency->id) {
$result->foreign_currency_id = $this->foreignCurrency->id;

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Factory;
use FireflyIII\Models\Bill;
use FireflyIII\Models\PiggyBank;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
@@ -54,6 +56,8 @@ use Illuminate\Support\Facades\Log;
use Exception;
use JsonException;
use function Safe\json_encode;
/**
* Class TransactionJournalFactory
*
@@ -122,10 +126,10 @@ class TransactionJournalFactory
foreach ($transactions as $index => $row) {
Log::debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions)));
$journal = $this->createJournal(new NullArrayObject($row));
if (null !== $journal) {
if ($journal instanceof TransactionJournal) {
$collection->push($journal);
}
if (null === $journal) {
if (!$journal instanceof TransactionJournal) {
Log::error('The createJournal() method returned NULL. This may indicate an error.');
}
}
@@ -175,7 +179,7 @@ class TransactionJournalFactory
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']);
$billId = TransactionTypeEnum::WITHDRAWAL->value === $type->type && null !== $bill ? $bill->id : null;
$billId = TransactionTypeEnum::WITHDRAWAL->value === $type->type && $bill instanceof Bill ? $bill->id : null;
$description = (string) $row['description'];
// Manipulate basic fields
@@ -286,7 +290,7 @@ class TransactionJournalFactory
// see the currency they expect to see.
$amount = (string) $row['amount'];
$foreignAmount = (string) $row['foreign_amount'];
if (null !== $foreignCurrency && $foreignCurrency->id !== $currency->id
if ($foreignCurrency instanceof TransactionCurrency && $foreignCurrency->id !== $currency->id
&& (TransactionTypeEnum::TRANSFER->value === $type->type || $this->isBetweenAssetAndLiability($sourceAccount, $destinationAccount))
) {
$transactionFactory->setCurrency($foreignCurrency);
@@ -325,7 +329,7 @@ class TransactionJournalFactory
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
try {
$json = \Safe\json_encode($dataRow, JSON_THROW_ON_ERROR);
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
Log::error(sprintf('Could not encode dataRow: %s', $e->getMessage()));
$json = microtime();
@@ -354,7 +358,7 @@ class TransactionJournalFactory
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->whereNotNull('transaction_journals.id')
->where('transaction_journals.user_id', $this->user->id)
->where('data', \Safe\json_encode($hash, JSON_THROW_ON_ERROR))
->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
->with(['transactionJournal', 'transactionJournal.transactionGroup'])
->first(['journal_meta.*'])
;
@@ -427,12 +431,12 @@ class TransactionJournalFactory
private function reconciliationSanityCheck(?Account $sourceAccount, ?Account $destinationAccount): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
if (null !== $sourceAccount && null !== $destinationAccount) {
if ($sourceAccount instanceof Account && $destinationAccount instanceof Account) {
Log::debug('Both accounts exist, simply return them.');
return [$sourceAccount, $destinationAccount];
}
if (null === $destinationAccount) {
if (!$destinationAccount instanceof Account) {
Log::debug('Destination account is NULL, source account is not.');
$account = $this->accountRepository->getReconciliation($sourceAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
@@ -440,7 +444,7 @@ class TransactionJournalFactory
return [$sourceAccount, $account];
}
if (null === $sourceAccount) { // @phpstan-ignore-line
if (!$sourceAccount instanceof Account) { // @phpstan-ignore-line
Log::debug('Source account is NULL, destination account is not.');
$account = $this->accountRepository->getReconciliation($destinationAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
@@ -482,7 +486,7 @@ class TransactionJournalFactory
/** @var null|TransactionCurrency $preference */
$preference = $this->accountRepository->getAccountCurrency($account);
if (null === $preference && null === $currency) {
if (null === $preference && !$currency instanceof TransactionCurrency) {
// return user's default:
return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
}
@@ -498,10 +502,10 @@ class TransactionJournalFactory
private function compareCurrencies(?TransactionCurrency $currency, ?TransactionCurrency $foreignCurrency): ?TransactionCurrency
{
Log::debug(sprintf('Now in compareCurrencies("%s", "%s")', $currency?->code, $foreignCurrency?->code));
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
return null;
}
if (null !== $foreignCurrency && $foreignCurrency->id === $currency->id) {
if ($foreignCurrency instanceof TransactionCurrency && $foreignCurrency->id === $currency->id) {
return null;
}
@@ -558,7 +562,7 @@ class TransactionJournalFactory
$piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']);
if (null !== $piggyBank) {
if ($piggyBank instanceof PiggyBank) {
$this->piggyEventFactory->create($journal, $piggyBank);
Log::debug('Create piggy event.');