mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code reordering and reformatting. I should really start employing style CI.
This commit is contained in:
@@ -32,6 +32,22 @@ use Log;
|
||||
*/
|
||||
trait DepositValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param mixed $accountName
|
||||
@@ -78,22 +94,6 @@ trait DepositValidation
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
|
@@ -35,31 +35,6 @@ use Log;
|
||||
trait LiabilityValidation
|
||||
{
|
||||
|
||||
/**
|
||||
* Source of an liability credit must be a liability.
|
||||
*
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateLCSource(?string $accountName): bool
|
||||
{
|
||||
$result = true;
|
||||
Log::debug(sprintf('Now in validateLCDestination("%s")', $accountName));
|
||||
if ('' === $accountName || null === $accountName) {
|
||||
$result = false;
|
||||
}
|
||||
if (true === $result) {
|
||||
// set the source to be a (dummy) revenue account.
|
||||
$account = new Account;
|
||||
$accountType = AccountType::whereType(AccountType::LIABILITY_CREDIT)->first();
|
||||
$account->accountType = $accountType;
|
||||
$this->source = $account;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
*
|
||||
@@ -96,4 +71,29 @@ trait LiabilityValidation
|
||||
return $result ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Source of an liability credit must be a liability.
|
||||
*
|
||||
* @param string|null $accountName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validateLCSource(?string $accountName): bool
|
||||
{
|
||||
$result = true;
|
||||
Log::debug(sprintf('Now in validateLCDestination("%s")', $accountName));
|
||||
if ('' === $accountName || null === $accountName) {
|
||||
$result = false;
|
||||
}
|
||||
if (true === $result) {
|
||||
// set the source to be a (dummy) revenue account.
|
||||
$account = new Account;
|
||||
$accountType = AccountType::whereType(AccountType::LIABILITY_CREDIT)->first();
|
||||
$account->accountType = $accountType;
|
||||
$this->source = $account;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -33,6 +33,13 @@ use Log;
|
||||
*/
|
||||
trait OBValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param mixed $accountName
|
||||
@@ -79,13 +86,6 @@ trait OBValidation
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* Source of an opening balance can either be an asset account
|
||||
* or an "initial balance account". The latter can be created.
|
||||
|
@@ -31,6 +31,22 @@ use Log;
|
||||
*/
|
||||
trait TransferValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param mixed $accountName
|
||||
@@ -71,22 +87,6 @@ trait TransferValidation
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
|
@@ -32,6 +32,22 @@ use Log;
|
||||
*/
|
||||
trait WithdrawalValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
@@ -103,13 +119,6 @@ trait WithdrawalValidation
|
||||
return true === $this->canCreateTypes($validTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param int|null $accountId
|
||||
* @param string|null $accountName
|
||||
@@ -143,13 +152,4 @@ trait WithdrawalValidation
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
* @param string $accountName
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, int $accountId, string $accountName): ?Account;
|
||||
}
|
||||
|
@@ -30,11 +30,11 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use FireflyIII\Validation\Account\AccountValidatorProperties;
|
||||
use FireflyIII\Validation\Account\DepositValidation;
|
||||
use FireflyIII\Validation\Account\LiabilityValidation;
|
||||
use FireflyIII\Validation\Account\OBValidation;
|
||||
use FireflyIII\Validation\Account\ReconciliationValidation;
|
||||
use FireflyIII\Validation\Account\TransferValidation;
|
||||
use FireflyIII\Validation\Account\WithdrawalValidation;
|
||||
use FireflyIII\Validation\Account\LiabilityValidation;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -202,21 +202,6 @@ class AccountValidator
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accountType
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canCreateType(string $accountType): bool
|
||||
{
|
||||
$canCreate = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT];
|
||||
if (in_array($accountType, $canCreate, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param int $accountId
|
||||
@@ -242,4 +227,19 @@ class AccountValidator
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accountType
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canCreateType(string $accountType): bool
|
||||
{
|
||||
$canCreate = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT];
|
||||
if (in_array($accountType, $canCreate, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -66,10 +66,11 @@ trait ValidatesBulkTransactionQuery
|
||||
}
|
||||
if ($source->accountType->type !== $dest->accountType->type) {
|
||||
$validator->errors()->add('query', (string)trans('validation.invalid_query_account_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
// must have same currency:
|
||||
if($repository->getAccountCurrency($source)->id !== $repository->getAccountCurrency($dest)->id) {
|
||||
if ($repository->getAccountCurrency($source)->id !== $repository->getAccountCurrency($dest)->id) {
|
||||
$validator->errors()->add('query', (string)trans('validation.invalid_query_currency'));
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ trait ValidatesAutoBudgetRequest
|
||||
// basic float check:
|
||||
if (!is_numeric($amount)) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -172,7 +172,7 @@ class FireflyValidator extends Validator
|
||||
"\u{3000}", // ideographic space
|
||||
"\u{FEFF}", // zero width no -break space
|
||||
'-',
|
||||
'?'
|
||||
'?',
|
||||
];
|
||||
$replace = '';
|
||||
$value = str_replace($search, $replace, $value);
|
||||
@@ -198,6 +198,7 @@ class FireflyValidator extends Validator
|
||||
$message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value);
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -36,6 +36,13 @@ use Log;
|
||||
trait GroupValidation
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getTransactionsArray(Validator $validator): array;
|
||||
|
||||
/**
|
||||
* Adds an error to the "description" field when the user has submitted no descriptions and no
|
||||
* journal description.
|
||||
@@ -104,13 +111,6 @@ trait GroupValidation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getTransactionsArray(Validator $validator): array;
|
||||
|
||||
/**
|
||||
* Do the validation required by validateJournalIds.
|
||||
*
|
||||
|
@@ -330,7 +330,7 @@ trait TransactionValidation
|
||||
/**
|
||||
* All types of splits must be equal.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateTransactionTypesForUpdate(Validator $validator): void
|
||||
{
|
||||
|
Reference in New Issue
Block a user