Code reordering and reformatting. I should really start employing style CI.

This commit is contained in:
James Cole
2021-09-18 10:26:12 +02:00
parent 9b9d52e99f
commit 4003cea759
344 changed files with 2776 additions and 2605 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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.

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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'));
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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.
*

View File

@@ -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
{