Various code cleanup.

This commit is contained in:
James Cole
2023-11-05 19:41:37 +01:00
parent a0564751d6
commit 1d2e95f5af
136 changed files with 1171 additions and 514 deletions

View File

@@ -169,7 +169,7 @@ class BackToJournals extends Command
// both have a budget, but they don't match.
if (null !== $budget && null !== $journalBudget && $budget->id !== $journalBudget->id) {
// sync to journal:
$journal->budgets()->sync([(int)$budget->id]);
$journal->budgets()->sync([$budget->id]);
return;
}
@@ -177,7 +177,7 @@ class BackToJournals extends Command
// transaction has a budget, but the journal doesn't.
if (null !== $budget && null === $journalBudget) {
// sync to journal:
$journal->budgets()->sync([(int)$budget->id]);
$journal->budgets()->sync([$budget->id]);
}
}
@@ -241,12 +241,12 @@ class BackToJournals extends Command
// both have a category, but they don't match.
if (null !== $category && null !== $journalCategory && $category->id !== $journalCategory->id) {
// sync to journal:
$journal->categories()->sync([(int)$category->id]);
$journal->categories()->sync([$category->id]);
}
// transaction has a category, but the journal doesn't.
if (null !== $category && null === $journalCategory) {
$journal->categories()->sync([(int)$category->id]);
$journal->categories()->sync([$category->id]);
}
}

View File

@@ -99,7 +99,7 @@ class MigrateRecurrenceType extends Command
*/
private function migrateRecurrence(Recurrence $recurrence): void
{
$originalType = (int)$recurrence->transaction_type_id;
$originalType = $recurrence->transaction_type_id;
$newType = $this->getInvalidType();
$recurrence->transaction_type_id = $newType->id;
$recurrence->save();

View File

@@ -335,7 +335,7 @@ class MigrateToGroups extends Command
if (null !== $budget) {
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id));
return (int)$budget->id;
return $budget->id;
}
// try to get a budget ID from the right transaction:
@@ -344,7 +344,7 @@ class MigrateToGroups extends Command
if (null !== $budget) {
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id));
return (int)$budget->id;
return $budget->id;
}
app('log')->debug('Neither left or right have a budget, return NULL');
@@ -368,7 +368,7 @@ class MigrateToGroups extends Command
if (null !== $category) {
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id));
return (int)$category->id;
return $category->id;
}
// try to get a category ID from the left transaction:
@@ -377,7 +377,7 @@ class MigrateToGroups extends Command
if (null !== $category) {
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id));
return (int)$category->id;
return $category->id;
}
app('log')->debug('Neither left or right have a category, return NULL');

View File

