mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 10:53:31 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -33,22 +33,7 @@ use Log;
|
||||
trait DepositValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -65,7 +50,7 @@ trait DepositValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a deposit can't be created.
|
||||
$this->destError = (string) trans('validation.deposit_dest_need_data');
|
||||
$this->destError = (string)trans('validation.deposit_dest_need_data');
|
||||
Log::error('Both values are NULL, cant create deposit destination.');
|
||||
$result = false;
|
||||
}
|
||||
@@ -80,7 +65,7 @@ trait DepositValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
Log::debug('findExistingAccount() returned NULL, so the result is false.');
|
||||
$this->destError = (string) trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string)trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$result = false;
|
||||
}
|
||||
if (null !== $search) {
|
||||
@@ -96,7 +81,22 @@ trait DepositValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -114,7 +114,7 @@ trait DepositValidation
|
||||
// if both values are NULL return false,
|
||||
// because the source of a deposit can't be created.
|
||||
// (this never happens).
|
||||
$this->sourceError = (string) trans('validation.deposit_source_need_data');
|
||||
$this->sourceError = (string)trans('validation.deposit_source_need_data');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
|
@@ -34,14 +34,7 @@ use Log;
|
||||
trait OBValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -57,7 +50,7 @@ trait OBValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a deposit can't be created.
|
||||
$this->destError = (string) trans('validation.ob_dest_need_data');
|
||||
$this->destError = (string)trans('validation.ob_dest_need_data');
|
||||
Log::error('Both values are NULL, cant create OB destination.');
|
||||
$result = false;
|
||||
}
|
||||
@@ -72,7 +65,7 @@ trait OBValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
Log::debug('findExistingAccount() returned NULL, so the result is false.', $validTypes);
|
||||
$this->destError = (string) trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string)trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$result = false;
|
||||
}
|
||||
if (null !== $search) {
|
||||
@@ -87,11 +80,18 @@ 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.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -108,7 +108,7 @@ trait OBValidation
|
||||
// if both values are NULL return false,
|
||||
// because the source of a deposit can't be created.
|
||||
// (this never happens).
|
||||
$this->sourceError = (string) trans('validation.ob_source_need_data');
|
||||
$this->sourceError = (string)trans('validation.ob_source_need_data');
|
||||
$result = false;
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Validation\Account;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -37,7 +36,7 @@ trait ReconciliationValidation
|
||||
public ?Account $source;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -60,7 +59,7 @@ trait ReconciliationValidation
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
@@ -73,7 +72,7 @@ trait ReconciliationValidation
|
||||
|
||||
/**
|
||||
* Basically the same check
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -97,7 +96,7 @@ trait ReconciliationValidation
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -32,22 +32,7 @@ use Log;
|
||||
trait TransferValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -61,7 +46,7 @@ trait TransferValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a transfer can't be created.
|
||||
$this->destError = (string) trans('validation.transfer_dest_need_data');
|
||||
$this->destError = (string)trans('validation.transfer_dest_need_data');
|
||||
Log::error('Both values are NULL, cant create transfer destination.');
|
||||
|
||||
return false;
|
||||
@@ -70,7 +55,7 @@ trait TransferValidation
|
||||
// or try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->destError = (string) trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string)trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -88,7 +73,22 @@ trait TransferValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ trait TransferValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the source of a withdrawal can't be created.
|
||||
$this->sourceError = (string) trans('validation.transfer_source_need_data');
|
||||
$this->sourceError = (string)trans('validation.transfer_source_need_data');
|
||||
app('log')->warning('Not a valid source, need more data.');
|
||||
|
||||
return false;
|
||||
@@ -111,7 +111,7 @@ trait TransferValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string)trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source, cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -33,22 +33,7 @@ use Log;
|
||||
trait WithdrawalValidation
|
||||
{
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -62,7 +47,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return TRUE
|
||||
// because we assume the user doesnt want to submit / change anything.
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_need_data');
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_need_data');
|
||||
app('log')->warning('[a] Not a valid source. Need more data.');
|
||||
|
||||
return false;
|
||||
@@ -71,7 +56,7 @@ trait WithdrawalValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
@@ -83,7 +68,22 @@ trait WithdrawalValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function canCreateTypes(array $accountTypes): bool;
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
abstract protected function findExistingAccount(array $validTypes, array $data): ?Account;
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -97,7 +97,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL return false,
|
||||
// because the destination of a withdrawal can never be created automatically.
|
||||
$this->destError = (string) trans('validation.withdrawal_dest_need_data');
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_need_data');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ trait WithdrawalValidation
|
||||
if (in_array($type, $validTypes, true)) {
|
||||
return true;
|
||||
}
|
||||
$this->destError = (string) trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ trait WithdrawalValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -136,7 +136,7 @@ trait WithdrawalValidation
|
||||
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the source of a withdrawal can't be created.
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_need_data');
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_need_data');
|
||||
app('log')->warning('[b] Not a valid source. Need more data.');
|
||||
|
||||
return false;
|
||||
@@ -145,7 +145,7 @@ trait WithdrawalValidation
|
||||
// otherwise try to find the account:
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
$this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
|
@@ -83,7 +83,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $transactionType
|
||||
* @param string $transactionType
|
||||
*/
|
||||
public function setTransactionType(string $transactionType): void
|
||||
{
|
||||
@@ -92,7 +92,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
@@ -101,7 +101,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -146,7 +146,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -184,7 +184,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountTypes
|
||||
* @param array $accountTypes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -205,7 +205,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accountType
|
||||
* @param string $accountType
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -220,8 +220,8 @@ class AccountValidator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
* @param array $validTypes
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
@@ -242,7 +242,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by iban
|
||||
if (null !== $accountIban && '' !== (string) $accountIban) {
|
||||
if (null !== $accountIban && '' !== (string)$accountIban) {
|
||||
$first = $this->accountRepository->findByIbanNull($accountIban, $validTypes);
|
||||
if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) {
|
||||
return $first;
|
||||
@@ -250,7 +250,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by number
|
||||
if (null !== $accountNumber && '' !== (string) $accountNumber) {
|
||||
if (null !== $accountNumber && '' !== (string)$accountNumber) {
|
||||
$first = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes);
|
||||
if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) {
|
||||
return $first;
|
||||
@@ -258,7 +258,7 @@ class AccountValidator
|
||||
}
|
||||
|
||||
// find by name:
|
||||
if ('' !== (string) $accountName) {
|
||||
if ('' !== (string)$accountName) {
|
||||
return $this->accountRepository->findByName($accountName, $validTypes);
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ use JsonException;
|
||||
trait ValidatesBulkTransactionQuery
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @throws JsonException
|
||||
*/
|
||||
@@ -50,26 +50,26 @@ trait ValidatesBulkTransactionQuery
|
||||
// find both accounts, must be same type.
|
||||
// already validated: belongs to this user.
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$source = $repository->find((int) $json['where']['account_id']);
|
||||
$dest = $repository->find((int) $json['update']['account_id']);
|
||||
$source = $repository->find((int)$json['where']['account_id']);
|
||||
$dest = $repository->find((int)$json['update']['account_id']);
|
||||
if (null === $source) {
|
||||
$validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'where', 'account_id'));
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'where', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (null === $dest) {
|
||||
$validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'update', 'account_id'));
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'update', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
if ($source->accountType->type !== $dest->accountType->type) {
|
||||
$validator->errors()->add('query', (string) trans('validation.invalid_query_account_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) {
|
||||
$validator->errors()->add('query', (string) trans('validation.invalid_query_currency'));
|
||||
$validator->errors()->add('query', (string)trans('validation.invalid_query_currency'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ use Illuminate\Validation\Validator;
|
||||
trait ValidatesAutoBudgetRequest
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function validateAutoBudgetAmount(Validator $validator): void
|
||||
{
|
||||
@@ -39,36 +39,36 @@ trait ValidatesAutoBudgetRequest
|
||||
$type = $data['auto_budget_type'] ?? '';
|
||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
||||
$period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int)$data['auto_budget_currency_id'] : null;
|
||||
$currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null;
|
||||
if (is_numeric($type)) {
|
||||
$type = (int) $type;
|
||||
$type = (int)$type;
|
||||
}
|
||||
if ('' === $type || 0 === $type) {
|
||||
return;
|
||||
}
|
||||
// basic float check:
|
||||
if (!is_numeric($amount)) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ('' === $amount) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
}
|
||||
if (1 !== bccomp((string) $amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.auto_budget_amount_positive'));
|
||||
if (1 !== bccomp((string)$amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
||||
}
|
||||
if ('' === $period) {
|
||||
$validator->errors()->add('auto_budget_period', (string) trans('validation.auto_budget_period_mandatory'));
|
||||
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if (null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.require_currency_info'));
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
}
|
||||
// too big amount
|
||||
if ((int)$amount > 268435456) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ trait CurrencyValidation
|
||||
/**
|
||||
* If the transactions contain foreign amounts, there must also be foreign currency information.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function validateForeignCurrencyInformation(Validator $validator): void
|
||||
{
|
||||
@@ -55,8 +55,8 @@ trait CurrencyValidation
|
||||
&& 0 !== bccomp('0', $transaction['foreign_amount'])
|
||||
) {
|
||||
$validator->errors()->add(
|
||||
'transactions.' . $index . '.foreign_amount',
|
||||
(string) trans('validation.require_currency_info')
|
||||
'transactions.'.$index.'.foreign_amount',
|
||||
(string)trans('validation.require_currency_info')
|
||||
);
|
||||
}
|
||||
// if the currency is present, then the amount must be present as well.
|
||||
@@ -66,15 +66,15 @@ trait CurrencyValidation
|
||||
$transaction
|
||||
)) {
|
||||
$validator->errors()->add(
|
||||
'transactions.' . $index . '.foreign_amount',
|
||||
(string) trans('validation.require_currency_amount')
|
||||
'transactions.'.$index.'.foreign_amount',
|
||||
(string)trans('validation.require_currency_amount')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FireflyValidator.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -56,8 +57,8 @@ use function is_string;
|
||||
class FireflyValidator extends Validator
|
||||
{
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
* @throws IncompatibleWithGoogleAuthenticatorException
|
||||
@@ -81,9 +82,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -91,7 +92,7 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
$field = $parameters[1] ?? 'id';
|
||||
|
||||
if (0 === (int) $value) {
|
||||
if (0 === (int)$value) {
|
||||
return true;
|
||||
}
|
||||
$count = DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count();
|
||||
@@ -100,8 +101,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -120,8 +121,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -188,13 +189,40 @@ class FireflyValidator extends Validator
|
||||
// replace characters outside of ASCI range.
|
||||
$value = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
|
||||
$search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||
$replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31',
|
||||
'32', '33', '34', '35',];
|
||||
$replace = [
|
||||
'',
|
||||
'10',
|
||||
'11',
|
||||
'12',
|
||||
'13',
|
||||
'14',
|
||||
'15',
|
||||
'16',
|
||||
'17',
|
||||
'18',
|
||||
'19',
|
||||
'20',
|
||||
'21',
|
||||
'22',
|
||||
'23',
|
||||
'24',
|
||||
'25',
|
||||
'26',
|
||||
'27',
|
||||
'28',
|
||||
'29',
|
||||
'30',
|
||||
'31',
|
||||
'32',
|
||||
'33',
|
||||
'34',
|
||||
'35',
|
||||
];
|
||||
|
||||
// take
|
||||
$first = substr($value, 0, 4);
|
||||
$last = substr($value, 4);
|
||||
$iban = $last . $first;
|
||||
$iban = $last.$first;
|
||||
$iban = trim(str_replace($search, $replace, $iban));
|
||||
if (0 === strlen($iban)) {
|
||||
return false;
|
||||
@@ -209,13 +237,13 @@ class FireflyValidator extends Validator
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1 === (int) $checksum;
|
||||
return 1 === (int)$checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -224,13 +252,13 @@ class FireflyValidator extends Validator
|
||||
/** @var mixed $compare */
|
||||
$compare = $parameters[0] ?? '0';
|
||||
|
||||
return bccomp((string) $value, (string) $compare) < 0;
|
||||
return bccomp((string)$value, (string)$compare) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -239,13 +267,13 @@ class FireflyValidator extends Validator
|
||||
/** @var mixed $compare */
|
||||
$compare = $parameters[0] ?? '0';
|
||||
|
||||
return bccomp((string) $value, (string) $compare) > 0;
|
||||
return bccomp((string)$value, (string)$compare) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -253,7 +281,7 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
$field = $parameters[1] ?? 'id';
|
||||
|
||||
if (0 === (int) $value) {
|
||||
if (0 === (int)$value) {
|
||||
return true;
|
||||
}
|
||||
$count = DB::table($parameters[0])->where($field, $value)->count();
|
||||
@@ -262,9 +290,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
* @param string $attribute
|
||||
*
|
||||
* @param string|null $value
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -273,7 +301,7 @@ class FireflyValidator extends Validator
|
||||
// first, get the index from this string:
|
||||
$value = $value ?? '';
|
||||
$parts = explode('.', $attribute);
|
||||
$index = (int) ($parts[1] ?? '0');
|
||||
$index = (int)($parts[1] ?? '0');
|
||||
|
||||
// get the name of the trigger from the data array:
|
||||
$actionType = $this->data['actions'][$index]['type'] ?? 'invalid';
|
||||
@@ -306,8 +334,14 @@ class FireflyValidator extends Validator
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$account = $repository->findByName(
|
||||
$value,
|
||||
[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,
|
||||
AccountType::CREDITCARD]
|
||||
[
|
||||
AccountType::DEFAULT,
|
||||
AccountType::ASSET,
|
||||
AccountType::LOAN,
|
||||
AccountType::DEBT,
|
||||
AccountType::MORTGAGE,
|
||||
AccountType::CREDITCARD,
|
||||
]
|
||||
);
|
||||
|
||||
return null !== $account;
|
||||
@@ -328,8 +362,8 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* $attribute has the format triggers.%d.value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -337,7 +371,7 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
// first, get the index from this string:
|
||||
$parts = explode('.', $attribute);
|
||||
$index = (int) ($parts[1] ?? '0');
|
||||
$index = (int)($parts[1] ?? '0');
|
||||
|
||||
// get the name of the trigger from the data array:
|
||||
$triggerType = $this->data['triggers'][$index]['type'] ?? 'invalid';
|
||||
@@ -354,18 +388,35 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
// these trigger types need a simple strlen check:
|
||||
$length = ['source_account_starts', 'source_account_ends', 'source_account_is', 'source_account_contains', 'destination_account_starts',
|
||||
'destination_account_ends',
|
||||
'destination_account_is', 'destination_account_contains', 'description_starts', 'description_ends', 'description_contains', 'description_is',
|
||||
'category_is',
|
||||
'budget_is', 'tag_is', 'currency_is', 'notes_contain', 'notes_start', 'notes_end', 'notes_are',];
|
||||
$length = [
|
||||
'source_account_starts',
|
||||
'source_account_ends',
|
||||
'source_account_is',
|
||||
'source_account_contains',
|
||||
'destination_account_starts',
|
||||
'destination_account_ends',
|
||||
'destination_account_is',
|
||||
'destination_account_contains',
|
||||
'description_starts',
|
||||
'description_ends',
|
||||
'description_contains',
|
||||
'description_is',
|
||||
'category_is',
|
||||
'budget_is',
|
||||
'tag_is',
|
||||
'currency_is',
|
||||
'notes_contain',
|
||||
'notes_start',
|
||||
'notes_end',
|
||||
'notes_are',
|
||||
];
|
||||
if (in_array($triggerType, $length, true)) {
|
||||
return '' !== $value;
|
||||
}
|
||||
|
||||
// check if it's an existing account.
|
||||
if (in_array($triggerType, ['destination_account_id', 'source_account_id'], true)) {
|
||||
return is_numeric($value) && (int) $value > 0;
|
||||
return is_numeric($value) && (int)$value > 0;
|
||||
}
|
||||
|
||||
// check transaction type.
|
||||
@@ -392,8 +443,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -401,7 +452,7 @@ class FireflyValidator extends Validator
|
||||
{
|
||||
$verify = false;
|
||||
if (array_key_exists('verify_password', $this->data)) {
|
||||
$verify = 1 === (int) $this->data['verify_password'];
|
||||
$verify = 1 === (int)$this->data['verify_password'];
|
||||
}
|
||||
if ($verify) {
|
||||
/** @var Verifier $service */
|
||||
@@ -414,9 +465,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -430,14 +481,14 @@ class FireflyValidator extends Validator
|
||||
return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']);
|
||||
}
|
||||
if (array_key_exists('type', $this->data)) {
|
||||
return $this->validateByAccountTypeString($value, $parameters, (string) $this->data['type']);
|
||||
return $this->validateByAccountTypeString($value, $parameters, (string)$this->data['type']);
|
||||
}
|
||||
if (array_key_exists('account_type_id', $this->data)) {
|
||||
return $this->validateByAccountTypeId($value, $parameters);
|
||||
}
|
||||
$parameterId = $parameters[0] ?? null;
|
||||
if (null !== $parameterId) {
|
||||
return $this->validateByParameterId((int) $parameterId, $value);
|
||||
return $this->validateByParameterId((int)$parameterId, $value);
|
||||
}
|
||||
if (array_key_exists('id', $this->data)) {
|
||||
return $this->validateByAccountId($value);
|
||||
@@ -471,23 +522,23 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param array $parameters
|
||||
* @param string $type
|
||||
* @param string $value
|
||||
* @param array $parameters
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
||||
{
|
||||
/** @var array|null $search */
|
||||
$search = Config::get('firefly.accountTypeByIdentifier.' . $type);
|
||||
$search = Config::get('firefly.accountTypeByIdentifier.'.$type);
|
||||
|
||||
if (null === $search) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$accountTypes = AccountType::whereIn('type', $search)->get();
|
||||
$ignore = (int) ($parameters[0] ?? 0.0);
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->get();
|
||||
@@ -501,15 +552,15 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountTypeId($value, $parameters): bool
|
||||
{
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$ignore = (int) ($parameters[0] ?? 0.0);
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
|
||||
/** @var Collection $set */
|
||||
$set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
|
||||
@@ -524,8 +575,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
* @param mixed $value
|
||||
* @param int $accountId
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -545,7 +596,7 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -565,7 +616,7 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -575,17 +626,17 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$accountId = (int) ($this->data['id'] ?? 0.0);
|
||||
$accountId = (int)($this->data['id'] ?? 0.0);
|
||||
if (0 === $accountId) {
|
||||
$accountId = (int) ($parameters[0] ?? 0.0);
|
||||
$accountId = (int)($parameters[0] ?? 0.0);
|
||||
}
|
||||
|
||||
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
@@ -617,7 +668,7 @@ class FireflyValidator extends Validator
|
||||
/** @var AccountMeta $entry */
|
||||
foreach ($set as $entry) {
|
||||
$otherAccount = $entry->account;
|
||||
$otherType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type));
|
||||
$otherType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type));
|
||||
if (('expense' === $otherType || 'revenue' === $otherType) && $otherType !== $type) {
|
||||
Log::debug(sprintf('The other account with this account number is a "%s" so return true.', $otherType));
|
||||
return true;
|
||||
@@ -634,23 +685,13 @@ class FireflyValidator extends Validator
|
||||
*/
|
||||
public function validateUniqueCurrencyCode($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value);
|
||||
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $attribute
|
||||
* @param string $value
|
||||
* @param string $field
|
||||
* @param string $attribute
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||
@@ -663,21 +704,31 @@ class FireflyValidator extends Validator
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value);
|
||||
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $something
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $something
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueExistingWebhook($value, $parameters, $something): bool
|
||||
{
|
||||
$existingId = (int) ($something[0] ?? 0);
|
||||
$existingId = (int)($something[0] ?? 0);
|
||||
$trigger = 0;
|
||||
$response = 0;
|
||||
$delivery = 0;
|
||||
@@ -724,24 +775,24 @@ class FireflyValidator extends Validator
|
||||
* parameter 1: the field
|
||||
* parameter 2: an id to ignore (when editing)
|
||||
*
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
[$table, $field] = $parameters;
|
||||
$exclude = (int) ($parameters[2] ?? 0.0);
|
||||
$exclude = (int)($parameters[2] ?? 0.0);
|
||||
|
||||
/*
|
||||
* If other data (in $this->getData()) contains
|
||||
* ID field, set that field to be the $exclude.
|
||||
*/
|
||||
$data = $this->getData();
|
||||
if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int) $data['id'] > 0) {
|
||||
$exclude = (int) $data['id'];
|
||||
if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
|
||||
$exclude = (int)$data['id'];
|
||||
}
|
||||
// get entries from table
|
||||
$set = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
@@ -759,9 +810,9 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -773,16 +824,16 @@ class FireflyValidator extends Validator
|
||||
->where('object_groups.user_id', auth()->user()->id)
|
||||
->where('object_groups.title', $value);
|
||||
if (null !== $exclude) {
|
||||
$query->where('object_groups.id', '!=', (int) $exclude);
|
||||
$query->where('object_groups.id', '!=', (int)$exclude);
|
||||
}
|
||||
|
||||
return 0 === $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -792,7 +843,7 @@ class FireflyValidator extends Validator
|
||||
$query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);
|
||||
if (null !== $exclude) {
|
||||
$query->where('piggy_banks.id', '!=', (int) $exclude);
|
||||
$query->where('piggy_banks.id', '!=', (int)$exclude);
|
||||
}
|
||||
$query->where('piggy_banks.name', $value);
|
||||
|
||||
@@ -800,8 +851,8 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@@ -36,25 +36,27 @@ use Log;
|
||||
trait GroupValidation
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getTransactionsArray(Validator $validator): array;
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function preventNoAccountInfo(Validator $validator): void
|
||||
{
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number', 'destination_number'];
|
||||
$keys = [
|
||||
'source_id',
|
||||
'destination_id',
|
||||
'source_name',
|
||||
'destination_name',
|
||||
'source_iban',
|
||||
'destination_iban',
|
||||
'source_number',
|
||||
'destination_number',
|
||||
];
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$hasAccountInfo = false;
|
||||
$hasJournalId = array_key_exists('transaction_journal_id', $transaction);
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) {
|
||||
if (array_key_exists($key, $transaction) && '' !== (string)$transaction[$key]) {
|
||||
$hasAccountInfo = true;
|
||||
}
|
||||
}
|
||||
@@ -62,23 +64,29 @@ trait GroupValidation
|
||||
if (false === $hasAccountInfo && !$hasJournalId) {
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.source_id', $index),
|
||||
(string) trans('validation.generic_no_source')
|
||||
(string)trans('validation.generic_no_source')
|
||||
);
|
||||
$validator->errors()->add(
|
||||
sprintf('transactions.%d.destination_id', $index),
|
||||
(string) trans('validation.generic_no_destination')
|
||||
(string)trans('validation.generic_no_destination')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// only an issue if there is no transaction_journal_id
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function validateDescriptions(Validator $validator): void
|
||||
{
|
||||
@@ -86,7 +94,7 @@ trait GroupValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$validDescriptions = 0;
|
||||
foreach ($transactions as $transaction) {
|
||||
if ('' !== (string) ($transaction['description'] ?? null)) {
|
||||
if ('' !== (string)($transaction['description'] ?? null)) {
|
||||
$validDescriptions++;
|
||||
}
|
||||
}
|
||||
@@ -95,13 +103,13 @@ trait GroupValidation
|
||||
if (0 === $validDescriptions) {
|
||||
$validator->errors()->add(
|
||||
'transactions.0.description',
|
||||
(string) trans('validation.filled', ['attribute' => (string) trans('validation.attributes.description')])
|
||||
(string)trans('validation.filled', ['attribute' => (string)trans('validation.attributes.description')])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
protected function validateGroupDescription(Validator $validator): void
|
||||
{
|
||||
@@ -111,7 +119,7 @@ trait GroupValidation
|
||||
|
||||
$groupTitle = $data['group_title'] ?? '';
|
||||
if ('' === $groupTitle && count($transactions) > 1) {
|
||||
$validator->errors()->add('group_title', (string) trans('validation.group_title_mandatory'));
|
||||
$validator->errors()->add('group_title', (string)trans('validation.group_title_mandatory'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +127,8 @@ trait GroupValidation
|
||||
* This method validates if the user has submitted transaction journal ID's for each array they submit, if they've submitted more than 1 transaction
|
||||
* journal. This check is necessary because Firefly III isn't able to distinguish between journals without the ID.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
protected function validateJournalIds(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
@@ -135,7 +143,7 @@ trait GroupValidation
|
||||
}
|
||||
// check each array:
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
@@ -146,10 +154,10 @@ trait GroupValidation
|
||||
/**
|
||||
* Do the validation required by validateJournalIds.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
@@ -169,7 +177,7 @@ trait GroupValidation
|
||||
if (null === $journalId || 0 === $count) {
|
||||
app('log')->warning(sprintf('Transaction group #%d has %d journals with ID %d', $transactionGroup->id, $count, $journalId));
|
||||
app('log')->warning('Invalid submission: Each split must have transaction_journal_id (either valid ID or 0).');
|
||||
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string) trans('validation.need_id_in_edit'));
|
||||
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string)trans('validation.need_id_in_edit'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ trait RecurrenceValidation
|
||||
*
|
||||
* TODO Must always trigger when the type of the recurrence changes.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function valUpdateAccountInfo(Validator $validator): void
|
||||
{
|
||||
@@ -91,7 +91,7 @@ trait RecurrenceValidation
|
||||
continue;
|
||||
}
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
||||
|
||||
@@ -103,7 +103,7 @@ trait RecurrenceValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$validDestination = $accountValidator->validateDestination(['id' => $destinationId, 'name' => $destinationName,]);
|
||||
// do something with result:
|
||||
@@ -119,7 +119,7 @@ trait RecurrenceValidation
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetition(Validator $validator): void
|
||||
{
|
||||
@@ -127,14 +127,14 @@ trait RecurrenceValidation
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
// need at least one transaction
|
||||
if (!is_countable($repetitions) || 0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the validator when there are no repetitions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRepetitionUpdate(Validator $validator): void
|
||||
{
|
||||
@@ -145,7 +145,7 @@ trait RecurrenceValidation
|
||||
}
|
||||
// need at least one transaction
|
||||
if (0 === count($repetitions)) {
|
||||
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
|
||||
$validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ trait RecurrenceValidation
|
||||
* Validates that the recurrence has valid repetition information. It either doesn't stop,
|
||||
* or stops after X times or at X date. Not both of them.,
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRecurrenceRepetition(Validator $validator): void
|
||||
{
|
||||
@@ -162,15 +162,15 @@ trait RecurrenceValidation
|
||||
$repeatUntil = $data['repeat_until'] ?? null;
|
||||
if (null !== $repetitions && null !== $repeatUntil) {
|
||||
// expect a date OR count:
|
||||
$validator->errors()->add('repeat_until', (string) trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string) trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until'));
|
||||
$validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until'));
|
||||
}
|
||||
}
|
||||
|
||||
public function validateRecurringConfig(Validator $validator)
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int) $data['nr_of_repetitions'] : null;
|
||||
$reps = array_key_exists('nr_of_repetitions', $data) ? (int)$data['nr_of_repetitions'] : null;
|
||||
$repeatUntil = array_key_exists('repeat_until', $data) ? new Carbon($data['repeat_until']) : null;
|
||||
|
||||
if (null === $reps && null === $repeatUntil) {
|
||||
@@ -186,19 +186,19 @@ trait RecurrenceValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateRepetitionMoment(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$repetitions = $data['repetitions'] ?? [];
|
||||
if (!is_array($repetitions)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', 0), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var array $repetition
|
||||
*/
|
||||
foreach ($repetitions as $index => $repetition) {
|
||||
@@ -211,23 +211,23 @@ trait RecurrenceValidation
|
||||
$repetition['moment'] = $repetition['moment'] ?? 'invalid';
|
||||
switch ($repetition['type'] ?? 'empty') {
|
||||
default:
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string) trans('validation.valid_recurrence_rep_type'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.type', $index), (string)trans('validation.valid_recurrence_rep_type'));
|
||||
|
||||
return;
|
||||
case 'daily':
|
||||
$this->validateDaily($validator, $index, (string) $repetition['moment']);
|
||||
$this->validateDaily($validator, $index, (string)$repetition['moment']);
|
||||
break;
|
||||
case 'monthly':
|
||||
$this->validateMonthly($validator, $index, (int) $repetition['moment']);
|
||||
$this->validateMonthly($validator, $index, (int)$repetition['moment']);
|
||||
break;
|
||||
case 'ndom':
|
||||
$this->validateNdom($validator, $index, (string) $repetition['moment']);
|
||||
$this->validateNdom($validator, $index, (string)$repetition['moment']);
|
||||
break;
|
||||
case 'weekly':
|
||||
$this->validateWeekly($validator, $index, (int) $repetition['moment']);
|
||||
$this->validateWeekly($validator, $index, (int)$repetition['moment']);
|
||||
break;
|
||||
case 'yearly':
|
||||
$this->validateYearly($validator, $index, (string) $repetition['moment']);
|
||||
$this->validateYearly($validator, $index, (string)$repetition['moment']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,28 +236,28 @@ trait RecurrenceValidation
|
||||
/**
|
||||
* If the repetition type is daily, the moment should be empty.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
*/
|
||||
protected function validateDaily(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
if ('' !== $moment) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the repetition type is monthly, the moment should be a day between 1-31 (inclusive).
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param int $dayOfMonth
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param int $dayOfMonth
|
||||
*/
|
||||
protected function validateMonthly(Validator $validator, int $index, int $dayOfMonth): void
|
||||
{
|
||||
if ($dayOfMonth < 1 || $dayOfMonth > 31) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,50 +265,50 @@ trait RecurrenceValidation
|
||||
* If the repetition type is "ndom", the first part must be between 1-5 (inclusive), for the week in the month,
|
||||
* and the second one must be between 1-7 (inclusive) for the day of the week.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
*/
|
||||
protected function validateNdom(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
$parameters = explode(',', $moment);
|
||||
if (2 !== count($parameters)) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
$nthDay = (int) ($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int) ($parameters[1] ?? 0.0);
|
||||
$nthDay = (int)($parameters[0] ?? 0.0);
|
||||
$dayOfWeek = (int)($parameters[1] ?? 0.0);
|
||||
if ($nthDay < 1 || $nthDay > 5) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
|
||||
return;
|
||||
}
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the repetition type is weekly, the moment should be a day between 1-7 (inclusive).
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param int $dayOfWeek
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param int $dayOfWeek
|
||||
*/
|
||||
protected function validateWeekly(Validator $validator, int $index, int $dayOfWeek): void
|
||||
{
|
||||
if ($dayOfWeek < 1 || $dayOfWeek > 7) {
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the repetition type is yearly, the moment should be a valid date.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $moment
|
||||
*/
|
||||
protected function validateYearly(Validator $validator, int $index, string $moment): void
|
||||
{
|
||||
@@ -316,7 +316,7 @@ trait RecurrenceValidation
|
||||
Carbon::createFromFormat('Y-m-d', $moment);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment'));
|
||||
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ trait TransactionValidation
|
||||
/**
|
||||
* Validates the given account information. Switches on given transaction type.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateAccountInformation(Validator $validator): void
|
||||
{
|
||||
@@ -51,7 +51,7 @@ trait TransactionValidation
|
||||
|
||||
Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
@@ -63,7 +63,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -87,10 +87,10 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $transactionType
|
||||
* @param array $transaction
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param string $transactionType
|
||||
* @param array $transaction
|
||||
*/
|
||||
protected function validateSingleAccount(Validator $validator, int $index, string $transactionType, array $transaction): void
|
||||
{
|
||||
@@ -101,10 +101,10 @@ trait TransactionValidation
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
|
||||
// validate source account.
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string) $transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string) $transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string) $transaction['source_number'] : null;
|
||||
$sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
|
||||
$sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null;
|
||||
$sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null;
|
||||
$sourceNumber = array_key_exists('source_number', $transaction) ? (string)$transaction['source_number'] : null;
|
||||
$source = [
|
||||
'id' => $sourceId,
|
||||
'name' => $sourceName,
|
||||
@@ -121,10 +121,10 @@ trait TransactionValidation
|
||||
return;
|
||||
}
|
||||
// validate destination account
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string) $transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string) $transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string) $transaction['destination_number'] : null;
|
||||
$destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
|
||||
$destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null;
|
||||
$destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null;
|
||||
$destinationNumber = array_key_exists('destination_number', $transaction) ? (string)$transaction['destination_number'] : null;
|
||||
$destination = [
|
||||
'id' => $destinationId,
|
||||
'name' => $destinationName,
|
||||
@@ -143,11 +143,11 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param string $transactionType
|
||||
* @param int $index
|
||||
* @param array $source
|
||||
* @param array $destination
|
||||
* @param Validator $validator
|
||||
* @param string $transactionType
|
||||
* @param int $index
|
||||
* @param array $source
|
||||
* @param array $destination
|
||||
* @return void
|
||||
*/
|
||||
protected function sanityCheckReconciliation(Validator $validator, string $transactionType, int $index, array $source, array $destination): void
|
||||
@@ -177,8 +177,8 @@ trait TransactionValidation
|
||||
/**
|
||||
* Validates the given account information. Switches on given transaction type.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
public function validateAccountInformationUpdate(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
@@ -186,7 +186,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
|
||||
/**
|
||||
* @var int $index
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
@@ -195,10 +195,10 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param Validator $validator
|
||||
* @param int $index
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
protected function validateSingleUpdate(Validator $validator, int $index, array $transaction, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
@@ -224,7 +224,7 @@ trait TransactionValidation
|
||||
// validate if the submitted source and / or name are valid
|
||||
if (array_key_exists('source_id', $transaction) || array_key_exists('source_name', $transaction)) {
|
||||
Log::debug('Will try to validate source account information.');
|
||||
$sourceId = (int) ($transaction['source_id'] ?? 0);
|
||||
$sourceId = (int)($transaction['source_id'] ?? 0);
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]);
|
||||
|
||||
@@ -252,7 +252,7 @@ trait TransactionValidation
|
||||
$accountValidator->source = $source;
|
||||
}
|
||||
}
|
||||
$destinationId = (int) ($transaction['destination_id'] ?? 0);
|
||||
$destinationId = (int)($transaction['destination_id'] ?? 0);
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$array = ['id' => $destinationId, 'name' => $destinationName,];
|
||||
$validDestination = $accountValidator->validateDestination($array);
|
||||
@@ -268,8 +268,8 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
* @param array $transactions
|
||||
* @param TransactionGroup $group
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -279,8 +279,8 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param array $transaction
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return Account|null
|
||||
*/
|
||||
@@ -293,7 +293,7 @@ trait TransactionValidation
|
||||
}
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($transactionGroup->transactionJournals as $journal) {
|
||||
if ((int) $journal->id === (int) $transaction['transaction_journal_id']) {
|
||||
if ((int)$journal->id === (int)$transaction['transaction_journal_id']) {
|
||||
return $journal->transactions()->where('amount', '<', 0)->first()->account;
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ trait TransactionValidation
|
||||
/**
|
||||
* Adds an error to the validator when there are no transactions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneRecurrenceTransaction(Validator $validator): void
|
||||
{
|
||||
@@ -313,14 +313,14 @@ trait TransactionValidation
|
||||
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the validator when there are no transactions in the array of data.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateOneTransaction(Validator $validator): void
|
||||
{
|
||||
@@ -328,7 +328,7 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
// need at least one transaction
|
||||
if (0 === count($transactions)) {
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
Log::debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -337,14 +337,14 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateTransactionArray(Validator $validator): void
|
||||
{
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (!is_int($key)) {
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
|
||||
Log::debug('Added error: at_least_one_transaction.');
|
||||
|
||||
return;
|
||||
@@ -355,7 +355,7 @@ trait TransactionValidation
|
||||
/**
|
||||
* All types of splits must be equal.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateTransactionTypes(Validator $validator): void
|
||||
{
|
||||
@@ -368,20 +368,20 @@ trait TransactionValidation
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
$first = $unique[0] ?? 'invalid';
|
||||
if ('invalid' === $first) {
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.invalid_transaction_type'));
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.invalid_transaction_type'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All types of splits must be equal.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateTransactionTypesForUpdate(Validator $validator): void
|
||||
{
|
||||
@@ -389,14 +389,14 @@ trait TransactionValidation
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$types = [];
|
||||
foreach ($transactions as $transaction) {
|
||||
$originalType = $this->getOriginalType((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalType = $this->getOriginalType((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
// if type is not set, fall back to the type of the journal, if one is given.
|
||||
$types[] = $transaction['type'] ?? $originalType;
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
if (count($unique) > 1) {
|
||||
app('log')->warning('Add error for mismatch transaction types.');
|
||||
$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));
|
||||
$validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -404,7 +404,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -423,7 +423,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*/
|
||||
private function validateEqualAccounts(Validator $validator): void
|
||||
{
|
||||
@@ -447,26 +447,26 @@ trait TransactionValidation
|
||||
default:
|
||||
case 'withdrawal':
|
||||
if (count($sources) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
break;
|
||||
case 'deposit':
|
||||
if (count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
break;
|
||||
case'transfer':
|
||||
if (count($sources) > 1 || count($dests) > 1) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*/
|
||||
private function validateEqualAccountsForUpdate(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
{
|
||||
@@ -489,14 +489,14 @@ trait TransactionValidation
|
||||
$result = $this->compareAccountData($type, $comparison);
|
||||
if (false === $result) {
|
||||
if ('withdrawal' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('deposit' === $type) {
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
if ('transfer' === $type) {
|
||||
$validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal'));
|
||||
$validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal'));
|
||||
}
|
||||
app('log')->warning('Add error about equal accounts.');
|
||||
|
||||
@@ -506,7 +506,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $transactions
|
||||
* @param array $transactions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -519,7 +519,7 @@ trait TransactionValidation
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// source or destination may be omitted. If this is the case, use the original source / destination name + ID.
|
||||
$originalData = $this->getOriginalData((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
$originalData = $this->getOriginalData((int)($transaction['transaction_journal_id'] ?? 0));
|
||||
|
||||
// get field.
|
||||
$comparison[$field][] = $transaction[$field] ?? $originalData[$field];
|
||||
@@ -530,7 +530,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -562,8 +562,8 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param array $comparison
|
||||
* @param string $type
|
||||
* @param array $comparison
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -577,7 +577,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $comparison
|
||||
* @param array $comparison
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -596,7 +596,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -606,7 +606,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $comparison
|
||||
* @param array $comparison
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -625,7 +625,7 @@ trait TransactionValidation
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $comparison
|
||||
* @param array $comparison
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
Reference in New Issue
Block a user