Reformat various code.

This commit is contained in:
James Cole
2022-03-29 15:00:29 +02:00
parent d1a09ff33b
commit d04efb8325
81 changed files with 662 additions and 662 deletions

View File

@@ -43,6 +43,36 @@ trait GroupValidation
*/
abstract protected function getTransactionsArray(Validator $validator): array;
/**
* @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'];
/** @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]) {
$hasAccountInfo = true;
}
}
// set errors:
if (false === $hasAccountInfo && !$hasJournalId) {
$validator->errors()->add(
sprintf('transactions.%d.source_id', $index), (string) trans('validation.generic_no_source')
);
$validator->errors()->add(
sprintf('transactions.%d.destination_id', $index), (string) trans('validation.generic_no_destination')
);
}
}
// only an issue if there is no transaction_journal_id
}
/**
* Adds an error to the "description" field when the user has submitted no descriptions and no
* journal description.
@@ -83,36 +113,6 @@ trait GroupValidation
}
}
/**
* @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'];
/** @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]) {
$hasAccountInfo = true;
}
}
// set errors:
if (false === $hasAccountInfo && !$hasJournalId) {
$validator->errors()->add(
sprintf('transactions.%d.source_id', $index), (string) trans('validation.generic_no_source')
);
$validator->errors()->add(
sprintf('transactions.%d.destination_id', $index), (string) trans('validation.generic_no_destination')
);
}
}
// only an issue if there is no transaction_journal_id
}
/**
* 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.