Various code cleanup.

This commit is contained in:
James Cole
2021-04-07 07:28:43 +02:00
parent 4ddcb0c965
commit f12744ad8c
180 changed files with 714 additions and 721 deletions

View File

@@ -114,7 +114,7 @@ class AccountCurrencies extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -58,7 +58,7 @@ class BackToJournals extends Command
*/
public function handle(): int
{
// @codeCoverageIgnoreStart
$start = microtime(true);
if (!$this->isMigrated()) {
$this->error('Please run firefly-iii:migrate-to-groups first.');
@@ -71,7 +71,7 @@ class BackToJournals extends Command
if (true === $this->option('force')) {
$this->warn('Forcing the command.');
}
// @codeCoverageIgnoreEnd
$this->migrateAll();
$end = round(microtime(true) - $start, 2);
@@ -87,7 +87,8 @@ class BackToJournals extends Command
private function isMigrated(): bool
{
$configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false);
return (bool)$configVar->data;
return (bool)$configVar->data;
}
/**
@@ -96,7 +97,8 @@ class BackToJournals extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
return (bool)$configVar->data;
return (bool)$configVar->data;
}
/**
@@ -137,15 +139,13 @@ class BackToJournals extends Command
*/
private function getIdsForBudgets(): array
{
$transactions = DB::table('budget_transaction')->distinct()->get(['transaction_id'])->pluck('transaction_id')->toArray();
$transactions = DB::table('budget_transaction')->distinct()->get(['transaction_id'])->pluck('transaction_id')->toArray(); // @phpstan-ignore-line
$array = [];
$chunks = array_chunk($transactions, 500);
foreach ($chunks as $chunk) {
$set = DB::table('transactions')
->whereIn('transactions.id', $chunk)
$set = DB::table('transactions')->whereIn('transactions.id', $chunk)
->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
/** @noinspection SlowArrayOperationsInLoopInspection */
$array = array_merge($array, $set);
}
@@ -162,11 +162,11 @@ class BackToJournals extends Command
/** @var Transaction $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
// @codeCoverageIgnoreStart
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
// @codeCoverageIgnoreEnd
}
/** @var Budget $budget */
$budget = $transaction->budgets->first();
@@ -217,12 +217,12 @@ class BackToJournals extends Command
*/
private function getIdsForCategories(): array
{
$transactions = DB::table('category_transaction')->distinct()->get(['transaction_id'])->pluck('transaction_id')->toArray();
$transactions = DB::table('category_transaction')->distinct()->get(['transaction_id'])->pluck('transaction_id')->toArray(); // @phpstan-ignore-line
$array = [];
$chunks = array_chunk($transactions, 500);
foreach ($chunks as $chunk) {
$set = DB::table('transactions')
$set = DB::table('transactions') // @phpstan-ignore-line
->whereIn('transactions.id', $chunk)
->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
/** @noinspection SlowArrayOperationsInLoopInspection */
@@ -241,11 +241,11 @@ class BackToJournals extends Command
/** @var Transaction $transaction */
$transaction = $journal->transactions->first();
if (null === $transaction) {
// @codeCoverageIgnoreStart
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return;
// @codeCoverageIgnoreEnd
}
/** @var Category $category */
$category = $transaction->categories->first();

View File

@@ -54,13 +54,13 @@ class BudgetLimitCurrency extends Command
public function handle(): int
{
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$count = 0;
$budgetLimits = BudgetLimit::get();
@@ -104,7 +104,7 @@ class BudgetLimitCurrency extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -56,13 +56,13 @@ class CCLiabilities extends Command
{
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first();
@@ -101,7 +101,7 @@ class CCLiabilities extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -54,14 +54,14 @@ class MigrateAttachments extends Command
*/
public function handle(): int
{
// @codeCoverageIgnoreStart
$start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$attachments = Attachment::get();
$count = 0;
@@ -113,7 +113,7 @@ class MigrateAttachments extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -56,13 +56,13 @@ class MigrateJournalNotes extends Command
public function handle(): int
{
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$count = 0;
/** @noinspection PhpUndefinedMethodInspection */
$set = TransactionJournalMeta::whereName('notes')->get();
@@ -80,11 +80,11 @@ class MigrateJournalNotes extends Command
Log::debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id));
try {
$meta->delete();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
} catch (Exception $e) { // @phpstan-ignore-line
Log::error(sprintf('Could not delete old meta entry #%d: %s', $meta->id, $e->getMessage()));
}
// @codeCoverageIgnoreEnd
$count++;
}
@@ -112,7 +112,7 @@ class MigrateJournalNotes extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -87,7 +87,7 @@ class MigrateRecurrenceMeta extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -82,7 +82,7 @@ class MigrateRecurrenceType extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -80,7 +80,7 @@ class MigrateTagLocations extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
private function migrateTagLocations(): void

View File

@@ -75,7 +75,7 @@ class MigrateToGroups extends Command
{
$this->stupidLaravel();
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isMigrated() && true !== $this->option('force')) {
$this->info('Database already seems to be migrated.');
@@ -85,7 +85,7 @@ class MigrateToGroups extends Command
if (true === $this->option('force')) {
$this->warn('Forcing the migration.');
}
// @codeCoverageIgnoreEnd
Log::debug('---- start group migration ----');
$this->makeGroupsFromSplitJournals();
@@ -135,7 +135,7 @@ class MigrateToGroups extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**
@@ -165,11 +165,11 @@ class MigrateToGroups extends Command
{
// double check transaction count.
if ($journal->transactions->count() <= 2) {
// @codeCoverageIgnoreStart
Log::debug(sprintf('Will not try to convert journal #%d because it has 2 or less transactions.', $journal->id));
return;
// @codeCoverageIgnoreEnd
}
Log::debug(sprintf('Will now try to convert journal #%d', $journal->id));
@@ -217,7 +217,7 @@ class MigrateToGroups extends Command
$opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) {
// @codeCoverageIgnoreStart
$this->error(
sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
@@ -226,7 +226,7 @@ class MigrateToGroups extends Command
)
);
continue;
// @codeCoverageIgnoreEnd
}
// overrule journal category with transaction category.

View File

@@ -73,13 +73,13 @@ class MigrateToRules extends Command
$this->stupidLaravel();
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$users = $this->userRepository->all();
/** @var User $user */
@@ -127,7 +127,7 @@ class MigrateToRules extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -75,13 +75,13 @@ class OtherCurrenciesCorrections extends Command
{
$this->stupidLaravel();
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$this->updateOtherJournalsCurrencies();
$this->markAsExecuted();
@@ -120,7 +120,7 @@ class OtherCurrenciesCorrections extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**
@@ -154,18 +154,18 @@ class OtherCurrenciesCorrections extends Command
$leadTransaction = $this->getLeadTransaction($journal);
if (null === $leadTransaction) {
// @codeCoverageIgnoreStart
$this->error(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id));
return;
// @codeCoverageIgnoreEnd
}
/** @var Account $account */
$account = $leadTransaction->account;
$currency = $this->getCurrency($account);
if (null === $currency) {
// @codeCoverageIgnoreStart
$this->error(
sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id
@@ -174,7 +174,7 @@ class OtherCurrenciesCorrections extends Command
$this->count++;
return;
// @codeCoverageIgnoreEnd
}
// fix each transaction:
$journal->transactions->each(
@@ -246,18 +246,18 @@ class OtherCurrenciesCorrections extends Command
{
$accountId = $account->id;
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
return null; // @codeCoverageIgnore
return null;
}
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
return $this->accountCurrencies[$accountId]; // @codeCoverageIgnore
return $this->accountCurrencies[$accountId];
}
$currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) {
// @codeCoverageIgnoreStart
$this->accountCurrencies[$accountId] = 0;
return null;
// @codeCoverageIgnoreEnd
}
$this->accountCurrencies[$accountId] = $currency;

View File

@@ -53,13 +53,13 @@ class RenameAccountMeta extends Command
public function handle(): int
{
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$array = [
'accountRole' => 'account_role',
'ccType' => 'cc_type',
@@ -104,7 +104,7 @@ class RenameAccountMeta extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**

View File

@@ -72,7 +72,7 @@ class TransactionIdentifier extends Command
{
$this->stupidLaravel();
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
@@ -83,7 +83,7 @@ class TransactionIdentifier extends Command
if (!Schema::hasTable('transaction_journals')) {
return 0;
}
// @codeCoverageIgnoreEnd
$journals = $this->cliRepository->getSplitJournals();
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
@@ -128,7 +128,7 @@ class TransactionIdentifier extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**
@@ -178,7 +178,7 @@ class TransactionIdentifier extends Command
->where('amount', $amount)->where('identifier', '=', 0)
->whereNotIn('id', $exclude)
->first();
// @codeCoverageIgnoreStart
} catch (QueryException $e) {
Log::error($e->getMessage());
$this->error('Firefly III could not find the "identifier" field in the "transactions" table.');
@@ -189,7 +189,7 @@ class TransactionIdentifier extends Command
return null;
}
// @codeCoverageIgnoreEnd
return $opposing;
}

View File

@@ -72,13 +72,13 @@ class TransferCurrenciesCorrections extends Command
{
$this->stupidLaravel();
$start = microtime(true);
// @codeCoverageIgnoreStart
if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.');
return 0;
}
// @codeCoverageIgnoreEnd
$this->startUpdateRoutine();
$this->markAsExecuted();
@@ -140,7 +140,7 @@ class TransferCurrenciesCorrections extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}
/**
@@ -167,27 +167,27 @@ class TransferCurrenciesCorrections extends Command
{
$this->resetInformation();
// @codeCoverageIgnoreStart
if ($this->isSplitJournal($transfer)) {
$this->line(sprintf(sprintf('Transaction journal #%d is a split journal. Cannot continue.', $transfer->id)));
return;
}
// @codeCoverageIgnoreEnd
$this->getSourceInformation($transfer);
$this->getDestinationInformation($transfer);
// unexpectedly, either one is null:
// @codeCoverageIgnoreStart
if ($this->isEmptyTransactions()) {
$this->error(sprintf('Source or destination information for transaction journal #%d is null. Cannot fix this one.', $transfer->id));
return;
}
// @codeCoverageIgnoreEnd
// both accounts must have currency preference:
// @codeCoverageIgnoreStart
if ($this->isNoCurrencyPresent()) {
$this->error(
sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id)
@@ -195,7 +195,7 @@ class TransferCurrenciesCorrections extends Command
return;
}
// @codeCoverageIgnoreEnd
// fix source transaction having no currency.
$this->fixSourceNoCurrency();
@@ -270,18 +270,18 @@ class TransferCurrenciesCorrections extends Command
{
$accountId = $account->id;
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
return null; // @codeCoverageIgnore
return null;
}
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
return $this->accountCurrencies[$accountId]; // @codeCoverageIgnore
return $this->accountCurrencies[$accountId];
}
$currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) {
// @codeCoverageIgnoreStart
$this->accountCurrencies[$accountId] = 0;
return null;
// @codeCoverageIgnoreEnd
}
$this->accountCurrencies[$accountId] = $currency;

View File

@@ -56,7 +56,7 @@ class UpgradeSkeleton extends Command
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return false;
}