From b27fe59ab4168b7a49bdcb2b2b3c1db6887c328a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 30 Oct 2022 12:24:51 +0100 Subject: [PATCH] Use PSR-12 code style --- .ci/phpcs.sh | 37 ++++++++ .ci/phpstan.sh | 6 -- .../CorrectOpeningBalanceCurrencies.php | 21 ++--- .../Commands/Correction/DeleteEmptyGroups.php | 2 +- .../Correction/DeleteEmptyJournals.php | 10 +-- .../Correction/DeleteOrphanedTransactions.php | 84 +++++++++---------- .../Commands/Correction/EnableCurrencies.php | 10 +-- .../Commands/Correction/FixAccountTypes.php | 14 ++-- .../Correction/FixFrontpageAccounts.php | 4 +- .../Commands/Correction/FixGroupAccounts.php | 6 +- app/Console/Commands/Correction/FixIbans.php | 2 +- .../Correction/FixLongDescriptions.php | 2 +- .../Correction/FixRecurringTransactions.php | 8 +- .../Correction/FixTransactionTypes.php | 14 ++-- .../Commands/Correction/FixUnevenAmount.php | 8 +- .../Commands/Correction/RenameMetaFields.php | 4 +- app/Console/Commands/DecryptDatabase.php | 36 ++++---- app/Console/Commands/Export/ExportData.php | 10 +-- app/Console/Commands/Integrity/ReportSum.php | 2 +- .../Integrity/UpdateGroupInformation.php | 39 +++++---- app/Console/Commands/Tools/ApplyRules.php | 10 +-- app/Console/Commands/Tools/Cron.php | 68 +++++++-------- .../Commands/Upgrade/AccountCurrencies.php | 22 ++--- .../Upgrade/AppendBudgetLimitPeriods.php | 12 +-- .../Commands/Upgrade/BackToJournals.php | 32 +++---- .../Commands/Upgrade/BudgetLimitCurrency.php | 8 +- .../Commands/Upgrade/CCLiabilities.php | 8 +- .../Upgrade/CreateGroupMemberships.php | 12 +-- .../Commands/Upgrade/MigrateAttachments.php | 10 ++- .../Commands/Upgrade/MigrateJournalNotes.php | 8 +- .../Upgrade/MigrateRecurrenceMeta.php | 10 ++- .../Upgrade/MigrateRecurrenceType.php | 10 ++- .../Commands/Upgrade/MigrateTagLocations.php | 12 +-- .../Commands/Upgrade/MigrateToGroups.php | 36 ++++---- .../Commands/Upgrade/MigrateToRules.php | 26 +++--- .../Upgrade/OtherCurrenciesCorrections.php | 18 ++-- .../Commands/Upgrade/RenameAccountMeta.php | 8 +- .../Upgrade/TransactionIdentifier.php | 16 ++-- .../Upgrade/TransferCurrenciesCorrections.php | 50 +++++------ .../Commands/Upgrade/UpgradeDatabase.php | 4 +- .../Commands/Upgrade/UpgradeLiabilities.php | 24 +++--- .../Commands/UpgradeFireflyInstructions.php | 12 +-- app/Console/Commands/VerifiesAccessToken.php | 8 +- app/Console/Commands/VerifySecurityAlerts.php | 3 +- 44 files changed, 414 insertions(+), 332 deletions(-) create mode 100755 .ci/phpcs.sh diff --git a/.ci/phpcs.sh b/.ci/phpcs.sh new file mode 100755 index 0000000000..285fd2deb8 --- /dev/null +++ b/.ci/phpcs.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# +# phpstan.sh +# Copyright (c) 2021 james@firefly-iii.org +# +# This file is part of Firefly III (https://github.com/firefly-iii). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +# Install composer packages +#composer install --no-scripts --no-ansi + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# enable test .env file. +# cp .ci/.env.ci .env + +# clean up php code +cd $SCRIPT_DIR/php-cs-fixer +composer update +./vendor/bin/php-cs-fixer fix $SCRIPT_DIR/../app/Console --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php --allow-risky=yes +cd $SCRIPT_DIR/.. + +exit 0 diff --git a/.ci/phpstan.sh b/.ci/phpstan.sh index 27155b4cfc..a89c7f3895 100755 --- a/.ci/phpstan.sh +++ b/.ci/phpstan.sh @@ -28,12 +28,6 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) # enable test .env file. # cp .ci/.env.ci .env -# clean up php code -cd $SCRIPT_DIR/php-cs-fixer -composer update -./vendor/bin/php-cs-fixer fix $SCRIPT_DIR/../app/Console --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php --allow-risky=yes -cd $SCRIPT_DIR/.. - # Do static code analysis. # ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress ./vendor/bin/phpstan analyse -c .ci/phpstan.neon diff --git a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php index de1617c0ee..2867048078 100644 --- a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php +++ b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands\Correction; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\Transaction; @@ -63,8 +64,8 @@ class CorrectOpeningBalanceCurrencies extends Command Log::debug(sprintf('Now in %s', __METHOD__)); // get all OB journals: $set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') - ->whereNull('transaction_journals.deleted_at') - ->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']); + ->whereNull('transaction_journals.deleted_at') + ->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']); $this->line(sprintf('Going to verify %d opening balance transactions.', $set->count())); $count = 0; @@ -90,7 +91,7 @@ class CorrectOpeningBalanceCurrencies extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return int */ @@ -112,7 +113,7 @@ class CorrectOpeningBalanceCurrencies extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Account|null */ @@ -131,11 +132,11 @@ class CorrectOpeningBalanceCurrencies extends Command } /** - * @param Account $account + * @param Account $account * * @return TransactionCurrency * @throws JsonException - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException */ private function getCurrency(Account $account): TransactionCurrency { @@ -147,15 +148,15 @@ class CorrectOpeningBalanceCurrencies extends Command } /** - * @param TransactionJournal $journal - * @param TransactionCurrency $currency + * @param TransactionJournal $journal + * @param TransactionCurrency $currency * * @return int */ private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): int { $count = 0; - if ((int) $journal->transaction_currency_id !== (int) $currency->id) { + if ((int)$journal->transaction_currency_id !== (int)$currency->id) { $journal->transaction_currency_id = $currency->id; $journal->save(); $count = 1; @@ -163,7 +164,7 @@ class CorrectOpeningBalanceCurrencies extends Command /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { - if ((int) $transaction->transaction_currency_id !== (int) $currency->id) { + if ((int)$transaction->transaction_currency_id !== (int)$currency->id) { $transaction->transaction_currency_id = $currency->id; $transaction->save(); $count = 1; diff --git a/app/Console/Commands/Correction/DeleteEmptyGroups.php b/app/Console/Commands/Correction/DeleteEmptyGroups.php index 9c6324e867..1b88164f6d 100644 --- a/app/Console/Commands/Correction/DeleteEmptyGroups.php +++ b/app/Console/Commands/Correction/DeleteEmptyGroups.php @@ -59,7 +59,7 @@ class DeleteEmptyGroups extends Command $start = microtime(true); $groupIds = TransactionGroup::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); Log::debug(sprintf('Count is %d', $total)); diff --git a/app/Console/Commands/Correction/DeleteEmptyJournals.php b/app/Console/Commands/Correction/DeleteEmptyJournals.php index 74f97d2518..45edc7ab93 100644 --- a/app/Console/Commands/Correction/DeleteEmptyJournals.php +++ b/app/Console/Commands/Correction/DeleteEmptyJournals.php @@ -67,22 +67,22 @@ class DeleteEmptyJournals extends Command private function deleteUnevenJournals(): void { $set = Transaction::whereNull('deleted_at') - ->groupBy('transactions.transaction_journal_id') - ->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); + ->groupBy('transactions.transaction_journal_id') + ->get([DB::raw('COUNT(transactions.transaction_journal_id) as the_count'), 'transaction_journal_id']); $total = 0; /** @var Transaction $row */ foreach ($set as $row) { - $count = (int) $row->the_count; + $count = (int)$row->the_count; if (1 === $count % 2) { // uneven number, delete journal and transactions: try { - TransactionJournal::find((int) $row->transaction_journal_id)->delete(); + TransactionJournal::find((int)$row->transaction_journal_id)->delete(); } catch (Exception $e) { // @phpstan-ignore-line Log::info(sprintf('Could not delete journal: %s', $e->getMessage())); } - Transaction::where('transaction_journal_id', (int) $row->transaction_journal_id)->delete(); + Transaction::where('transaction_journal_id', (int)$row->transaction_journal_id)->delete(); $this->info(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id)); $total++; } diff --git a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php index bd26c549bd..f3fb23a901 100644 --- a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php +++ b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php @@ -66,6 +66,34 @@ class DeleteOrphanedTransactions extends Command return 0; } + private function deleteOrphanedJournals(): void + { + $set = TransactionJournal::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id') + ->whereNotNull('transaction_groups.deleted_at') + ->whereNull('transaction_journals.deleted_at') + ->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']); + $count = $set->count(); + if (0 === $count) { + $this->info('No orphaned journals.'); + } + if ($count > 0) { + $this->info(sprintf('Found %d orphaned journal(s).', $count)); + foreach ($set as $entry) { + $journal = TransactionJournal::withTrashed()->find((int)$entry->id); + if (null !== $journal) { + $journal->delete(); + $this->info( + sprintf( + 'Journal #%d (part of deleted transaction group #%d) has been deleted as well.', + $entry->id, + $entry->transaction_group_id + ) + ); + } + } + } + } + /** * @throws Exception */ @@ -73,18 +101,18 @@ class DeleteOrphanedTransactions extends Command { $count = 0; $set = Transaction::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->whereNotNull('transaction_journals.deleted_at') - ->whereNull('transactions.deleted_at') - ->whereNotNull('transactions.id') - ->get( - [ - 'transaction_journals.id as journal_id', - 'transactions.id as transaction_id', - ] - ); + ->whereNotNull('transaction_journals.deleted_at') + ->whereNull('transactions.deleted_at') + ->whereNotNull('transactions.id') + ->get( + [ + 'transaction_journals.id as journal_id', + 'transactions.id as transaction_id', + ] + ); /** @var stdClass $entry */ foreach ($set as $entry) { - $transaction = Transaction::find((int) $entry->transaction_id); + $transaction = Transaction::find((int)$entry->transaction_id); if (null !== $transaction) { $transaction->delete(); $this->info( @@ -109,13 +137,13 @@ class DeleteOrphanedTransactions extends Command { $set = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id') - ->whereNotNull('accounts.deleted_at') - ->get(['transactions.*']); + ->whereNotNull('accounts.deleted_at') + ->get(['transactions.*']); $count = 0; /** @var Transaction $transaction */ foreach ($set as $transaction) { // delete journals - $journal = TransactionJournal::find((int) $transaction->transaction_journal_id); + $journal = TransactionJournal::find((int)$transaction->transaction_journal_id); if ($journal) { try { $journal->delete(); @@ -123,7 +151,7 @@ class DeleteOrphanedTransactions extends Command 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( sprintf( 'Deleted transaction journal #%d because account #%d was already deleted.', @@ -137,32 +165,4 @@ class DeleteOrphanedTransactions extends Command $this->info('No orphaned accounts.'); } } - - private function deleteOrphanedJournals(): void - { - $set = TransactionJournal::leftJoin('transaction_groups', 'transaction_journals.transaction_group_id', 'transaction_groups.id') - ->whereNotNull('transaction_groups.deleted_at') - ->whereNull('transaction_journals.deleted_at') - ->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']); - $count = $set->count(); - if (0 === $count) { - $this->info('No orphaned journals.'); - } - if ($count > 0) { - $this->info(sprintf('Found %d orphaned journal(s).', $count)); - foreach ($set as $entry) { - $journal = TransactionJournal::withTrashed()->find((int) $entry->id); - if (null !== $journal) { - $journal->delete(); - $this->info( - sprintf( - 'Journal #%d (part of deleted transaction group #%d) has been deleted as well.', - $entry->id, - $entry->transaction_group_id - ) - ); - } - } - } - } } diff --git a/app/Console/Commands/Correction/EnableCurrencies.php b/app/Console/Commands/Correction/EnableCurrencies.php index 9cf7f5b434..16957c4ff6 100644 --- a/app/Console/Commands/Correction/EnableCurrencies.php +++ b/app/Console/Commands/Correction/EnableCurrencies.php @@ -63,26 +63,26 @@ class EnableCurrencies extends Command /** @var Collection $meta */ $meta = AccountMeta::where('name', 'currency_id')->groupBy('data')->get(['data']); foreach ($meta as $entry) { - $found[] = (int) $entry->data; + $found[] = (int)$entry->data; } // get all from journals: $journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']); foreach ($journals as $entry) { - $found[] = (int) $entry->transaction_currency_id; + $found[] = (int)$entry->transaction_currency_id; } // get all from transactions $transactions = Transaction::groupBy('transaction_currency_id', 'foreign_currency_id')->get(['transaction_currency_id', 'foreign_currency_id']); foreach ($transactions as $entry) { - $found[] = (int) $entry->transaction_currency_id; - $found[] = (int) $entry->foreign_currency_id; + $found[] = (int)$entry->transaction_currency_id; + $found[] = (int)$entry->foreign_currency_id; } // get all from budget limits $limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']); foreach ($limits as $entry) { - $found[] = (int) $entry->transaction_currency_id; + $found[] = (int)$entry->transaction_currency_id; } $found = array_values(array_unique($found)); diff --git a/app/Console/Commands/Correction/FixAccountTypes.php b/app/Console/Commands/Correction/FixAccountTypes.php index a9cd3ff80a..e3da62893d 100644 --- a/app/Console/Commands/Correction/FixAccountTypes.php +++ b/app/Console/Commands/Correction/FixAccountTypes.php @@ -99,7 +99,7 @@ class FixAccountTypes extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @throws FireflyException */ @@ -140,7 +140,7 @@ class FixAccountTypes extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction */ @@ -150,7 +150,7 @@ class FixAccountTypes extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction */ @@ -160,10 +160,10 @@ class FixAccountTypes extends Command } /** - * @param TransactionJournal $journal - * @param string $type - * @param Transaction $source - * @param Transaction $dest + * @param TransactionJournal $journal + * @param string $type + * @param Transaction $source + * @param Transaction $dest * * @throws FireflyException */ diff --git a/app/Console/Commands/Correction/FixFrontpageAccounts.php b/app/Console/Commands/Correction/FixFrontpageAccounts.php index 64372c7db4..3175bc0e3d 100644 --- a/app/Console/Commands/Correction/FixFrontpageAccounts.php +++ b/app/Console/Commands/Correction/FixFrontpageAccounts.php @@ -73,7 +73,7 @@ class FixFrontpageAccounts extends Command } /** - * @param Preference $preference + * @param Preference $preference */ private function fixPreference(Preference $preference): void { @@ -88,7 +88,7 @@ class FixFrontpageAccounts extends Command if (is_array($data)) { /** @var string $accountId */ foreach ($data as $accountId) { - $accountIdInt = (int) $accountId; + $accountIdInt = (int)$accountId; $account = $repository->find($accountIdInt); if (null !== $account && in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true) diff --git a/app/Console/Commands/Correction/FixGroupAccounts.php b/app/Console/Commands/Correction/FixGroupAccounts.php index a5028d8533..6cc0ee9b7e 100644 --- a/app/Console/Commands/Correction/FixGroupAccounts.php +++ b/app/Console/Commands/Correction/FixGroupAccounts.php @@ -58,11 +58,11 @@ class FixGroupAccounts extends Command { $groups = []; $res = TransactionJournal::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 */ foreach ($res as $journal) { - if ((int) $journal->the_count > 1) { - $groups[] = (int) $journal->transaction_group_id; + if ((int)$journal->the_count > 1) { + $groups[] = (int)$journal->transaction_group_id; } } $handler = new UpdatedGroupEventHandler(); diff --git a/app/Console/Commands/Correction/FixIbans.php b/app/Console/Commands/Correction/FixIbans.php index c1a330ef11..f527e84f9a 100644 --- a/app/Console/Commands/Correction/FixIbans.php +++ b/app/Console/Commands/Correction/FixIbans.php @@ -57,7 +57,7 @@ class FixIbans extends Command foreach ($accounts as $account) { $iban = $account->iban; if (str_contains($iban, ' ')) { - $iban = app('steam')->filterSpaces((string) $account->iban); + $iban = app('steam')->filterSpaces((string)$account->iban); if ('' !== $iban) { $account->iban = $iban; $account->save(); diff --git a/app/Console/Commands/Correction/FixLongDescriptions.php b/app/Console/Commands/Correction/FixLongDescriptions.php index 2dfd02d15b..32fa810ec7 100644 --- a/app/Console/Commands/Correction/FixLongDescriptions.php +++ b/app/Console/Commands/Correction/FixLongDescriptions.php @@ -68,7 +68,7 @@ class FixLongDescriptions extends Command $groups = TransactionGroup::get(['id', 'title']); /** @var TransactionGroup $group */ foreach ($groups as $group) { - if (strlen((string) $group->title) > self::MAX_LENGTH) { + if (strlen((string)$group->title) > self::MAX_LENGTH) { $group->title = substr($group->title, 0, self::MAX_LENGTH); $group->save(); $this->line(sprintf('Truncated description of transaction group #%d', $group->id)); diff --git a/app/Console/Commands/Correction/FixRecurringTransactions.php b/app/Console/Commands/Correction/FixRecurringTransactions.php index ac6e047558..58329f08d6 100644 --- a/app/Console/Commands/Correction/FixRecurringTransactions.php +++ b/app/Console/Commands/Correction/FixRecurringTransactions.php @@ -96,7 +96,7 @@ class FixRecurringTransactions extends Command } /** - * @param User $user + * @param User $user */ private function processUser(User $user): void { @@ -109,7 +109,7 @@ class FixRecurringTransactions extends Command } /** - * @param Recurrence $recurrence + * @param Recurrence $recurrence */ private function processRecurrence(Recurrence $recurrence): void { @@ -120,8 +120,8 @@ class FixRecurringTransactions extends Command } /** - * @param Recurrence $recurrence - * @param RecurrenceTransaction $transaction + * @param Recurrence $recurrence + * @param RecurrenceTransaction $transaction */ private function processTransaction(Recurrence $recurrence, RecurrenceTransaction $transaction): void { diff --git a/app/Console/Commands/Correction/FixTransactionTypes.php b/app/Console/Commands/Correction/FixTransactionTypes.php index b37661d1d9..fa9c0c7b6f 100644 --- a/app/Console/Commands/Correction/FixTransactionTypes.php +++ b/app/Console/Commands/Correction/FixTransactionTypes.php @@ -86,11 +86,11 @@ class FixTransactionTypes extends Command private function collectJournals(): Collection { return TransactionJournal::with(['transactionType', 'transactions', 'transactions.account', 'transactions.account.accountType']) - ->get(); + ->get(); } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return bool */ @@ -105,7 +105,7 @@ class FixTransactionTypes extends Command return false; } - $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) { $this->line( sprintf( @@ -126,7 +126,7 @@ class FixTransactionTypes extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Account * @throws FireflyException @@ -155,7 +155,7 @@ class FixTransactionTypes extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Account * @throws FireflyException @@ -184,8 +184,8 @@ class FixTransactionTypes extends Command } /** - * @param TransactionJournal $journal - * @param string $expectedType + * @param TransactionJournal $journal + * @param string $expectedType */ private function changeJournal(TransactionJournal $journal, string $expectedType): void { diff --git a/app/Console/Commands/Correction/FixUnevenAmount.php b/app/Console/Commands/Correction/FixUnevenAmount.php index f02cb4e445..fa3dbc5fdd 100644 --- a/app/Console/Commands/Correction/FixUnevenAmount.php +++ b/app/Console/Commands/Correction/FixUnevenAmount.php @@ -65,11 +65,11 @@ class FixUnevenAmount extends Command ->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]); /** @var stdClass $entry */ foreach ($journals as $entry) { - if (0 !== bccomp((string) $entry->the_sum, '0')) { + if (0 !== bccomp((string)$entry->the_sum, '0')) { $message = sprintf('Sum of journal #%d is %s instead of zero.', $entry->transaction_journal_id, $entry->the_sum); $this->warn($message); Log::warning($message); - $this->fixJournal((int) $entry->transaction_journal_id); + $this->fixJournal((int)$entry->transaction_journal_id); $count++; } } @@ -84,7 +84,7 @@ class FixUnevenAmount extends Command } /** - * @param int $param + * @param int $param */ private function fixJournal(int $param): void { @@ -110,7 +110,7 @@ class FixUnevenAmount extends Command return; } - $amount = bcmul('-1', (string) $source->amount); + $amount = bcmul('-1', (string)$source->amount); // fix amount of destination: /** @var Transaction $destination */ diff --git a/app/Console/Commands/Correction/RenameMetaFields.php b/app/Console/Commands/Correction/RenameMetaFields.php index 480f586700..ff070f3707 100644 --- a/app/Console/Commands/Correction/RenameMetaFields.php +++ b/app/Console/Commands/Correction/RenameMetaFields.php @@ -87,8 +87,8 @@ class RenameMetaFields extends Command } /** - * @param string $original - * @param string $update + * @param string $original + * @param string $update */ private function rename(string $original, string $update): void { diff --git a/app/Console/Commands/DecryptDatabase.php b/app/Console/Commands/DecryptDatabase.php index 465bea2193..8b2e10e32d 100644 --- a/app/Console/Commands/DecryptDatabase.php +++ b/app/Console/Commands/DecryptDatabase.php @@ -32,6 +32,8 @@ use Illuminate\Console\Command; use Illuminate\Contracts\Encryption\DecryptException; use JsonException; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use stdClass; /** @@ -75,7 +77,7 @@ class DecryptDatabase extends Command ]; /** * @var string $table - * @var array $fields + * @var array $fields */ foreach ($tables as $table => $fields) { $this->decryptTable($table, $fields); @@ -86,8 +88,8 @@ class DecryptDatabase extends Command } /** - * @param string $table - * @param array $fields + * @param string $table + * @param array $fields */ private function decryptTable(string $table, array $fields): void { @@ -106,11 +108,11 @@ class DecryptDatabase extends Command } /** - * @param string $table + * @param string $table * * @return bool - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isDecrypted(string $table): bool { @@ -122,15 +124,15 @@ class DecryptDatabase extends Command Log::error($e->getMessage()); } if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; } /** - * @param string $table - * @param string $field + * @param string $table + * @param string $field */ private function decryptField(string $table, string $field): void { @@ -142,9 +144,9 @@ class DecryptDatabase extends Command } /** - * @param string $table - * @param string $field - * @param stdClass $row + * @param string $table + * @param string $field + * @param stdClass $row */ private function decryptRow(string $table, string $field, stdClass $row): void { @@ -152,7 +154,7 @@ class DecryptDatabase extends Command if (null === $original) { return; } - $id = (int) $row->id; + $id = (int)$row->id; $value = ''; try { @@ -179,7 +181,7 @@ class DecryptDatabase extends Command /** * Tries to decrypt data. Will only throw an exception when the MAC is invalid. * - * @param mixed $value + * @param mixed $value * * @return string * @throws FireflyException @@ -198,8 +200,8 @@ class DecryptDatabase extends Command } /** - * @param int $id - * @param string $value + * @param int $id + * @param string $value */ private function decryptPreferencesRow(int $id, string $value): void { @@ -217,7 +219,7 @@ class DecryptDatabase extends Command } /** @var Preference $object */ - $object = Preference::find((int) $id); + $object = Preference::find((int)$id); if (null !== $object) { $object->data = $newValue; $object->save(); diff --git a/app/Console/Commands/Export/ExportData.php b/app/Console/Commands/Export/ExportData.php index 7419aaa36c..af46c4feb6 100644 --- a/app/Console/Commands/Export/ExportData.php +++ b/app/Console/Commands/Export/ExportData.php @@ -184,7 +184,7 @@ class ExportData extends Command } /** - * @param string $field + * @param string $field * * @return Carbon * @throws Exception @@ -234,7 +234,7 @@ class ExportData extends Command $accounts = new Collection(); $accountList = $this->option('accounts'); $types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; - if (null !== $accountList && '' !== (string) $accountList) { + if (null !== $accountList && '' !== (string)$accountList) { $accountIds = explode(',', $accountList); $accounts = $this->accountRepository->getAccountsById($accountIds); } @@ -262,7 +262,7 @@ class ExportData extends Command */ private function getExportDirectory(): string { - $directory = (string) $this->option('export_directory'); + $directory = (string)$this->option('export_directory'); if (null === $directory) { $directory = './'; } @@ -274,8 +274,8 @@ class ExportData extends Command } /** - * @param array $options - * @param array $data + * @param array $options + * @param array $data * * @throws FireflyException */ diff --git a/app/Console/Commands/Integrity/ReportSum.php b/app/Console/Commands/Integrity/ReportSum.php index 7365299de1..5b5bcb8dc1 100644 --- a/app/Console/Commands/Integrity/ReportSum.php +++ b/app/Console/Commands/Integrity/ReportSum.php @@ -68,7 +68,7 @@ class ReportSum extends Command /** @var User $user */ foreach ($userRepository->all() as $user) { - $sum = (string) $user->transactions()->sum('amount'); + $sum = (string)$user->transactions()->sum('amount'); if (0 !== bccomp($sum, '0')) { $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); $this->error($message); diff --git a/app/Console/Commands/Integrity/UpdateGroupInformation.php b/app/Console/Commands/Integrity/UpdateGroupInformation.php index b6e935ef42..30ebd19755 100644 --- a/app/Console/Commands/Integrity/UpdateGroupInformation.php +++ b/app/Console/Commands/Integrity/UpdateGroupInformation.php @@ -47,19 +47,18 @@ use Illuminate\Console\Command; */ class UpdateGroupInformation extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'firefly-iii:upgrade-group-information'; - /** * The console command description. * * @var string */ protected $description = 'Makes sure that every object is linked to a group'; + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'firefly-iii:upgrade-group-information'; /** * Execute the console command. @@ -87,19 +86,31 @@ class UpdateGroupInformation extends Command $this->warn(sprintf('User "%s" has no group.', $user->email)); return; } - $set = [Account::class, Attachment::class, AvailableBudget::class, - Bill::class, Budget::class, Category::class, CurrencyExchangeRate::class, - Recurrence::class, RuleGroup::class, Rule::class, Tag::class, TransactionGroup::class, - TransactionJournal::class, Webhook::class]; + $set = [ + Account::class, + Attachment::class, + AvailableBudget::class, + Bill::class, + Budget::class, + Category::class, + CurrencyExchangeRate::class, + Recurrence::class, + RuleGroup::class, + Rule::class, + Tag::class, + TransactionGroup::class, + TransactionJournal::class, + Webhook::class, + ]; foreach ($set as $className) { $this->updateGroupInfoForObject($user, $group, $className); } } /** - * @param User $user - * @param UserGroup $group - * @param string $className + * @param User $user + * @param UserGroup $group + * @param string $className * @return void */ private function updateGroupInfoForObject(User $user, UserGroup $group, string $className): void diff --git a/app/Console/Commands/Tools/ApplyRules.php b/app/Console/Commands/Tools/ApplyRules.php index 7f620eca71..576259c6bb 100644 --- a/app/Console/Commands/Tools/ApplyRules.php +++ b/app/Console/Commands/Tools/ApplyRules.php @@ -212,7 +212,7 @@ class ApplyRules extends Command $accountRepository = app(AccountRepositoryInterface::class); $accountRepository->setUser($this->getUser()); foreach ($accountList as $accountId) { - $accountId = (int) $accountId; + $accountId = (int)$accountId; $account = $accountRepository->find($accountId); if (null !== $account && in_array($account->accountType->type, $this->acceptedAccounts, true)) { $finalList->push($account); @@ -242,7 +242,7 @@ class ApplyRules extends Command $ruleGroupList = explode(',', $ruleGroupString); foreach ($ruleGroupList as $ruleGroupId) { - $ruleGroup = $this->ruleGroupRepository->find((int) $ruleGroupId); + $ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId); if ($ruleGroup->active) { $this->ruleGroupSelection[] = $ruleGroup->id; } @@ -267,7 +267,7 @@ class ApplyRules extends Command $ruleList = explode(',', $ruleString); foreach ($ruleList as $ruleId) { - $rule = $this->ruleRepository->find((int) $ruleId); + $rule = $this->ruleRepository->find((int)$ruleId); if (null !== $rule && $rule->active) { $this->ruleSelection[] = $rule->id; } @@ -343,8 +343,8 @@ class ApplyRules extends Command } /** - * @param Rule $rule - * @param RuleGroup $group + * @param Rule $rule + * @param RuleGroup $group * * @return bool */ diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.php index c4a85e8625..9b7269e90b 100644 --- a/app/Console/Commands/Tools/Cron.php +++ b/app/Console/Commands/Tools/Cron.php @@ -68,7 +68,7 @@ class Cron extends Command } catch (InvalidArgumentException $e) { $this->error(sprintf('"%s" is not a valid date', $this->option('date'))); } - $force = (bool) $this->option('force'); + $force = (bool)$this->option('force'); /* * Fire recurring transaction cron job. @@ -122,8 +122,35 @@ class Cron extends Command } /** - * @param bool $force - * @param Carbon|null $date + * @param bool $force + * @param Carbon|null $date + * @throws FireflyException + */ + private function exchangeRatesCronJob(bool $force, ?Carbon $date): void + { + $exchangeRates = new ExchangeRatesCronjob(); + $exchangeRates->setForce($force); + // set date in cron job: + if (null !== $date) { + $exchangeRates->setDate($date); + } + + $exchangeRates->fire(); + + if ($exchangeRates->jobErrored) { + $this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); + } + if ($exchangeRates->jobFired) { + $this->line(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); + } + if ($exchangeRates->jobSucceeded) { + $this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); + } + } + + /** + * @param bool $force + * @param Carbon|null $date * * @throws FireflyException */ @@ -150,8 +177,8 @@ class Cron extends Command } /** - * @param bool $force - * @param Carbon|null $date + * @param bool $force + * @param Carbon|null $date * */ private function autoBudgetCronJob(bool $force, ?Carbon $date): void @@ -177,8 +204,8 @@ class Cron extends Command } /** - * @param bool $force - * @param Carbon|null $date + * @param bool $force + * @param Carbon|null $date * @throws FireflyException */ private function billWarningCronJob(bool $force, ?Carbon $date): void @@ -202,31 +229,4 @@ class Cron extends Command $this->info(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message)); } } - - /** - * @param bool $force - * @param Carbon|null $date - * @throws FireflyException - */ - private function exchangeRatesCronJob(bool $force, ?Carbon $date): void - { - $exchangeRates = new ExchangeRatesCronjob(); - $exchangeRates->setForce($force); - // set date in cron job: - if (null !== $date) { - $exchangeRates->setDate($date); - } - - $exchangeRates->fire(); - - if ($exchangeRates->jobErrored) { - $this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message)); - } - if ($exchangeRates->jobFired) { - $this->line(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message)); - } - if ($exchangeRates->jobSucceeded) { - $this->info(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message)); - } - } } diff --git a/app/Console/Commands/Upgrade/AccountCurrencies.php b/app/Console/Commands/Upgrade/AccountCurrencies.php index 617fe579ad..8734353548 100644 --- a/app/Console/Commands/Upgrade/AccountCurrencies.php +++ b/app/Console/Commands/Upgrade/AccountCurrencies.php @@ -34,6 +34,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class AccountCurrencies @@ -109,14 +111,14 @@ class AccountCurrencies extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -129,7 +131,7 @@ class AccountCurrencies extends Command { Log::debug('Now in updateAccountCurrencies()'); $users = $this->userRepos->all(); - $defaultCurrencyCode = (string) config('firefly.default_currency', 'EUR'); + $defaultCurrencyCode = (string)config('firefly.default_currency', 'EUR'); Log::debug(sprintf('Default currency is %s', $defaultCurrencyCode)); foreach ($users as $user) { $this->updateCurrenciesForUser($user, $defaultCurrencyCode); @@ -137,8 +139,8 @@ class AccountCurrencies extends Command } /** - * @param User $user - * @param string $systemCurrencyCode + * @param User $user + * @param string $systemCurrencyCode * * @throws FireflyException */ @@ -172,21 +174,21 @@ class AccountCurrencies extends Command } /** - * @param Account $account - * @param TransactionCurrency $currency + * @param Account $account + * @param TransactionCurrency $currency */ private function updateAccount(Account $account, TransactionCurrency $currency): void { Log::debug(sprintf('Now in updateAccount(%d, %s)', $account->id, $currency->code)); $this->accountRepos->setUser($account->user); - $accountCurrency = (int) $this->accountRepos->getMetaValue($account, 'currency_id'); + $accountCurrency = (int)$this->accountRepos->getMetaValue($account, 'currency_id'); Log::debug(sprintf('Account currency is #%d', $accountCurrency)); $openingBalance = $this->accountRepos->getOpeningBalance($account); $obCurrency = 0; if (null !== $openingBalance) { - $obCurrency = (int) $openingBalance->transaction_currency_id; + $obCurrency = (int)$openingBalance->transaction_currency_id; Log::debug('Account has opening balance.'); } Log::debug(sprintf('Account OB currency is #%d.', $obCurrency)); diff --git a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php index 48cfa23172..224bfdab3a 100644 --- a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php +++ b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php @@ -27,6 +27,8 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\BudgetLimit; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class AppendBudgetLimitPeriods extends Command { @@ -72,14 +74,14 @@ class AppendBudgetLimitPeriods extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); - return (bool) $configVar->data; + return (bool)$configVar->data; } /** @@ -95,7 +97,7 @@ class AppendBudgetLimitPeriods extends Command } /** - * @param BudgetLimit $limit + * @param BudgetLimit $limit */ private function fixLimit(BudgetLimit $limit) { @@ -127,7 +129,7 @@ class AppendBudgetLimitPeriods extends Command } /** - * @param BudgetLimit $limit + * @param BudgetLimit $limit * * @return string|null */ diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.php index 15298a237f..2d504fde12 100644 --- a/app/Console/Commands/Upgrade/BackToJournals.php +++ b/app/Console/Commands/Upgrade/BackToJournals.php @@ -32,6 +32,8 @@ use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; use Illuminate\Support\Collection; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class BackToJournals @@ -85,27 +87,27 @@ class BackToJournals extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isMigrated(): bool { $configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false); - return (bool) $configVar->data; + return (bool)$configVar->data; } /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); - return (bool) $configVar->data; + return (bool)$configVar->data; } /** @@ -159,7 +161,7 @@ class BackToJournals extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal */ private function migrateBudgetsForJournal(TransactionJournal $journal): void { @@ -179,7 +181,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([(int)$budget->id]); return; } @@ -187,7 +189,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([(int)$budget->id]); } } @@ -225,9 +227,9 @@ class BackToJournals extends Command $chunks = array_chunk($transactions, 500); foreach ($chunks as $chunk) { - $set = DB::table('transactions') // @phpstan-ignore-line - ->whereIn('transactions.id', $chunk) - ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); + $set = DB::table('transactions') // @phpstan-ignore-line + ->whereIn('transactions.id', $chunk) + ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); $array = array_merge($array, $set); } @@ -235,7 +237,7 @@ class BackToJournals extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal */ private function migrateCategoriesForJournal(TransactionJournal $journal): void { @@ -255,12 +257,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([(int)$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([(int)$category->id]); } } diff --git a/app/Console/Commands/Upgrade/BudgetLimitCurrency.php b/app/Console/Commands/Upgrade/BudgetLimitCurrency.php index 93b5ac95a1..333a4af854 100644 --- a/app/Console/Commands/Upgrade/BudgetLimitCurrency.php +++ b/app/Console/Commands/Upgrade/BudgetLimitCurrency.php @@ -27,6 +27,8 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\BudgetLimit; use Illuminate\Console\Command; use JsonException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class BudgetLimitCurrency @@ -99,14 +101,14 @@ class BudgetLimitCurrency extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; diff --git a/app/Console/Commands/Upgrade/CCLiabilities.php b/app/Console/Commands/Upgrade/CCLiabilities.php index d28dc36860..aaac64b4bd 100644 --- a/app/Console/Commands/Upgrade/CCLiabilities.php +++ b/app/Console/Commands/Upgrade/CCLiabilities.php @@ -28,6 +28,8 @@ use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use Illuminate\Console\Command; use Illuminate\Support\Collection; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class CCLiabilities @@ -96,14 +98,14 @@ class CCLiabilities extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; diff --git a/app/Console/Commands/Upgrade/CreateGroupMemberships.php b/app/Console/Commands/Upgrade/CreateGroupMemberships.php index 29e79f1cc9..e6e33a37a0 100644 --- a/app/Console/Commands/Upgrade/CreateGroupMemberships.php +++ b/app/Console/Commands/Upgrade/CreateGroupMemberships.php @@ -31,6 +31,8 @@ use FireflyIII\Models\UserRole; use FireflyIII\User; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class CreateGroupMemberships @@ -77,14 +79,14 @@ class CreateGroupMemberships extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -109,7 +111,7 @@ class CreateGroupMemberships extends Command } /** - * @param User $user + * @param User $user * * @return bool */ @@ -119,7 +121,7 @@ class CreateGroupMemberships extends Command } /** - * @param User $user + * @param User $user * * @throws FireflyException */ diff --git a/app/Console/Commands/Upgrade/MigrateAttachments.php b/app/Console/Commands/Upgrade/MigrateAttachments.php index b323cb1749..1fe8957180 100644 --- a/app/Console/Commands/Upgrade/MigrateAttachments.php +++ b/app/Console/Commands/Upgrade/MigrateAttachments.php @@ -28,6 +28,8 @@ use FireflyIII\Models\Attachment; use FireflyIII\Models\Note; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateAttachments @@ -70,7 +72,7 @@ class MigrateAttachments extends Command /** @var Attachment $att */ foreach ($attachments as $att) { // move description: - $attDescription = (string) $att->description; + $attDescription = (string)$att->description; if ('' !== $attDescription) { // find or create note: $note = $att->notes()->first(); @@ -105,14 +107,14 @@ class MigrateAttachments extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; diff --git a/app/Console/Commands/Upgrade/MigrateJournalNotes.php b/app/Console/Commands/Upgrade/MigrateJournalNotes.php index 33add64d5a..7bb3b8929d 100644 --- a/app/Console/Commands/Upgrade/MigrateJournalNotes.php +++ b/app/Console/Commands/Upgrade/MigrateJournalNotes.php @@ -29,6 +29,8 @@ use FireflyIII\Models\Note; use FireflyIII\Models\TransactionJournalMeta; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateJournalNotes @@ -105,14 +107,14 @@ class MigrateJournalNotes extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; diff --git a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php index a1b3c2aa80..1e1b25dd4f 100644 --- a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php +++ b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php @@ -29,6 +29,8 @@ use FireflyIII\Models\RecurrenceMeta; use FireflyIII\Models\RecurrenceTransactionMeta; use Illuminate\Console\Command; use JsonException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateRecurrenceMeta @@ -84,14 +86,14 @@ class MigrateRecurrenceMeta extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -115,7 +117,7 @@ class MigrateRecurrenceMeta extends Command } /** - * @param RecurrenceMeta $meta + * @param RecurrenceMeta $meta * * @return int * @throws JsonException diff --git a/app/Console/Commands/Upgrade/MigrateRecurrenceType.php b/app/Console/Commands/Upgrade/MigrateRecurrenceType.php index d86e719aea..485aa4ca9a 100644 --- a/app/Console/Commands/Upgrade/MigrateRecurrenceType.php +++ b/app/Console/Commands/Upgrade/MigrateRecurrenceType.php @@ -29,6 +29,8 @@ use FireflyIII\Models\Recurrence; use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\TransactionType; use Illuminate\Console\Command; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateRecurrenceType @@ -77,14 +79,14 @@ class MigrateRecurrenceType extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -106,7 +108,7 @@ class MigrateRecurrenceType extends Command private function migrateRecurrence(Recurrence $recurrence): void { - $originalType = (int) $recurrence->transaction_type_id; + $originalType = (int)$recurrence->transaction_type_id; $newType = $this->getInvalidType(); $recurrence->transaction_type_id = $newType->id; $recurrence->save(); diff --git a/app/Console/Commands/Upgrade/MigrateTagLocations.php b/app/Console/Commands/Upgrade/MigrateTagLocations.php index e3170acbd4..97bd4d1368 100644 --- a/app/Console/Commands/Upgrade/MigrateTagLocations.php +++ b/app/Console/Commands/Upgrade/MigrateTagLocations.php @@ -28,6 +28,8 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Location; use FireflyIII\Models\Tag; use Illuminate\Console\Command; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateTagLocations @@ -74,14 +76,14 @@ class MigrateTagLocations extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -99,7 +101,7 @@ class MigrateTagLocations extends Command } /** - * @param Tag $tag + * @param Tag $tag * * @return bool */ @@ -109,7 +111,7 @@ class MigrateTagLocations extends Command } /** - * @param Tag $tag + * @param Tag $tag */ private function migrateLocationDetails(Tag $tag): void { diff --git a/app/Console/Commands/Upgrade/MigrateToGroups.php b/app/Console/Commands/Upgrade/MigrateToGroups.php index c4ee070bb8..1c2c642d4e 100644 --- a/app/Console/Commands/Upgrade/MigrateToGroups.php +++ b/app/Console/Commands/Upgrade/MigrateToGroups.php @@ -37,6 +37,8 @@ use FireflyIII\Services\Internal\Destroy\JournalDestroyService; use Illuminate\Console\Command; use Illuminate\Support\Collection; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * This command will take split transactions and migrate them to "transaction groups". @@ -129,14 +131,14 @@ class MigrateToGroups extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isMigrated(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -161,7 +163,7 @@ class MigrateToGroups extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @throws Exception */ @@ -303,7 +305,7 @@ class MigrateToGroups extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Collection */ @@ -317,8 +319,8 @@ class MigrateToGroups extends Command } /** - * @param TransactionJournal $journal - * @param Transaction $transaction + * @param TransactionJournal $journal + * @param Transaction $transaction * * @return Transaction|null */ @@ -326,7 +328,7 @@ class MigrateToGroups extends Command { $set = $journal->transactions->filter( static function (Transaction $subject) use ($transaction) { - $amount = (float) $transaction->amount * -1 === (float) $subject->amount; + $amount = (float)$transaction->amount * -1 === (float)$subject->amount; $identifier = $transaction->identifier === $subject->identifier; Log::debug(sprintf('Amount the same? %s', var_export($amount, true))); Log::debug(sprintf('ID the same? %s', var_export($identifier, true))); @@ -339,8 +341,8 @@ class MigrateToGroups extends Command } /** - * @param Transaction $left - * @param Transaction $right + * @param Transaction $left + * @param Transaction $right * * @return int|null */ @@ -354,7 +356,7 @@ class MigrateToGroups extends Command if (null !== $budget) { Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id)); - return (int) $budget->id; + return (int)$budget->id; } // try to get a budget ID from the right transaction: @@ -363,7 +365,7 @@ class MigrateToGroups extends Command if (null !== $budget) { Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id)); - return (int) $budget->id; + return (int)$budget->id; } Log::debug('Neither left or right have a budget, return NULL'); @@ -372,8 +374,8 @@ class MigrateToGroups extends Command } /** - * @param Transaction $left - * @param Transaction $right + * @param Transaction $left + * @param Transaction $right * * @return int|null */ @@ -387,7 +389,7 @@ class MigrateToGroups extends Command if (null !== $category) { Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id)); - return (int) $category->id; + return (int)$category->id; } // try to get a category ID from the left transaction: @@ -396,7 +398,7 @@ class MigrateToGroups extends Command if (null !== $category) { Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id)); - return (int) $category->id; + return (int)$category->id; } Log::debug('Neither left or right have a category, return NULL'); @@ -425,7 +427,7 @@ class MigrateToGroups extends Command } /** - * @param array $array + * @param array $array */ private function giveGroup(array $array): void { diff --git a/app/Console/Commands/Upgrade/MigrateToRules.php b/app/Console/Commands/Upgrade/MigrateToRules.php index b07eec0547..fd2c3b41d0 100644 --- a/app/Console/Commands/Upgrade/MigrateToRules.php +++ b/app/Console/Commands/Upgrade/MigrateToRules.php @@ -33,6 +33,8 @@ use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class MigrateToRules @@ -120,14 +122,14 @@ class MigrateToRules extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -136,7 +138,7 @@ class MigrateToRules extends Command /** * Migrate bills to new rule structure for a specific user. * - * @param User $user + * @param User $user * * @throws FireflyException */ @@ -148,14 +150,14 @@ class MigrateToRules extends Command /** @var Preference $lang */ $lang = app('preferences')->getForUser($user, 'language', 'en_US'); - $groupTitle = (string) trans('firefly.rulegroup_for_bills_title', [], $lang->data); + $groupTitle = (string)trans('firefly.rulegroup_for_bills_title', [], $lang->data); $ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle); if (null === $ruleGroup) { $ruleGroup = $this->ruleGroupRepository->store( [ - 'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $lang->data), - 'description' => (string) trans('firefly.rulegroup_for_bills_description', [], $lang->data), + 'title' => (string)trans('firefly.rulegroup_for_bills_title', [], $lang->data), + 'description' => (string)trans('firefly.rulegroup_for_bills_description', [], $lang->data), 'active' => true, ] ); @@ -169,9 +171,9 @@ class MigrateToRules extends Command } /** - * @param RuleGroup $ruleGroup - * @param Bill $bill - * @param Preference $language + * @param RuleGroup $ruleGroup + * @param Bill $bill + * @param Preference $language */ private function migrateBill(RuleGroup $ruleGroup, Bill $bill, Preference $language): void { @@ -186,8 +188,8 @@ class MigrateToRules extends Command 'active' => true, 'strict' => false, 'stop_processing' => false, // field is no longer used. - 'title' => (string) trans('firefly.rule_for_bill_title', ['name' => $bill->name], $language->data), - 'description' => (string) trans('firefly.rule_for_bill_description', ['name' => $bill->name], $language->data), + 'title' => (string)trans('firefly.rule_for_bill_title', ['name' => $bill->name], $language->data), + 'description' => (string)trans('firefly.rule_for_bill_description', ['name' => $bill->name], $language->data), 'trigger' => 'store-journal', 'triggers' => [ [ diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php index d5f00056f7..0afedae36e 100644 --- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php +++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php @@ -35,6 +35,8 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Console\Command; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class OtherCurrenciesCorrections @@ -115,14 +117,14 @@ class OtherCurrenciesCorrections extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -147,7 +149,7 @@ class OtherCurrenciesCorrections extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal */ private function updateJournalCurrency(TransactionJournal $journal): void { @@ -188,8 +190,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 ((int)$transaction->transaction_currency_id !== (int)$currency->id) { + $transaction->foreign_currency_id = (int)$transaction->transaction_currency_id; $transaction->foreign_amount = $transaction->amount; $transaction->transaction_currency_id = $currency->id; $transaction->save(); @@ -206,7 +208,7 @@ class OtherCurrenciesCorrections extends Command * Gets the transaction that determines the transaction that "leads" and will determine * the currency to be used by all transactions, and the journal itself. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction|null */ @@ -247,7 +249,7 @@ class OtherCurrenciesCorrections extends Command } /** - * @param Account $account + * @param Account $account * * @return TransactionCurrency|null */ diff --git a/app/Console/Commands/Upgrade/RenameAccountMeta.php b/app/Console/Commands/Upgrade/RenameAccountMeta.php index 1591dbe898..8f4dd04373 100644 --- a/app/Console/Commands/Upgrade/RenameAccountMeta.php +++ b/app/Console/Commands/Upgrade/RenameAccountMeta.php @@ -26,6 +26,8 @@ namespace FireflyIII\Console\Commands\Upgrade; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\AccountMeta; use Illuminate\Console\Command; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class RenameAccountMeta @@ -99,14 +101,14 @@ class RenameAccountMeta extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; diff --git a/app/Console/Commands/Upgrade/TransactionIdentifier.php b/app/Console/Commands/Upgrade/TransactionIdentifier.php index 4672508f16..9a27dafc74 100644 --- a/app/Console/Commands/Upgrade/TransactionIdentifier.php +++ b/app/Console/Commands/Upgrade/TransactionIdentifier.php @@ -31,6 +31,8 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Console\Command; use Illuminate\Database\QueryException; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Schema; /** @@ -123,14 +125,14 @@ class TransactionIdentifier extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -140,7 +142,7 @@ class TransactionIdentifier extends Command * Grab all positive transactions from this journal that are not deleted. for each one, grab the negative opposing one * which has 0 as an identifier and give it the same identifier. * - * @param TransactionJournal $transactionJournal + * @param TransactionJournal $transactionJournal */ private function updateJournalIdentifiers(TransactionJournal $transactionJournal): void { @@ -166,15 +168,15 @@ class TransactionIdentifier extends Command } /** - * @param Transaction $transaction - * @param array $exclude + * @param Transaction $transaction + * @param array $exclude * * @return Transaction|null */ private function findOpposing(Transaction $transaction, array $exclude): ?Transaction { // find opposing: - $amount = bcmul((string) $transaction->amount, '-1'); + $amount = bcmul((string)$transaction->amount, '-1'); try { /** @var Transaction $opposing */ diff --git a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php index 11827e8584..295b8e6e87 100644 --- a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php +++ b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php @@ -33,6 +33,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class TransferCurrenciesCorrections @@ -69,8 +71,8 @@ class TransferCurrenciesCorrections extends Command * * @return int * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function handle(): int { @@ -137,14 +139,14 @@ class TransferCurrenciesCorrections extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -168,7 +170,7 @@ class TransferCurrenciesCorrections extends Command } /** - * @param TransactionJournal $transfer + * @param TransactionJournal $transfer */ private function updateTransferCurrency(TransactionJournal $transfer): void { @@ -233,7 +235,7 @@ class TransferCurrenciesCorrections extends Command /** * Is this a split transaction journal? * - * @param TransactionJournal $transfer + * @param TransactionJournal $transfer * * @return bool * @codeCoverageIgnore @@ -246,7 +248,7 @@ class TransferCurrenciesCorrections extends Command /** * Extract source transaction, source account + source account currency from the journal. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @codeCoverageIgnore */ @@ -258,7 +260,7 @@ class TransferCurrenciesCorrections extends Command } /** - * @param TransactionJournal $transfer + * @param TransactionJournal $transfer * * @return Transaction|null * @codeCoverageIgnore @@ -269,7 +271,7 @@ class TransferCurrenciesCorrections extends Command } /** - * @param Account $account + * @param Account $account * * @return TransactionCurrency|null */ @@ -296,7 +298,7 @@ class TransferCurrenciesCorrections extends Command /** * Extract destination transaction, destination account + destination account currency from the journal. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @codeCoverageIgnore */ @@ -308,7 +310,7 @@ class TransferCurrenciesCorrections extends Command } /** - * @param TransactionJournal $transfer + * @param TransactionJournal $transfer * * @return Transaction|null * @codeCoverageIgnore @@ -371,7 +373,7 @@ class TransferCurrenciesCorrections extends Command if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) { $this->sourceTransaction ->transaction_currency_id - = (int) $this->sourceCurrency->id; + = (int)$this->sourceCurrency->id; $message = sprintf( 'Transaction #%d has no currency setting, now set to %s.', $this->sourceTransaction->id, @@ -392,7 +394,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 !== (int)$this->sourceCurrency->id ) { $message = sprintf( 'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.', @@ -404,7 +406,7 @@ class TransferCurrenciesCorrections extends Command Log::debug($message); $this->line($message); $this->count++; - $this->sourceTransaction->transaction_currency_id = (int) $this->sourceCurrency->id; + $this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id; $this->sourceTransaction->save(); } } @@ -418,7 +420,7 @@ class TransferCurrenciesCorrections extends Command if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) { $this->destinationTransaction ->transaction_currency_id - = (int) $this->destinationCurrency->id; + = (int)$this->destinationCurrency->id; $message = sprintf( 'Transaction #%d has no currency setting, now set to %s.', $this->destinationTransaction->id, @@ -439,7 +441,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 !== (int)$this->destinationCurrency->id ) { $message = sprintf( 'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.', @@ -451,7 +453,7 @@ class TransferCurrenciesCorrections extends Command Log::debug($message); $this->line($message); $this->count++; - $this->destinationTransaction->transaction_currency_id = (int) $this->destinationCurrency->id; + $this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id; $this->destinationTransaction->save(); } } @@ -463,7 +465,7 @@ class TransferCurrenciesCorrections extends Command */ private function fixInvalidForeignCurrency(): void { - if ((int) $this->destinationCurrency->id === (int) $this->sourceCurrency->id) { + if ((int)$this->destinationCurrency->id === (int)$this->sourceCurrency->id) { // update both transactions to match: $this->sourceTransaction->foreign_amount = null; $this->sourceTransaction->foreign_currency_id = null; @@ -497,7 +499,7 @@ class TransferCurrenciesCorrections extends Command */ private function fixMismatchedForeignCurrency(): void { - if ((int) $this->sourceCurrency->id !== (int) $this->destinationCurrency->id) { + if ((int)$this->sourceCurrency->id !== (int)$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; @@ -517,7 +519,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((string)$this->destinationTransaction->foreign_amount, '-1'); $this->sourceTransaction->save(); $this->count++; Log::debug( @@ -537,7 +539,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((string)$this->sourceTransaction->foreign_amount, '-1'); $this->destinationTransaction->save(); $this->count++; Log::debug( @@ -553,11 +555,11 @@ class TransferCurrenciesCorrections extends Command /** * This method makes sure that the transaction journal uses the currency given in the source transaction. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal */ private function fixTransactionJournalCurrency(TransactionJournal $journal): void { - if ((int) $journal->transaction_currency_id !== (int) $this->sourceCurrency->id) { + if ((int)$journal->transaction_currency_id !== (int)$this->sourceCurrency->id) { $oldCurrencyCode = $journal->transactionCurrency->code ?? '(nothing)'; $journal->transaction_currency_id = $this->sourceCurrency->id; $message = sprintf( diff --git a/app/Console/Commands/Upgrade/UpgradeDatabase.php b/app/Console/Commands/Upgrade/UpgradeDatabase.php index d97c14e576..5a493abe57 100644 --- a/app/Console/Commands/Upgrade/UpgradeDatabase.php +++ b/app/Console/Commands/Upgrade/UpgradeDatabase.php @@ -121,9 +121,9 @@ class UpgradeDatabase extends Command echo $result; } // set new DB version. - app('fireflyconfig')->set('db_version', (int) config('firefly.db_version')); + app('fireflyconfig')->set('db_version', (int)config('firefly.db_version')); // index will set FF3 version. - app('fireflyconfig')->set('ff3_version', (string) config('firefly.version')); + app('fireflyconfig')->set('ff3_version', (string)config('firefly.version')); return 0; } diff --git a/app/Console/Commands/Upgrade/UpgradeLiabilities.php b/app/Console/Commands/Upgrade/UpgradeLiabilities.php index 8fb175caff..43c2cc68c5 100644 --- a/app/Console/Commands/Upgrade/UpgradeLiabilities.php +++ b/app/Console/Commands/Upgrade/UpgradeLiabilities.php @@ -34,6 +34,8 @@ use FireflyIII\Services\Internal\Support\CreditRecalculateService; use FireflyIII\User; use Illuminate\Console\Command; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class UpgradeLiabilities @@ -81,14 +83,14 @@ class UpgradeLiabilities extends Command /** * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function isExecuted(): bool { $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); if (null !== $configVar) { - return (bool) $configVar->data; + return (bool)$configVar->data; } return false; @@ -108,7 +110,7 @@ class UpgradeLiabilities extends Command } /** - * @param User $user + * @param User $user */ private function upgradeForUser(User $user): void { @@ -127,7 +129,7 @@ class UpgradeLiabilities extends Command } /** - * @param Account $account + * @param Account $account */ private function upgradeLiability(Account $account): void { @@ -150,8 +152,8 @@ class UpgradeLiabilities extends Command } /** - * @param Account $account - * @param TransactionJournal $openingBalance + * @param Account $account + * @param TransactionJournal $openingBalance */ private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void { @@ -161,10 +163,10 @@ class UpgradeLiabilities extends Command return; } // source MUST be the liability. - if ((int) $destination->account_id === (int) $account->id) { + if ((int)$destination->account_id === (int)$account->id) { Log::debug(sprintf('Must switch around, because account #%d is the destination.', $destination->account_id)); // so if not, switch things around: - $sourceAccountId = (int) $source->account_id; + $sourceAccountId = (int)$source->account_id; $source->account_id = $destination->account_id; $destination->account_id = $sourceAccountId; $source->save(); @@ -175,7 +177,7 @@ class UpgradeLiabilities extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction|null */ @@ -185,7 +187,7 @@ class UpgradeLiabilities extends Command } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction|null */ diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php index 63b19a6315..06c27d32fa 100644 --- a/app/Console/Commands/UpgradeFireflyInstructions.php +++ b/app/Console/Commands/UpgradeFireflyInstructions.php @@ -54,10 +54,10 @@ class UpgradeFireflyInstructions extends Command public function handle(): int { $this->generateInstallationId(); - if ('update' === (string) $this->argument('task')) { + if ('update' === (string)$this->argument('task')) { $this->updateInstructions(); } - if ('install' === (string) $this->argument('task')) { + if ('install' === (string)$this->argument('task')) { $this->installInstructions(); } @@ -112,26 +112,26 @@ class UpgradeFireflyInstructions extends Command /** * Show a nice box. * - * @param string $text + * @param string $text */ private function boxed(string $text): void { $parts = explode("\n", wordwrap($text)); foreach ($parts as $string) { - $this->line('| ' . sprintf('%-77s', $string) . '|'); + $this->line('| '.sprintf('%-77s', $string).'|'); } } /** * Show a nice info box. * - * @param string $text + * @param string $text */ private function boxedInfo(string $text): void { $parts = explode("\n", wordwrap($text)); foreach ($parts as $string) { - $this->info('| ' . sprintf('%-77s', $string) . '|'); + $this->info('| '.sprintf('%-77s', $string).'|'); } } diff --git a/app/Console/Commands/VerifiesAccessToken.php b/app/Console/Commands/VerifiesAccessToken.php index 7a8c06e076..d5b4783acc 100644 --- a/app/Console/Commands/VerifiesAccessToken.php +++ b/app/Console/Commands/VerifiesAccessToken.php @@ -43,7 +43,7 @@ trait VerifiesAccessToken */ public function getUser(): User { - $userId = (int) $this->option('user'); + $userId = (int)$this->option('user'); /** @var UserRepositoryInterface $repository */ $repository = app(UserRepositoryInterface::class); $user = $repository->find($userId); @@ -57,7 +57,7 @@ trait VerifiesAccessToken /** * Abstract method to make sure trait knows about method "option". * - * @param string|null $key + * @param string|null $key * * @return mixed */ @@ -71,8 +71,8 @@ trait VerifiesAccessToken */ protected function verifyAccessToken(): bool { - $userId = (int) $this->option('user'); - $token = (string) $this->option('token'); + $userId = (int)$this->option('user'); + $token = (string)$this->option('token'); /** @var UserRepositoryInterface $repository */ $repository = app(UserRepositoryInterface::class); $user = $repository->find($userId); diff --git a/app/Console/Commands/VerifySecurityAlerts.php b/app/Console/Commands/VerifySecurityAlerts.php index 4427f91a4d..b7ab063619 100644 --- a/app/Console/Commands/VerifySecurityAlerts.php +++ b/app/Console/Commands/VerifySecurityAlerts.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands; use Illuminate\Console\Command; +use League\Flysystem\FilesystemException; use Log; use Storage; @@ -50,7 +51,7 @@ class VerifySecurityAlerts extends Command * Execute the console command. * * @return int - * @throws \League\Flysystem\FilesystemException + * @throws FilesystemException */ public function handle(): int {