Replace enum

This commit is contained in:
James Cole
2025-01-03 09:15:52 +01:00
parent 1787f4421b
commit a8ae496fda
57 changed files with 257 additions and 204 deletions

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory;
@@ -96,7 +97,7 @@ trait AccountServiceTrait
public function updateMetaData(Account $account, array $data): void
{
$fields = $this->validFields;
if (AccountType::ASSET === $account->accountType->type) {
if (AccountTypeEnum::ASSET->value === $account->accountType->type) {
$fields = $this->validAssetFields;
}
@@ -119,11 +120,11 @@ trait AccountServiceTrait
}
// only asset account may have a role:
if (AccountType::ASSET !== $account->accountType->type) {
if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
$data['account_role'] = '';
}
if (AccountType::ASSET === $account->accountType->type && 'ccAsset' === $data['account_role']) {
if (AccountTypeEnum::ASSET->value === $account->accountType->type && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory;
@@ -258,7 +259,7 @@ trait JournalServiceTrait
}
if (null === $account) {
// final attempt, create it.
if (AccountType::ASSET === $preferredType) {
if (AccountTypeEnum::ASSET->value === $preferredType) {
throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data)));
}
// fix name of account if only IBAN is given:
@@ -312,7 +313,7 @@ trait JournalServiceTrait
{
// return cash account.
if (null === $account && '' === (string) $data['name']
&& in_array(AccountType::CASH, $types, true)) {
&& in_array(AccountTypeEnum::CASH->value, $types, true)) {
$account = $this->accountRepository->getCashAccount();
}
app('log')->debug('Cannot return cash account, return input instead.');

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\BillFactory;
@@ -189,7 +190,7 @@ trait RecurringTransactionTrait
}
// maybe we can create it? Try to avoid LOAN and other asset types.
$cannotCreate = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];
$cannotCreate = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::CREDITCARD->value];
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\UpdatedAccount;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
@@ -153,7 +154,7 @@ class AccountUpdateService
{
$type = $account->accountType->type;
return in_array($type, [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true);
return in_array($type, [AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value], true);
}
private function getAccountType(string $type): AccountType
@@ -171,7 +172,7 @@ class AccountUpdateService
}
// skip if not of orderable type.
$type = $account->accountType->type;
if (!in_array($type, [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], true)) {
if (!in_array($type, [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], true)) {
app('log')->debug('Will not change order of this account.');
return $account;
@@ -180,9 +181,9 @@ class AccountUpdateService
$oldOrder = $account->order;
$newOrder = $data['order'];
app('log')->debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
$list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]);
if (AccountType::ASSET === $type) {
$list = $this->getTypeIds([AccountType::ASSET]);
$list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
if (AccountTypeEnum::ASSET->value === $type) {
$list = $this->getTypeIds([AccountTypeEnum::ASSET->value]);
}
if ($newOrder > $oldOrder) {