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

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use Illuminate\Contracts\Validation\ValidationRule;
@@ -46,7 +47,7 @@ class IsAssetAccountId implements ValidationRule
return;
}
if (AccountType::ASSET !== $account->accountType->type && AccountType::DEFAULT !== $account->accountType->type) {
if (AccountTypeEnum::ASSET->value !== $account->accountType->type && AccountTypeEnum::DEFAULT->value !== $account->accountType->type) {
$fail('validation.no_asset_account')->translate();
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
@@ -49,13 +50,13 @@ class UniqueAccountNumber implements ValidationRule
$this->expectedType = $expectedType;
// a very basic fix to make sure we get the correct account type:
if ('expense' === $expectedType) {
$this->expectedType = AccountType::EXPENSE;
$this->expectedType = AccountTypeEnum::EXPENSE->value;
}
if ('revenue' === $expectedType) {
$this->expectedType = AccountType::REVENUE;
$this->expectedType = AccountTypeEnum::REVENUE->value;
}
if ('asset' === $expectedType) {
$this->expectedType = AccountType::ASSET;
$this->expectedType = AccountTypeEnum::ASSET->value;
}
app('log')->debug(sprintf('Expected type is "%s"', $this->expectedType));
}
@@ -106,20 +107,20 @@ class UniqueAccountNumber implements ValidationRule
private function getMaxOccurrences(): array
{
$maxCounts = [
AccountType::ASSET => 0,
AccountType::EXPENSE => 0,
AccountType::REVENUE => 0,
AccountTypeEnum::ASSET->value => 0,
AccountTypeEnum::EXPENSE->value => 0,
AccountTypeEnum::REVENUE->value => 0,
];
if ('expense' === $this->expectedType || AccountType::EXPENSE === $this->expectedType) {
if ('expense' === $this->expectedType || AccountTypeEnum::EXPENSE->value === $this->expectedType) {
// IBAN should be unique amongst expense and asset accounts.
// may appear once in revenue accounts
$maxCounts[AccountType::REVENUE] = 1;
$maxCounts[AccountTypeEnum::REVENUE->value] = 1;
}
if ('revenue' === $this->expectedType || AccountType::REVENUE === $this->expectedType) {
if ('revenue' === $this->expectedType || AccountTypeEnum::REVENUE->value === $this->expectedType) {
// IBAN should be unique amongst revenue and asset accounts.
// may appear once in expense accounts
$maxCounts[AccountType::EXPENSE] = 1;
$maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
}
return $maxCounts;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Support\Facades\Steam;
@@ -50,16 +51,16 @@ class UniqueIban implements ValidationRule
$this->expectedTypes = [$expectedType];
// a very basic fix to make sure we get the correct account type:
if ('expense' === $expectedType) {
$this->expectedTypes = [AccountType::EXPENSE];
$this->expectedTypes = [AccountTypeEnum::EXPENSE->value];
}
if ('revenue' === $expectedType) {
$this->expectedTypes = [AccountType::REVENUE];
$this->expectedTypes = [AccountTypeEnum::REVENUE->value];
}
if ('asset' === $expectedType) {
$this->expectedTypes = [AccountType::ASSET];
$this->expectedTypes = [AccountTypeEnum::ASSET->value];
}
if ('liabilities' === $expectedType) {
$this->expectedTypes = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
$this->expectedTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
}
}
@@ -123,21 +124,21 @@ class UniqueIban implements ValidationRule
private function getMaxOccurrences(): array
{
$maxCounts = [
AccountType::ASSET => 0,
AccountType::EXPENSE => 0,
AccountType::REVENUE => 0,
AccountTypeEnum::ASSET->value => 0,
AccountTypeEnum::EXPENSE->value => 0,
AccountTypeEnum::REVENUE->value => 0,
'liabilities' => 0,
];
if (in_array('expense', $this->expectedTypes, true) || in_array(AccountType::EXPENSE, $this->expectedTypes, true)) {
if (in_array('expense', $this->expectedTypes, true) || in_array(AccountTypeEnum::EXPENSE->value, $this->expectedTypes, true)) {
// IBAN should be unique amongst expense and asset accounts.
// may appear once in revenue accounts
$maxCounts[AccountType::REVENUE] = 1;
$maxCounts[AccountTypeEnum::REVENUE->value] = 1;
}
if (in_array('revenue', $this->expectedTypes, true) || in_array(AccountType::REVENUE, $this->expectedTypes, true)) {
if (in_array('revenue', $this->expectedTypes, true) || in_array(AccountTypeEnum::REVENUE->value, $this->expectedTypes, true)) {
// IBAN should be unique amongst revenue and asset accounts.
// may appear once in expense accounts
$maxCounts[AccountType::EXPENSE] = 1;
$maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
}
return $maxCounts;
@@ -147,7 +148,7 @@ class UniqueIban implements ValidationRule
{
$typesArray = [$type];
if ('liabilities' === $type) {
$typesArray = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
$typesArray = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
}
$query
= auth()->user()