mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-09 20:11:22 +00:00
Remove static references
This commit is contained in:
@@ -53,17 +53,17 @@ trait RecurrenceValidation
|
||||
|
||||
// grab model from parameter and try to set the transaction type from it
|
||||
if ('invalid' === $transactionType) {
|
||||
Log::debug('Type is invalid but we will search for it.');
|
||||
app('log')->debug('Type is invalid but we will search for it.');
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->route()->parameter('recurrence');
|
||||
if (null !== $recurrence) {
|
||||
Log::debug('There is a recurrence in the route.');
|
||||
app('log')->debug('There is a recurrence in the route.');
|
||||
// ok so we have a recurrence should be able to extract type somehow.
|
||||
/** @var RecurrenceTransaction|null $first */
|
||||
$first = $recurrence->recurrenceTransactions()->first();
|
||||
if (null !== $first) {
|
||||
$transactionType = $first->transactionType ? $first->transactionType->type : 'withdrawal';
|
||||
Log::debug(sprintf('Determined type to be %s.', $transactionType));
|
||||
app('log')->debug(sprintf('Determined type to be %s.', $transactionType));
|
||||
}
|
||||
if (null === $first) {
|
||||
app('log')->warning('Just going to assume type is a withdrawal.');
|
||||
@@ -77,7 +77,7 @@ trait RecurrenceValidation
|
||||
/** @var AccountValidator $accountValidator */
|
||||
$accountValidator = app(AccountValidator::class);
|
||||
|
||||
Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
|
||||
app('log')->debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$transactionType = $transaction['type'] ?? $transactionType;
|
||||
$accountValidator->setTransactionType($transactionType);
|
||||
@@ -321,7 +321,7 @@ trait RecurrenceValidation
|
||||
try {
|
||||
Carbon::createFromFormat('Y-m-d', $moment);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
|
||||
app('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'));
|
||||
}
|
||||
}
|
||||
@@ -334,7 +334,7 @@ trait RecurrenceValidation
|
||||
*/
|
||||
protected function validateTransactionId(Recurrence $recurrence, Validator $validator): void
|
||||
{
|
||||
Log::debug('Now in validateTransactionId');
|
||||
app('log')->debug('Now in validateTransactionId');
|
||||
$transactions = $this->getTransactionData();
|
||||
$submittedTrCount = count($transactions);
|
||||
|
||||
@@ -353,28 +353,28 @@ trait RecurrenceValidation
|
||||
if (1 === $submittedTrCount && 1 === $originalTrCount) {
|
||||
$first = $transactions[0]; // can safely assume index 0.
|
||||
if (!array_key_exists('id', $first)) {
|
||||
Log::debug('Single count and no ID, done.');
|
||||
app('log')->debug('Single count and no ID, done.');
|
||||
return; // home safe!
|
||||
}
|
||||
$id = $first['id'];
|
||||
if ('' === (string)$id) {
|
||||
Log::debug('Single count and empty ID, done.');
|
||||
app('log')->debug('Single count and empty ID, done.');
|
||||
return; // home safe!
|
||||
}
|
||||
$integer = (int)$id;
|
||||
$secondCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', $integer)->count();
|
||||
Log::debug(sprintf('Result of ID count: %d', $secondCount));
|
||||
app('log')->debug(sprintf('Result of ID count: %d', $secondCount));
|
||||
if (0 === $secondCount) {
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.id_does_not_match', ['id' => $integer]));
|
||||
}
|
||||
Log::debug('Single ID validation done.');
|
||||
app('log')->debug('Single ID validation done.');
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('Multi ID validation.');
|
||||
app('log')->debug('Multi ID validation.');
|
||||
$idsMandatory = false;
|
||||
if ($submittedTrCount < $originalTrCount) {
|
||||
Log::debug(sprintf('User submits %d transaction, recurrence has %d transactions. All entries must have ID.', $submittedTrCount, $originalTrCount));
|
||||
app('log')->debug(sprintf('User submits %d transaction, recurrence has %d transactions. All entries must have ID.', $submittedTrCount, $originalTrCount));
|
||||
$idsMandatory = true;
|
||||
}
|
||||
/**
|
||||
@@ -391,7 +391,7 @@ trait RecurrenceValidation
|
||||
$unmatchedIds = 0;
|
||||
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
Log::debug(sprintf('Now at %d/%d', $index + 1, $submittedTrCount));
|
||||
app('log')->debug(sprintf('Now at %d/%d', $index + 1, $submittedTrCount));
|
||||
if (!is_array($transaction)) {
|
||||
app('log')->warning('Not an array. Give error.');
|
||||
$validator->errors()->add(sprintf('transactions.%d.id', $index), (string)trans('validation.at_least_one_transaction'));
|
||||
@@ -403,26 +403,26 @@ trait RecurrenceValidation
|
||||
return;
|
||||
}
|
||||
if (array_key_exists('id', $transaction)) { // don't matter if $idsMandatory
|
||||
Log::debug('Array has ID.');
|
||||
app('log')->debug('Array has ID.');
|
||||
$idCount = $recurrence->recurrenceTransactions()->where('recurrences_transactions.id', (int)$transaction['id'])->count();
|
||||
if (0 === $idCount) {
|
||||
Log::debug('ID does not exist or no match. Count another unmatched ID.');
|
||||
app('log')->debug('ID does not exist or no match. Count another unmatched ID.');
|
||||
$unmatchedIds++;
|
||||
}
|
||||
}
|
||||
if (!array_key_exists('id', $transaction) && !$idsMandatory) {
|
||||
Log::debug('Array has no ID but was not mandatory at this point.');
|
||||
app('log')->debug('Array has no ID but was not mandatory at this point.');
|
||||
$unmatchedIds++;
|
||||
}
|
||||
}
|
||||
// if too many don't match, but you haven't submitted more than already present:
|
||||
$maxUnmatched = max(1, $submittedTrCount - $originalTrCount);
|
||||
Log::debug(sprintf('Submitted: %d. Original: %d. User can submit %d unmatched transactions.', $submittedTrCount, $originalTrCount, $maxUnmatched));
|
||||
app('log')->debug(sprintf('Submitted: %d. Original: %d. User can submit %d unmatched transactions.', $submittedTrCount, $originalTrCount, $maxUnmatched));
|
||||
if ($unmatchedIds > $maxUnmatched) {
|
||||
app('log')->warning(sprintf('Too many unmatched transactions (%d).', $unmatchedIds));
|
||||
$validator->errors()->add('transactions.0.id', (string)trans('validation.too_many_unmatched'));
|
||||
return;
|
||||
}
|
||||
Log::debug('Done with ID validation.');
|
||||
app('log')->debug('Done with ID validation.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user