Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -118,7 +118,7 @@ class CorrectOpeningBalanceCurrencies extends Command
if ((int)$journal->transaction_currency_id !== $currency->id) {
$journal->transaction_currency_id = $currency->id;
$journal->save();
$count = 1;
$count = 1;
}
/** @var Transaction $transaction */
@@ -126,7 +126,7 @@ class CorrectOpeningBalanceCurrencies extends Command
if ($transaction->transaction_currency_id !== $currency->id) {
$transaction->transaction_currency_id = $currency->id;
$transaction->save();
$count = 1;
$count = 1;
}
}

View File

@@ -37,7 +37,7 @@ class CreateAccessTokens extends Command
protected $description = 'Creates user access tokens which are used for command line access to personal data.';
protected $signature = 'firefly-iii:create-access-tokens';
protected $signature = 'firefly-iii:create-access-tokens';
/**
* Execute the console command.
@@ -50,8 +50,8 @@ class CreateAccessTokens extends Command
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$count = 0;
$users = $repository->all();
$count = 0;
$users = $repository->all();
/** @var User $user */
foreach ($users as $user) {

View File

@@ -36,7 +36,7 @@ class CreateLinkTypes extends Command
protected $description = 'Creates all link types.';
protected $signature = 'firefly-iii:create-link-types';
protected $signature = 'firefly-iii:create-link-types';
/**
* Execute the console command.
@@ -51,7 +51,7 @@ class CreateLinkTypes extends Command
'Reimbursement' => ['(partially) reimburses', 'is (partially) reimbursed by'],
];
foreach ($set as $name => $values) {
$link = LinkType::where('name', $name)
$link = LinkType::where('name', $name)
->first()
;
if (null === $link) {

View File

@@ -46,7 +46,7 @@ class DeleteEmptyGroups extends Command
public function handle(): int
{
$groupIds
= TransactionGroup::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
= TransactionGroup::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray()
;

View File

@@ -38,7 +38,7 @@ class DeleteEmptyJournals extends Command
protected $description = 'Delete empty and uneven transaction journals.';
protected $signature = 'firefly-iii:delete-empty-journals';
protected $signature = 'firefly-iii:delete-empty-journals';
/**
* Execute the console command.
@@ -56,7 +56,7 @@ class DeleteEmptyJournals extends Command
*/
private function deleteUnevenJournals(): void
{
$set = Transaction::whereNull('deleted_at')
$set = Transaction::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id')
->get([\DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']) // @phpstan-ignore-line
;

View File

@@ -37,7 +37,7 @@ class DeleteOrphanedTransactions extends Command
protected $description = 'Deletes orphaned transactions.';
protected $signature = 'firefly-iii:delete-orphaned-transactions';
protected $signature = 'firefly-iii:delete-orphaned-transactions';
/**
* Execute the console command.

View File

@@ -37,7 +37,7 @@ class DeleteZeroAmount extends Command
protected $description = 'Delete transactions with zero amount.';
protected $signature = 'firefly-iii:delete-zero-amount';
protected $signature = 'firefly-iii:delete-zero-amount';
/**
* Execute the console command.

View File

@@ -62,17 +62,17 @@ class EnableCurrencies extends Command
private function correctCurrencies(UserGroup $userGroup): void
{
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$repos = app(CurrencyRepositoryInterface::class);
// first check if the user has any default currency (not necessarily the case, so can be forced).
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($userGroup);
Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id));
$found = [$defaultCurrency->id];
$found = [$defaultCurrency->id];
// get all meta entries
/** @var Collection $meta */
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.user_group_id', $userGroup->id)
->where('account_meta.name', 'currency_id')->groupBy('data')->get(['data'])
;
@@ -81,7 +81,7 @@ class EnableCurrencies extends Command
}
// get all from journals:
$journals = TransactionJournal::where('user_group_id', $userGroup->id)
$journals = TransactionJournal::where('user_group_id', $userGroup->id)
->groupBy('transaction_currency_id')->get(['transaction_currency_id'])
;
foreach ($journals as $entry) {
@@ -89,7 +89,7 @@ class EnableCurrencies extends Command
}
// get all from transactions
$transactions = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
$transactions = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_group_id', $userGroup->id)
->groupBy('transactions.transaction_currency_id', 'transactions.foreign_currency_id')
->get(['transactions.transaction_currency_id', 'transactions.foreign_currency_id'])
@@ -100,7 +100,7 @@ class EnableCurrencies extends Command
}
// get all from budget limits
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->groupBy('transaction_currency_id')
->get(['budget_limits.transaction_currency_id'])
;
@@ -108,8 +108,8 @@ class EnableCurrencies extends Command
$found[] = $entry->transaction_currency_id;
}
$found = array_values(array_unique($found));
$found = array_values(
$found = array_values(array_unique($found));
$found = array_values(
array_filter(
$found,
static function (int $currencyId) {
@@ -118,7 +118,7 @@ class EnableCurrencies extends Command
)
);
$valid = new Collection();
$valid = new Collection();
/** @var int $currencyId */
foreach ($found as $currencyId) {
@@ -127,7 +127,7 @@ class EnableCurrencies extends Command
$valid->push($currency);
}
}
$ids = $valid->pluck('id')->toArray();
$ids = $valid->pluck('id')->toArray();
Log::debug(sprintf('Found currencies for user group #%d: %s', $userGroup->id, implode(', ', $ids)));
$userGroup->currencies()->sync($ids);

View File

@@ -60,7 +60,7 @@ class FixAccountTypes extends Command
$this->expected = config('firefly.source_dests');
$expected = config('firefly.source_dests');
$query = TransactionJournal::leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
$query = TransactionJournal::leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id')
->leftJoin(
'transactions as source',
static function (JoinClause $join): void {
@@ -94,7 +94,7 @@ class FixAccountTypes extends Command
}
});
$resultSet = $query->get(
$resultSet = $query->get(
[
'transaction_journals.id',
// 'transaction_type_id as type_id',
@@ -138,7 +138,7 @@ class FixAccountTypes extends Command
private function inspectJournal(TransactionJournal $journal): void
{
app('log')->debug(sprintf('Now inspecting journal #%d', $journal->id));
$transactions = $journal->transactions()->count();
$transactions = $journal->transactions()->count();
if (2 !== $transactions) {
app('log')->debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
$this->friendlyError(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
@@ -165,7 +165,7 @@ class FixAccountTypes extends Command
return;
}
$expectedTypes = $this->expected[$type][$sourceAccountType];
$expectedTypes = $this->expected[$type][$sourceAccountType];
if (!in_array($destAccountType, $expectedTypes, true)) {
app('log')->debug(sprintf('[b] Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
@@ -187,9 +187,9 @@ class FixAccountTypes extends Command
app('log')->debug(sprintf('Going to fix journal #%d', $journal->id));
++$this->count;
// variables:
$sourceType = $source->account->accountType->type;
$destinationType = $dest->account->accountType->type;
$combination = sprintf('%s%s%s', $transactionType, $source->account->accountType->type, $dest->account->accountType->type);
$sourceType = $source->account->accountType->type;
$destinationType = $dest->account->accountType->type;
$combination = sprintf('%s%s%s', $transactionType, $source->account->accountType->type, $dest->account->accountType->type);
app('log')->debug(sprintf('Combination is "%s"', $combination));
if ($this->shouldBeTransfer($transactionType, $sourceType, $destinationType)) {
@@ -214,9 +214,9 @@ class FixAccountTypes extends Command
}
// transaction has no valid source.
$validSources = array_keys($this->expected[$transactionType]);
$canCreateSource = $this->canCreateSource($validSources);
$hasValidSource = $this->hasValidAccountType($validSources, $sourceType);
$validSources = array_keys($this->expected[$transactionType]);
$canCreateSource = $this->canCreateSource($validSources);
$hasValidSource = $this->hasValidAccountType($validSources, $sourceType);
if (!$hasValidSource && $canCreateSource) {
$this->giveNewRevenue($journal, $source);
@@ -279,7 +279,7 @@ class FixAccountTypes extends Command
$withdrawal = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$journal->transactionType()->associate($withdrawal);
$journal->save();
$message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id);
$message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id);
$this->friendlyInfo($message);
app('log')->debug($message);
// check it again:
@@ -329,7 +329,7 @@ class FixAccountTypes extends Command
$oldSource = $source->account;
$source->account()->associate($result);
$source->save();
$message = sprintf(
$message = sprintf(
'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").',
$journal->id,
$oldSource->id,

View File

@@ -62,7 +62,7 @@ class FixFrontpageAccounts extends Command
private function fixPreference(Preference $preference): void
{
$fixed = [];
$fixed = [];
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
@@ -70,7 +70,7 @@ class FixFrontpageAccounts extends Command
return;
}
$repository->setUser($preference->user);
$data = $preference->data;
$data = $preference->data;
if (is_array($data)) {
/** @var string $accountId */
foreach ($data as $accountId) {

View File

@@ -46,8 +46,8 @@ class FixGroupAccounts extends Command
*/
public function handle(): int
{
$groups = [];
$res = TransactionJournal::groupBy('transaction_group_id')
$groups = [];
$res = TransactionJournal::groupBy('transaction_group_id')
->get(['transaction_group_id', \DB::raw('COUNT(transaction_group_id) as the_count')])// @phpstan-ignore-line
;

View File

@@ -39,7 +39,7 @@ class FixIbans extends Command
protected $description = 'Removes spaces from IBANs';
protected $signature = 'firefly-iii:fix-ibans';
private int $count = 0;
private int $count = 0;
/**
* Execute the console command.
@@ -79,13 +79,13 @@ class FixIbans extends Command
/** @var Account $account */
foreach ($accounts as $account) {
$userId = $account->user_id;
$userId = $account->user_id;
$set[$userId] ??= [];
$iban = (string)$account->iban;
$iban = (string)$account->iban;
if ('' === $iban) {
continue;
}
$type = $account->accountType->type;
$type = $account->accountType->type;
if (in_array($type, [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true)) {
$type = 'liabilities';
}

View File

@@ -37,8 +37,8 @@ class FixLongDescriptions extends Command
use ShowsFriendlyMessages;
private const int MAX_LENGTH = 1000;
protected $description = 'Fixes long descriptions in journals and groups.';
protected $signature = 'firefly-iii:fix-long-descriptions';
protected $description = 'Fixes long descriptions in journals and groups.';
protected $signature = 'firefly-iii:fix-long-descriptions';
/**
* Execute the console command.
@@ -58,7 +58,7 @@ class FixLongDescriptions extends Command
}
}
$groups = TransactionGroup::get(['id', 'title']);
$groups = TransactionGroup::get(['id', 'title']);
/** @var TransactionGroup $group */
foreach ($groups as $group) {

View File

@@ -40,9 +40,9 @@ class FixRecurringTransactions extends Command
{
use ShowsFriendlyMessages;
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
private int $count = 0;
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
private int $count = 0;
private RecurringRepositoryInterface $recurringRepos;
private UserRepositoryInterface $userRepos;

View File

@@ -80,7 +80,7 @@ class FixTransactionTypes extends Command
private function fixJournal(TransactionJournal $journal): bool
{
$type = $journal->transactionType->type;
$type = $journal->transactionType->type;
try {
$source = $this->getSourceAccount($journal);
@@ -115,7 +115,7 @@ class FixTransactionTypes extends Command
*/
private function getSourceAccount(TransactionJournal $journal): Account
{
$collection = $journal->transactions->filter(
$collection = $journal->transactions->filter(
static function (Transaction $transaction) {
return $transaction->amount < 0;
}
@@ -131,7 +131,7 @@ class FixTransactionTypes extends Command
$transaction = $collection->first();
/** @var null|Account $account */
$account = $transaction->account;
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('300003: Journal #%d, transaction #%d has no source account.', $journal->id, $transaction->id));
}
@@ -144,7 +144,7 @@ class FixTransactionTypes extends Command
*/
private function getDestinationAccount(TransactionJournal $journal): Account
{
$collection = $journal->transactions->filter(
$collection = $journal->transactions->filter(
static function (Transaction $transaction) {
return $transaction->amount > 0;
}
@@ -160,7 +160,7 @@ class FixTransactionTypes extends Command
$transaction = $collection->first();
/** @var null|Account $account */
$account = $transaction->account;
$account = $transaction->account;
if (null === $account) {
throw new FireflyException(sprintf('300006: Journal #%d, transaction #%d has no destination account.', $journal->id, $transaction->id));
}

View File

@@ -100,13 +100,13 @@ class FixUnevenAmount extends Command
private function fixJournal(int $param): void
{
// one of the transactions is bad.
$journal = TransactionJournal::find($param);
$journal = TransactionJournal::find($param);
if (null === $journal) {
return;
}
/** @var null|Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
$source = $journal->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
$this->friendlyError(
@@ -122,11 +122,11 @@ class FixUnevenAmount extends Command
return;
}
$amount = bcmul('-1', $source->amount);
$amount = bcmul('-1', $source->amount);
// fix amount of destination:
/** @var null|Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
$destination = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $destination) {
$this->friendlyError(
@@ -146,7 +146,7 @@ class FixUnevenAmount extends Command
$destination->amount = $amount;
$destination->save();
$message = sprintf('Corrected amount in transaction journal #%d', $param);
$message = sprintf('Corrected amount in transaction journal #%d', $param);
$this->friendlyInfo($message);
}
}

View File

@@ -48,7 +48,7 @@ class RemoveBills extends Command
if (null === $withdrawal) {
return 0;
}
$journals = TransactionJournal::whereNotNull('bill_id')->where('transaction_type_id', '!=', $withdrawal->id)->get();
$journals = TransactionJournal::whereNotNull('bill_id')->where('transaction_type_id', '!=', $withdrawal->id)->get();
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {

View File

@@ -36,7 +36,7 @@ class RenameMetaFields extends Command
protected $description = 'Rename changed meta fields.';
protected $signature = 'firefly-iii:rename-meta-fields';
private int $count = 0;
private int $count = 0;
/**
* Execute the console command.
@@ -72,7 +72,7 @@ class RenameMetaFields extends Command
private function rename(string $original, string $update): void
{
$total = \DB::table('journal_meta')
$total = \DB::table('journal_meta')
->where('name', '=', $original)
->update(['name' => $update])
;