Use PSR-12 code style

This commit is contained in:
James Cole
2022-10-30 12:23:16 +01:00
parent 8edfb1460c
commit bdcd9825ec
32 changed files with 78 additions and 105 deletions

View File

@@ -62,8 +62,7 @@ class CorrectOpeningBalanceCurrencies extends Command
{ {
Log::debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
// get all OB journals: // get all OB journals:
$set = TransactionJournal $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']); ->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);

View File

@@ -63,7 +63,7 @@ class CreateLinkTypes extends Command
$link = LinkType::where('name', $name) $link = LinkType::where('name', $name)
->first(); ->first();
if (null === $link) { if (null === $link) {
$link = new LinkType; $link = new LinkType();
$link->name = $name; $link->name = $name;
$link->inward = $values[1]; $link->inward = $values[1];
$link->outward = $values[0]; $link->outward = $values[0];

View File

@@ -58,8 +58,7 @@ class DeleteEmptyGroups extends Command
Log::debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$start = microtime(true); $start = microtime(true);
$groupIds $groupIds
= TransactionGroup = TransactionGroup::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray(); ->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray();
$total = count($groupIds); $total = count($groupIds);

View File

@@ -66,8 +66,7 @@ class DeleteEmptyJournals extends Command
*/ */
private function deleteUnevenJournals(): void private function deleteUnevenJournals(): void
{ {
$set = Transaction $set = Transaction::whereNull('deleted_at')
::whereNull('deleted_at')
->groupBy('transactions.transaction_journal_id') ->groupBy('transactions.transaction_journal_id')
->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); ->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']);
$total = 0; $total = 0;
@@ -78,7 +77,6 @@ class DeleteEmptyJournals extends Command
// uneven number, delete journal and transactions: // uneven number, delete journal and transactions:
try { try {
TransactionJournal::find((int) $row->transaction_journal_id)->delete(); TransactionJournal::find((int) $row->transaction_journal_id)->delete();
} catch (Exception $e) { // @phpstan-ignore-line } catch (Exception $e) { // @phpstan-ignore-line
Log::info(sprintf('Could not delete journal: %s', $e->getMessage())); Log::info(sprintf('Could not delete journal: %s', $e->getMessage()));
} }
@@ -106,7 +104,6 @@ class DeleteEmptyJournals extends Command
foreach ($set as $entry) { foreach ($set as $entry) {
try { try {
TransactionJournal::find($entry->id)->delete(); TransactionJournal::find($entry->id)->delete();
} catch (Exception $e) { // @phpstan-ignore-line } catch (Exception $e) { // @phpstan-ignore-line
Log::info(sprintf('Could not delete entry: %s', $e->getMessage())); Log::info(sprintf('Could not delete entry: %s', $e->getMessage()));
} }
@@ -121,5 +118,4 @@ class DeleteEmptyJournals extends Command
$end = round(microtime(true) - $start, 2); $end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty journals in %s seconds', $end)); $this->info(sprintf('Verified empty journals in %s seconds', $end));
} }
} }

View File

@@ -72,8 +72,7 @@ class DeleteOrphanedTransactions extends Command
private function deleteOrphanedTransactions(): void private function deleteOrphanedTransactions(): void
{ {
$count = 0; $count = 0;
$set = Transaction $set = Transaction::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->whereNotNull('transaction_journals.deleted_at') ->whereNotNull('transaction_journals.deleted_at')
->whereNull('transactions.deleted_at') ->whereNull('transactions.deleted_at')
->whereNotNull('transactions.id') ->whereNotNull('transactions.id')
@@ -109,8 +108,7 @@ class DeleteOrphanedTransactions extends Command
private function deleteFromOrphanedAccounts(): void private function deleteFromOrphanedAccounts(): void
{ {
$set $set
= Transaction = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->whereNotNull('accounts.deleted_at') ->whereNotNull('accounts.deleted_at')
->get(['transactions.*']); ->get(['transactions.*']);
$count = 0; $count = 0;
@@ -121,11 +119,9 @@ class DeleteOrphanedTransactions extends Command
if ($journal) { if ($journal) {
try { try {
$journal->delete(); $journal->delete();
} catch (Exception $e) { // @phpstan-ignore-line } catch (Exception $e) { // @phpstan-ignore-line
Log::info(sprintf('Could not delete journal %s', $e->getMessage())); Log::info(sprintf('Could not delete journal %s', $e->getMessage()));
} }
} }
Transaction::where('transaction_journal_id', (int) $transaction->transaction_journal_id)->delete(); Transaction::where('transaction_journal_id', (int) $transaction->transaction_journal_id)->delete();
$this->line( $this->line(
@@ -144,8 +140,7 @@ class DeleteOrphanedTransactions extends Command
private function deleteOrphanedJournals(): void private function deleteOrphanedJournals(): void
{ {
$set = TransactionJournal $set = TransactionJournal::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
->whereNotNull('transaction_groups.deleted_at') ->whereNotNull('transaction_groups.deleted_at')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']); ->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']);

View File

@@ -62,7 +62,6 @@ class DeleteZeroAmount extends Command
$this->info(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id)); $this->info(sprintf('Deleted transaction journal #%d because the amount is zero (0.00).', $journal->id));
try { try {
$journal->delete(); $journal->delete();
} catch (Exception $e) { // @phpstan-ignore-line } catch (Exception $e) { // @phpstan-ignore-line
$this->line($e->getMessage()); $this->line($e->getMessage());
} }

View File

@@ -88,7 +88,8 @@ class EnableCurrencies extends Command
$found = array_values(array_unique($found)); $found = array_values(array_unique($found));
$found = array_values( $found = array_values(
array_filter( array_filter(
$found, function (int $currencyId) { $found,
function (int $currencyId) {
return $currencyId !== 0; return $currencyId !== 0;
} }
) )

View File

@@ -121,12 +121,10 @@ class FixAccountTypes extends Command
$destAccountType = $destAccount->accountType->type; $destAccountType = $destAccount->accountType->type;
if (!array_key_exists($type, $this->expected)) { if (!array_key_exists($type, $this->expected)) {
Log::info(sprintf('No source/destination info for transaction type %s.', $type)); Log::info(sprintf('No source/destination info for transaction type %s.', $type));
$this->info(sprintf('No source/destination info for transaction type %s.', $type)); $this->info(sprintf('No source/destination info for transaction type %s.', $type));
return; return;
} }
if (!array_key_exists($sourceAccountType, $this->expected[$type])) { if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id)); Log::debug(sprintf('Going to fix journal #%d', $journal->id));
@@ -211,8 +209,12 @@ class FixAccountTypes extends Command
$dest->account()->associate($result); $dest->account()->associate($result);
$dest->save(); $dest->save();
$message = sprintf( $message = sprintf(
'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldDest->id, $oldDest->name, 'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").',
$result->id, $result->name $journal->id,
$oldDest->id,
$oldDest->name,
$result->id,
$result->name
); );
$this->info($message); $this->info($message);
Log::debug($message); Log::debug($message);
@@ -227,8 +229,12 @@ class FixAccountTypes extends Command
$source->account()->associate($result); $source->account()->associate($result);
$source->save(); $source->save();
$message = sprintf( $message = sprintf(
'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldSource->id, $oldSource->name, 'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").',
$result->id, $result->name $journal->id,
$oldSource->id,
$oldSource->name,
$result->id,
$result->name
); );
$this->info($message); $this->info($message);
Log::debug($message); Log::debug($message);
@@ -244,7 +250,6 @@ class FixAccountTypes extends Command
Log::debug($message); Log::debug($message);
break; break;
} }
} }
} }

View File

@@ -57,8 +57,7 @@ class FixGroupAccounts extends Command
public function handle(): int public function handle(): int
{ {
$groups = []; $groups = [];
$res = TransactionJournal $res = TransactionJournal::groupBy('transaction_group_id')
::groupBy('transaction_group_id')
->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]); ->get(['transaction_group_id', DB::raw('COUNT(transaction_group_id) as the_count')]);
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($res as $journal) { foreach ($res as $journal) {
@@ -66,7 +65,7 @@ class FixGroupAccounts extends Command
$groups[] = (int) $journal->transaction_group_id; $groups[] = (int) $journal->transaction_group_id;
} }
} }
$handler = new UpdatedGroupEventHandler; $handler = new UpdatedGroupEventHandler();
foreach ($groups as $groupId) { foreach ($groups as $groupId) {
$group = TransactionGroup::find($groupId); $group = TransactionGroup::find($groupId);
$event = new UpdatedTransactionGroup($group); $event = new UpdatedTransactionGroup($group);

View File

@@ -57,7 +57,6 @@ class FixIbans extends Command
foreach ($accounts as $account) { foreach ($accounts as $account) {
$iban = $account->iban; $iban = $account->iban;
if (str_contains($iban, ' ')) { if (str_contains($iban, ' ')) {
$iban = app('steam')->filterSpaces((string) $account->iban); $iban = app('steam')->filterSpaces((string) $account->iban);
if ('' !== $iban) { if ('' !== $iban) {
$account->iban = $iban; $account->iban = $iban;

View File

@@ -61,7 +61,6 @@ class FixPiggies extends Command
/** @var PiggyBankEvent $event */ /** @var PiggyBankEvent $event */
foreach ($set as $event) { foreach ($set as $event) {
if (null === $event->transaction_journal_id) { if (null === $event->transaction_journal_id) {
continue; continue;
} }

View File

@@ -52,7 +52,6 @@ class FixPostgresSequences extends Command
*/ */
public function handle(): int public function handle(): int
{ {
if (DB::connection()->getName() !== 'pgsql') { if (DB::connection()->getName() !== 'pgsql') {
$this->info('Command executed successfully.'); $this->info('Command executed successfully.');

View File

@@ -85,8 +85,7 @@ class FixTransactionTypes extends Command
*/ */
private function collectJournals(): Collection private function collectJournals(): Collection
{ {
return TransactionJournal return TransactionJournal::with(['transactionType', 'transactions', 'transactions.account', 'transactions.account.accountType'])
::with(['transactionType', 'transactions', 'transactions.account', 'transactions.account.accountType'])
->get(); ->get();
} }
@@ -109,10 +108,15 @@ class FixTransactionTypes extends Command
$expectedType = (string) config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type)); $expectedType = (string) config(sprintf('firefly.account_to_transaction.%s.%s', $source->accountType->type, $destination->accountType->type));
if ($expectedType !== $type) { if ($expectedType !== $type) {
$this->line( $this->line(
sprintf('Transaction journal #%d was of type "%s" but is corrected to "%s" (%s -> %s)', sprintf(
$journal->id, $type, $expectedType, 'Transaction journal #%d was of type "%s" but is corrected to "%s" (%s -> %s)',
$source->accountType->type, $destination->accountType->type, $journal->id,
)); $type,
$expectedType,
$source->accountType->type,
$destination->accountType->type,
)
);
$this->changeJournal($journal, $expectedType); $this->changeJournal($journal, $expectedType);
return true; return true;

View File

@@ -97,6 +97,5 @@ class CreateFirstUser extends Command
private function stupidLaravel(): void private function stupidLaravel(): void
{ {
$this->repository = app(UserRepositoryInterface::class); $this->repository = app(UserRepositoryInterface::class);
} }
} }

View File

@@ -230,8 +230,8 @@ class ExportData extends Command
*/ */
private function getAccountsParameter(): Collection private function getAccountsParameter(): Collection
{ {
$final = new Collection; $final = new Collection();
$accounts = new Collection; $accounts = new Collection();
$accountList = $this->option('accounts'); $accountList = $this->option('accounts');
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
if (null !== $accountList && '' !== (string) $accountList) { if (null !== $accountList && '' !== (string) $accountList) {

View File

@@ -131,7 +131,6 @@ class ReportEmptyObjects extends Command
/** @var stdClass $entry */ /** @var stdClass $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$line = sprintf( $line = sprintf(
'User #%d (%s) has tag #%d ("%s") which has no transaction journals.', 'User #%d (%s) has tag #%d ("%s") which has no transaction journals.',
$entry->user_id, $entry->user_id,

View File

@@ -34,7 +34,6 @@ use Schema;
*/ */
class ReportIntegrity extends Command class ReportIntegrity extends Command
{ {
/** /**
* The console command description. * The console command description.
* *

View File

@@ -79,6 +79,5 @@ class ReportSum extends Command
} }
$end = round(microtime(true) - $start, 2); $end = round(microtime(true) - $start, 2);
$this->info(sprintf('Report on total sum finished in %s seconds', $end)); $this->info(sprintf('Report on total sum finished in %s seconds', $end));
} }
} }

View File

@@ -161,13 +161,13 @@ class ApplyRules extends Command
private function stupidLaravel(): void private function stupidLaravel(): void
{ {
$this->allRules = false; $this->allRules = false;
$this->accounts = new Collection; $this->accounts = new Collection();
$this->ruleSelection = []; $this->ruleSelection = [];
$this->ruleGroupSelection = []; $this->ruleGroupSelection = [];
$this->ruleRepository = app(RuleRepositoryInterface::class); $this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class); $this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->acceptedAccounts = [AccountType::DEFAULT, AccountType::DEBT, AccountType::ASSET, AccountType::LOAN, AccountType::MORTGAGE]; $this->acceptedAccounts = [AccountType::DEFAULT, AccountType::DEBT, AccountType::ASSET, AccountType::LOAN, AccountType::MORTGAGE];
$this->groups = new Collection; $this->groups = new Collection();
} }
/** /**
@@ -205,7 +205,7 @@ class ApplyRules extends Command
return false; return false;
} }
$finalList = new Collection; $finalList = new Collection();
$accountList = explode(',', $accountString); $accountList = explode(',', $accountString);
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
@@ -227,7 +227,6 @@ class ApplyRules extends Command
$this->accounts = $finalList; $this->accounts = $finalList;
return true; return true;
} }
/** /**
@@ -325,7 +324,7 @@ class ApplyRules extends Command
*/ */
private function getRulesToApply(): Collection private function getRulesToApply(): Collection
{ {
$rulesToApply = new Collection; $rulesToApply = new Collection();
/** @var RuleGroup $group */ /** @var RuleGroup $group */
foreach ($this->groups as $group) { foreach ($this->groups as $group) {
$rules = $this->ruleGroupRepository->getActiveStoreRules($group); $rules = $this->ruleGroupRepository->getActiveStoreRules($group);

View File

@@ -129,7 +129,7 @@ class Cron extends Command
*/ */
private function recurringCronJob(bool $force, ?Carbon $date): void private function recurringCronJob(bool $force, ?Carbon $date): void
{ {
$recurring = new RecurringCronjob; $recurring = new RecurringCronjob();
$recurring->setForce($force); $recurring->setForce($force);
// set date in cron job: // set date in cron job:
@@ -156,7 +156,7 @@ class Cron extends Command
*/ */
private function autoBudgetCronJob(bool $force, ?Carbon $date): void private function autoBudgetCronJob(bool $force, ?Carbon $date): void
{ {
$autoBudget = new AutoBudgetCronjob; $autoBudget = new AutoBudgetCronjob();
$autoBudget->setForce($force); $autoBudget->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if (null !== $date) {
@@ -174,7 +174,6 @@ class Cron extends Command
if ($autoBudget->jobSucceeded) { if ($autoBudget->jobSucceeded) {
$this->info(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message)); $this->info(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message));
} }
} }
/** /**
@@ -184,7 +183,7 @@ class Cron extends Command
*/ */
private function billWarningCronJob(bool $force, ?Carbon $date): void private function billWarningCronJob(bool $force, ?Carbon $date): void
{ {
$autoBudget = new BillWarningCronjob; $autoBudget = new BillWarningCronjob();
$autoBudget->setForce($force); $autoBudget->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if (null !== $date) {
@@ -202,7 +201,6 @@ class Cron extends Command
if ($autoBudget->jobSucceeded) { if ($autoBudget->jobSucceeded) {
$this->info(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message)); $this->info(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
} }
} }
/** /**
@@ -212,7 +210,7 @@ class Cron extends Command
*/ */
private function exchangeRatesCronJob(bool $force, ?Carbon $date): void private function exchangeRatesCronJob(bool $force, ?Carbon $date): void
{ {
$exchangeRates = new ExchangeRatesCronjob; $exchangeRates = new ExchangeRatesCronjob();
$exchangeRates->setForce($force); $exchangeRates->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if (null !== $date) {
@@ -230,6 +228,5 @@ class Cron extends Command
if ($exchangeRates->jobSucceeded) { if ($exchangeRates->jobSucceeded) {
$this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); $this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
} }
} }
} }

View File

@@ -103,7 +103,10 @@ class AppendBudgetLimitPeriods extends Command
if (null === $period) { if (null === $period) {
$message = sprintf( $message = sprintf(
'Could not guesstimate budget limit #%d (%s - %s) period.', $limit->id, $limit->start_date->format('Y-m-d'), $limit->end_date->format('Y-m-d') 'Could not guesstimate budget limit #%d (%s - %s) period.',
$limit->id,
$limit->start_date->format('Y-m-d'),
$limit->end_date->format('Y-m-d')
); );
$this->warn($message); $this->warn($message);
Log::warning($message); Log::warning($message);
@@ -114,10 +117,13 @@ class AppendBudgetLimitPeriods extends Command
$limit->save(); $limit->save();
$msg = sprintf( $msg = sprintf(
'Budget limit #%d (%s - %s) period is "%s".', $limit->id, $limit->start_date->format('Y-m-d'), $limit->end_date->format('Y-m-d'), $period 'Budget limit #%d (%s - %s) period is "%s".',
$limit->id,
$limit->start_date->format('Y-m-d'),
$limit->end_date->format('Y-m-d'),
$period
); );
Log::debug($msg); Log::debug($msg);
} }
/** /**
@@ -159,8 +165,8 @@ class AppendBudgetLimitPeriods extends Command
$start = ['1-1', '1-7']; $start = ['1-1', '1-7'];
$end = ['30-6', '31-12']; $end = ['30-6', '31-12'];
if ( if (
in_array($limit->start_date->format('j-n'), $start) // start of quarter in_array($limit->start_date->format('j-n'), $start, true) // start of quarter
&& in_array($limit->end_date->format('j-n'), $end) // end of quarter && in_array($limit->end_date->format('j-n'), $end, true) // end of quarter
&& 5 === $limit->start_date->diffInMonths($limit->end_date) && 5 === $limit->start_date->diffInMonths($limit->end_date)
) { ) {
return 'half_year'; return 'half_year';

View File

@@ -60,7 +60,6 @@ class BackToJournals extends Command
*/ */
public function handle(): int public function handle(): int
{ {
$start = microtime(true); $start = microtime(true);
if (!$this->isMigrated()) { if (!$this->isMigrated()) {
$this->error('Please run firefly-iii:migrate-to-groups first.'); $this->error('Please run firefly-iii:migrate-to-groups first.');
@@ -128,7 +127,7 @@ class BackToJournals extends Command
*/ */
private function migrateBudgets(): void private function migrateBudgets(): void
{ {
$journals = new Collection; $journals = new Collection();
$allIds = $this->getIdsForBudgets(); $allIds = $this->getIdsForBudgets();
$chunks = array_chunk($allIds, 500); $chunks = array_chunk($allIds, 500);
foreach ($chunks as $journalIds) { foreach ($chunks as $journalIds) {
@@ -164,16 +163,13 @@ class BackToJournals extends Command
*/ */
private function migrateBudgetsForJournal(TransactionJournal $journal): void private function migrateBudgetsForJournal(TransactionJournal $journal): void
{ {
// grab category from first transaction // grab category from first transaction
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $journal->transactions->first(); $transaction = $journal->transactions->first();
if (null === $transaction) { if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); $this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return; return;
} }
/** @var Budget $budget */ /** @var Budget $budget */
$budget = $transaction->budgets->first(); $budget = $transaction->budgets->first();
@@ -201,7 +197,7 @@ class BackToJournals extends Command
private function migrateCategories(): void private function migrateCategories(): void
{ {
Log::debug('Now in migrateCategories()'); Log::debug('Now in migrateCategories()');
$journals = new Collection; $journals = new Collection();
$allIds = $this->getIdsForCategories(); $allIds = $this->getIdsForCategories();
Log::debug(sprintf('Total: %d', count($allIds))); Log::debug(sprintf('Total: %d', count($allIds)));
@@ -247,11 +243,9 @@ class BackToJournals extends Command
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $journal->transactions->first(); $transaction = $journal->transactions->first();
if (null === $transaction) { if (null === $transaction) {
$this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id)); $this->info(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
return; return;
} }
/** @var Category $category */ /** @var Category $category */
$category = $transaction->categories->first(); $category = $transaction->categories->first();

View File

@@ -56,7 +56,6 @@ class MigrateAttachments extends Command
*/ */
public function handle(): int public function handle(): int
{ {
$start = microtime(true); $start = microtime(true);
if ($this->isExecuted() && true !== $this->option('force')) { if ($this->isExecuted() && true !== $this->option('force')) {
$this->warn('This command has already been executed.'); $this->warn('This command has already been executed.');
@@ -70,15 +69,13 @@ class MigrateAttachments extends Command
/** @var Attachment $att */ /** @var Attachment $att */
foreach ($attachments as $att) { foreach ($attachments as $att) {
// move description: // move description:
$attDescription = (string) $att->description; $attDescription = (string) $att->description;
if ('' !== $attDescription) { if ('' !== $attDescription) {
// find or create note: // find or create note:
$note = $att->notes()->first(); $note = $att->notes()->first();
if (null === $note) { if (null === $note) {
$note = new Note; $note = new Note();
$note->noteable()->associate($att); $note->noteable()->associate($att);
} }
$note->text = $attDescription; $note->text = $attDescription;

View File

@@ -81,7 +81,6 @@ class MigrateJournalNotes extends Command
Log::debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id)); Log::debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id));
try { try {
$meta->delete(); $meta->delete();
} catch (Exception $e) { // @phpstan-ignore-line } catch (Exception $e) { // @phpstan-ignore-line
Log::error(sprintf('Could not delete old meta entry #%d: %s', $meta->id, $e->getMessage())); Log::error(sprintf('Could not delete old meta entry #%d: %s', $meta->id, $e->getMessage()));
} }

View File

@@ -34,7 +34,6 @@ use Illuminate\Console\Command;
*/ */
class MigrateTagLocations extends Command class MigrateTagLocations extends Command
{ {
public const CONFIG_NAME = '500_migrate_tag_locations'; public const CONFIG_NAME = '500_migrate_tag_locations';
/** /**
* The console command description. * The console command description.
@@ -114,7 +113,7 @@ class MigrateTagLocations extends Command
*/ */
private function migrateLocationDetails(Tag $tag): void private function migrateLocationDetails(Tag $tag): void
{ {
$location = new Location; $location = new Location();
$location->longitude = $tag->longitude; $location->longitude = $tag->longitude;
$location->latitude = $tag->latitude; $location->latitude = $tag->latitude;
$location->zoom_level = $tag->zoomLevel; $location->zoom_level = $tag->zoomLevel;

View File

@@ -169,11 +169,9 @@ class MigrateToGroups extends Command
{ {
// double check transaction count. // double check transaction count.
if ($journal->transactions->count() <= 2) { if ($journal->transactions->count() <= 2) {
Log::debug(sprintf('Will not try to convert journal #%d because it has 2 or less transactions.', $journal->id)); Log::debug(sprintf('Will not try to convert journal #%d because it has 2 or less transactions.', $journal->id));
return; return;
} }
Log::debug(sprintf('Will now try to convert journal #%d', $journal->id)); Log::debug(sprintf('Will now try to convert journal #%d', $journal->id));
@@ -221,7 +219,6 @@ class MigrateToGroups extends Command
$opposingTr = $this->findOpposingTransaction($journal, $transaction); $opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) { if (null === $opposingTr) {
$this->error( $this->error(
sprintf( sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.', 'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
@@ -230,7 +227,6 @@ class MigrateToGroups extends Command
) )
); );
continue; continue;
} }
// overrule journal category with transaction category. // overrule journal category with transaction category.

View File

@@ -166,7 +166,6 @@ class MigrateToRules extends Command
foreach ($bills as $bill) { foreach ($bills as $bill) {
$this->migrateBill($ruleGroup, $bill, $lang); $this->migrateBill($ruleGroup, $bill, $lang);
} }
} }
/** /**

View File

@@ -159,26 +159,25 @@ class OtherCurrenciesCorrections extends Command
$leadTransaction = $this->getLeadTransaction($journal); $leadTransaction = $this->getLeadTransaction($journal);
if (null === $leadTransaction) { if (null === $leadTransaction) {
$this->error(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id)); $this->error(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id));
return; return;
} }
$account = $leadTransaction->account; $account = $leadTransaction->account;
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
if (null === $currency) { if (null === $currency) {
$this->error( $this->error(
sprintf( sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
$account->id,
$account->name,
$journal->id
) )
); );
$this->count++; $this->count++;
return; return;
} }
// fix each transaction: // fix each transaction:
$journal->transactions->each( $journal->transactions->each(
@@ -227,13 +226,19 @@ class OtherCurrenciesCorrections extends Command
case TransactionType::OPENING_BALANCE: case TransactionType::OPENING_BALANCE:
// whichever isn't an initial balance account: // whichever isn't an initial balance account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin( $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id' 'account_types',
'accounts.account_type_id',
'=',
'account_types.id'
)->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']); )->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);
break; break;
case TransactionType::RECONCILIATION: case TransactionType::RECONCILIATION:
// whichever isn't the reconciliation account: // whichever isn't the reconciliation account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin( $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id' 'account_types',
'accounts.account_type_id',
'=',
'account_types.id'
)->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']); )->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);
break; break;
} }
@@ -257,11 +262,9 @@ class OtherCurrenciesCorrections extends Command
} }
$currency = $this->accountRepos->getAccountCurrency($account); $currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$this->accountCurrencies[$accountId] = 0; $this->accountCurrencies[$accountId] = 0;
return null; return null;
} }
$this->accountCurrencies[$accountId] = $currency; $this->accountCurrencies[$accountId] = $currency;

View File

@@ -163,7 +163,6 @@ class TransactionIdentifier extends Command
} }
++$identifier; ++$identifier;
} }
} }
/** /**
@@ -183,7 +182,6 @@ class TransactionIdentifier extends Command
->where('amount', $amount)->where('identifier', '=', 0) ->where('amount', $amount)->where('identifier', '=', 0)
->whereNotIn('id', $exclude) ->whereNotIn('id', $exclude)
->first(); ->first();
} catch (QueryException $e) { } catch (QueryException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
$this->error('Firefly III could not find the "identifier" field in the "transactions" table.'); $this->error('Firefly III could not find the "identifier" field in the "transactions" table.');

View File

@@ -284,11 +284,9 @@ class TransferCurrenciesCorrections extends Command
} }
$currency = $this->accountRepos->getAccountCurrency($account); $currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) { if (null === $currency) {
$this->accountCurrencies[$accountId] = 0; $this->accountCurrencies[$accountId] = 0;
return null; return null;
} }
$this->accountCurrencies[$accountId] = $currency; $this->accountCurrencies[$accountId] = $currency;

View File

@@ -55,7 +55,6 @@ class UpgradeDatabase extends Command
*/ */
public function handle(): int public function handle(): int
{ {
$this->callInitialCommands(); $this->callInitialCommands();
$commands = [ $commands = [
// there are 14 upgrade commands. // there are 14 upgrade commands.

View File

@@ -201,5 +201,4 @@ class UpgradeLiabilities extends Command
{ {
app('fireflyconfig')->set(self::CONFIG_NAME, true); app('fireflyconfig')->set(self::CONFIG_NAME, true);
} }
} }