@@ -169,8 +169,8 @@ class OtherCurrenciesCorrections extends Command
}
// when mismatch in transaction:
if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {
$transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;
if ($transaction->transaction_currency_id !== $currency->id) {
$transaction->foreign_currency_id = $transaction->transaction_currency_id;
$transaction->foreign_amount = $transaction->amount;
$transaction->transaction_currency_id = $currency->id;
$transaction->save();

View File

@@ -161,7 +161,7 @@ class TransactionIdentifier extends Command
private function findOpposing(Transaction $transaction, array $exclude): ?Transaction
{
// find opposing:
$amount = bcmul((string)$transaction->amount, '-1');
$amount = bcmul($transaction->amount, '-1');
try {
/** @var Transaction $opposing */

View File

@@ -349,7 +349,7 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
$this->sourceTransaction
->transaction_currency_id
= (int)$this->sourceCurrency->id;
= $this->sourceCurrency->id;
$message = sprintf(
'Transaction #%d has no currency setting, now set to %s.',
$this->sourceTransaction->id,
@@ -369,7 +369,7 @@ class TransferCurrenciesCorrections extends Command
{
if (null !== $this->sourceCurrency
&& null === $this->sourceTransaction->foreign_amount
&& (int)$this->sourceTransaction->transaction_currency_id !== (int)$this->sourceCurrency->id
&& (int)$this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
) {
$message = sprintf(
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
@@ -380,7 +380,7 @@ class TransferCurrenciesCorrections extends Command
);
$this->friendlyWarning($message);
$this->count++;
$this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id;
$this->sourceTransaction->transaction_currency_id = $this->sourceCurrency->id;
$this->sourceTransaction->save();
}
}
@@ -394,7 +394,7 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
$this->destinationTransaction
->transaction_currency_id
= (int)$this->destinationCurrency->id;
= $this->destinationCurrency->id;
$message = sprintf(
'Transaction #%d has no currency setting, now set to %s.',
$this->destinationTransaction->id,
@@ -414,7 +414,7 @@ class TransferCurrenciesCorrections extends Command
{
if (null !== $this->destinationCurrency
&& null === $this->destinationTransaction->foreign_amount
&& (int)$this->destinationTransaction->transaction_currency_id !== (int)$this->destinationCurrency->id
&& (int)$this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
) {
$message = sprintf(
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
@@ -425,7 +425,7 @@ class TransferCurrenciesCorrections extends Command
);
$this->friendlyWarning($message);
$this->count++;
$this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id;
$this->destinationTransaction->transaction_currency_id = $this->destinationCurrency->id;
$this->destinationTransaction->save();
}
}
@@ -437,7 +437,7 @@ class TransferCurrenciesCorrections extends Command
*/
private function fixInvalidForeignCurrency(): void
{
if ((int)$this->destinationCurrency->id === (int)$this->sourceCurrency->id) {
if ($this->destinationCurrency->id === $this->sourceCurrency->id) {
// update both transactions to match:
$this->sourceTransaction->foreign_amount = null;
$this->sourceTransaction->foreign_currency_id = null;
@@ -457,7 +457,7 @@ class TransferCurrenciesCorrections extends Command
*/
private function fixMismatchedForeignCurrency(): void
{
if ((int)$this->sourceCurrency->id !== (int)$this->destinationCurrency->id) {
if ($this->sourceCurrency->id !== $this->destinationCurrency->id) {
$this->sourceTransaction->transaction_currency_id = $this->sourceCurrency->id;
$this->sourceTransaction->foreign_currency_id = $this->destinationCurrency->id;
$this->destinationTransaction->transaction_currency_id = $this->sourceCurrency->id;
@@ -479,7 +479,7 @@ class TransferCurrenciesCorrections extends Command
private function fixSourceNullForeignAmount(): void
{
if (null === $this->sourceTransaction->foreign_amount && null !== $this->destinationTransaction->foreign_amount) {
$this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1');
$this->sourceTransaction->foreign_amount = bcmul($this->destinationTransaction->foreign_amount, '-1');
$this->sourceTransaction->save();
$this->count++;
$this->friendlyInfo(
@@ -499,7 +499,7 @@ class TransferCurrenciesCorrections extends Command
private function fixDestNullForeignAmount(): void
{
if (null === $this->destinationTransaction->foreign_amount && null !== $this->sourceTransaction->foreign_amount) {
$this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1');
$this->destinationTransaction->foreign_amount = bcmul($this->sourceTransaction->foreign_amount, '-1');
$this->destinationTransaction->save();
$this->count++;
$this->friendlyInfo(
@@ -519,7 +519,7 @@ class TransferCurrenciesCorrections extends Command
*/
private function fixTransactionJournalCurrency(TransactionJournal $journal): void
{
if ((int)$journal->transaction_currency_id !== (int)$this->sourceCurrency->id) {
if ((int)$journal->transaction_currency_id !== $this->sourceCurrency->id) {
$oldCurrencyCode = $journal->transactionCurrency->code ?? '(nothing)';
$journal->transaction_currency_id = $this->sourceCurrency->id;
$message = sprintf(

View File

@@ -149,9 +149,9 @@ class UpgradeLiabilities extends Command
return;
}
// source MUST be the liability.
if ((int)$destination->account_id === (int)$account->id) {
if ($destination->account_id === $account->id) {
// so if not, switch things around:
$sourceAccountId = (int)$source->account_id;
$sourceAccountId = $source->account_id;
$source->account_id = $destination->account_id;
$destination->account_id = $sourceAccountId;
$source->save();

View File

@@ -238,10 +238,10 @@ class UpgradeLiabilitiesEight extends Command
// if source is this liability and destination is expense, remove transaction.
// if source is revenue and destination is liability, remove transaction.
if ((int)$source->account_id === (int)$account->id && $dest->account->accountType->type === AccountType::EXPENSE) {
if ($source->account_id === $account->id && $dest->account->accountType->type === AccountType::EXPENSE) {
$delete = true;
}
if ((int)$dest->account_id === (int)$account->id && $source->account->accountType->type === AccountType::REVENUE) {
if ($dest->account_id === $account->id && $source->account->accountType->type === AccountType::REVENUE) {
$delete = true;
}