Use PSR-12 code style

This commit is contained in:
James Cole
2022-10-30 12:24:51 +01:00
parent bdcd9825ec
commit b27fe59ab4
44 changed files with 414 additions and 332 deletions

37
.ci/phpcs.sh Executable file
View File

@@ -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 <https://www.gnu.org/licenses/>.
#
# 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

View File

@@ -28,12 +28,6 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# enable test .env file. # enable test .env file.
# cp .ci/.env.ci .env # 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. # Do static code analysis.
# ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress # ./vendor/bin/phpstan analyse -c .ci/phpstan.neon --no-progress
./vendor/bin/phpstan analyse -c .ci/phpstan.neon ./vendor/bin/phpstan analyse -c .ci/phpstan.neon

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -63,8 +64,8 @@ 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::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') $set = TransactionJournal::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.*']);
$this->line(sprintf('Going to verify %d opening balance transactions.', $set->count())); $this->line(sprintf('Going to verify %d opening balance transactions.', $set->count()));
$count = 0; $count = 0;
@@ -90,7 +91,7 @@ class CorrectOpeningBalanceCurrencies extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return int * @return int
*/ */
@@ -112,7 +113,7 @@ class CorrectOpeningBalanceCurrencies extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Account|null * @return Account|null
*/ */
@@ -131,11 +132,11 @@ class CorrectOpeningBalanceCurrencies extends Command
} }
/** /**
* @param Account $account * @param Account $account
* *
* @return TransactionCurrency * @return TransactionCurrency
* @throws JsonException * @throws JsonException
* @throws \FireflyIII\Exceptions\FireflyException * @throws FireflyException
*/ */
private function getCurrency(Account $account): TransactionCurrency private function getCurrency(Account $account): TransactionCurrency
{ {
@@ -147,15 +148,15 @@ class CorrectOpeningBalanceCurrencies extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
* *
* @return int * @return int
*/ */
private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): int private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): int
{ {
$count = 0; $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->transaction_currency_id = $currency->id;
$journal->save(); $journal->save();
$count = 1; $count = 1;
@@ -163,7 +164,7 @@ class CorrectOpeningBalanceCurrencies extends Command
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($journal->transactions as $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->transaction_currency_id = $currency->id;
$transaction->save(); $transaction->save();
$count = 1; $count = 1;

View File

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

View File

@@ -67,22 +67,22 @@ class DeleteEmptyJournals extends Command
private function deleteUnevenJournals(): void private function deleteUnevenJournals(): void
{ {
$set = Transaction::whereNull('deleted_at') $set = Transaction::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;
/** @var Transaction $row */ /** @var Transaction $row */
foreach ($set as $row) { foreach ($set as $row) {
$count = (int) $row->the_count; $count = (int)$row->the_count;
if (1 === $count % 2) { if (1 === $count % 2) {
// 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()));
} }
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)); $this->info(sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id));
$total++; $total++;
} }

View File

@@ -66,6 +66,34 @@ class DeleteOrphanedTransactions extends Command
return 0; 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 * @throws Exception
*/ */
@@ -73,18 +101,18 @@ class DeleteOrphanedTransactions extends Command
{ {
$count = 0; $count = 0;
$set = Transaction::leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') $set = Transaction::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')
->get( ->get(
[ [
'transaction_journals.id as journal_id', 'transaction_journals.id as journal_id',
'transactions.id as transaction_id', 'transactions.id as transaction_id',
] ]
); );
/** @var stdClass $entry */ /** @var stdClass $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
$transaction = Transaction::find((int) $entry->transaction_id); $transaction = Transaction::find((int)$entry->transaction_id);
if (null !== $transaction) { if (null !== $transaction) {
$transaction->delete(); $transaction->delete();
$this->info( $this->info(
@@ -109,13 +137,13 @@ class DeleteOrphanedTransactions extends Command
{ {
$set $set
= Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id') = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->whereNotNull('accounts.deleted_at') ->whereNotNull('accounts.deleted_at')
->get(['transactions.*']); ->get(['transactions.*']);
$count = 0; $count = 0;
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($set as $transaction) { foreach ($set as $transaction) {
// delete journals // delete journals
$journal = TransactionJournal::find((int) $transaction->transaction_journal_id); $journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
if ($journal) { if ($journal) {
try { try {
$journal->delete(); $journal->delete();
@@ -123,7 +151,7 @@ class DeleteOrphanedTransactions extends Command
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(
sprintf( sprintf(
'Deleted transaction journal #%d because account #%d was already deleted.', 'Deleted transaction journal #%d because account #%d was already deleted.',
@@ -137,32 +165,4 @@ class DeleteOrphanedTransactions extends Command
$this->info('No orphaned accounts.'); $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
)
);
}
}
}
}
} }

View File

@@ -63,26 +63,26 @@ class EnableCurrencies extends Command
/** @var Collection $meta */ /** @var Collection $meta */
$meta = AccountMeta::where('name', 'currency_id')->groupBy('data')->get(['data']); $meta = AccountMeta::where('name', 'currency_id')->groupBy('data')->get(['data']);
foreach ($meta as $entry) { foreach ($meta as $entry) {
$found[] = (int) $entry->data; $found[] = (int)$entry->data;
} }
// get all from journals: // get all from journals:
$journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']); $journals = TransactionJournal::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
foreach ($journals as $entry) { foreach ($journals as $entry) {
$found[] = (int) $entry->transaction_currency_id; $found[] = (int)$entry->transaction_currency_id;
} }
// get all from transactions // get all from transactions
$transactions = Transaction::groupBy('transaction_currency_id', 'foreign_currency_id')->get(['transaction_currency_id', 'foreign_currency_id']); $transactions = Transaction::groupBy('transaction_currency_id', 'foreign_currency_id')->get(['transaction_currency_id', 'foreign_currency_id']);
foreach ($transactions as $entry) { foreach ($transactions as $entry) {
$found[] = (int) $entry->transaction_currency_id; $found[] = (int)$entry->transaction_currency_id;
$found[] = (int) $entry->foreign_currency_id; $found[] = (int)$entry->foreign_currency_id;
} }
// get all from budget limits // get all from budget limits
$limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']); $limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
foreach ($limits as $entry) { foreach ($limits as $entry) {
$found[] = (int) $entry->transaction_currency_id; $found[] = (int)$entry->transaction_currency_id;
} }
$found = array_values(array_unique($found)); $found = array_values(array_unique($found));

View File

@@ -99,7 +99,7 @@ class FixAccountTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @throws FireflyException * @throws FireflyException
*/ */
@@ -140,7 +140,7 @@ class FixAccountTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Transaction * @return Transaction
*/ */
@@ -150,7 +150,7 @@ class FixAccountTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Transaction * @return Transaction
*/ */
@@ -160,10 +160,10 @@ class FixAccountTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param string $type * @param string $type
* @param Transaction $source * @param Transaction $source
* @param Transaction $dest * @param Transaction $dest
* *
* @throws FireflyException * @throws FireflyException
*/ */

View File

@@ -73,7 +73,7 @@ class FixFrontpageAccounts extends Command
} }
/** /**
* @param Preference $preference * @param Preference $preference
*/ */
private function fixPreference(Preference $preference): void private function fixPreference(Preference $preference): void
{ {
@@ -88,7 +88,7 @@ class FixFrontpageAccounts extends Command
if (is_array($data)) { if (is_array($data)) {
/** @var string $accountId */ /** @var string $accountId */
foreach ($data as $accountId) { foreach ($data as $accountId) {
$accountIdInt = (int) $accountId; $accountIdInt = (int)$accountId;
$account = $repository->find($accountIdInt); $account = $repository->find($accountIdInt);
if (null !== $account if (null !== $account
&& in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true) && in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true)

View File

@@ -58,11 +58,11 @@ class FixGroupAccounts extends Command
{ {
$groups = []; $groups = [];
$res = TransactionJournal::groupBy('transaction_group_id') $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 */ /** @var TransactionJournal $journal */
foreach ($res as $journal) { foreach ($res as $journal) {
if ((int) $journal->the_count > 1) { if ((int)$journal->the_count > 1) {
$groups[] = (int) $journal->transaction_group_id; $groups[] = (int)$journal->transaction_group_id;
} }
} }
$handler = new UpdatedGroupEventHandler(); $handler = new UpdatedGroupEventHandler();

View File

@@ -57,7 +57,7 @@ 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;
$account->save(); $account->save();

View File

@@ -68,7 +68,7 @@ class FixLongDescriptions extends Command
$groups = TransactionGroup::get(['id', 'title']); $groups = TransactionGroup::get(['id', 'title']);
/** @var TransactionGroup $group */ /** @var TransactionGroup $group */
foreach ($groups as $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->title = substr($group->title, 0, self::MAX_LENGTH);
$group->save(); $group->save();
$this->line(sprintf('Truncated description of transaction group #%d', $group->id)); $this->line(sprintf('Truncated description of transaction group #%d', $group->id));

View File

@@ -96,7 +96,7 @@ class FixRecurringTransactions extends Command
} }
/** /**
* @param User $user * @param User $user
*/ */
private function processUser(User $user): void 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 private function processRecurrence(Recurrence $recurrence): void
{ {
@@ -120,8 +120,8 @@ class FixRecurringTransactions extends Command
} }
/** /**
* @param Recurrence $recurrence * @param Recurrence $recurrence
* @param RecurrenceTransaction $transaction * @param RecurrenceTransaction $transaction
*/ */
private function processTransaction(Recurrence $recurrence, RecurrenceTransaction $transaction): void private function processTransaction(Recurrence $recurrence, RecurrenceTransaction $transaction): void
{ {

View File

@@ -86,11 +86,11 @@ class FixTransactionTypes extends Command
private function collectJournals(): Collection private function collectJournals(): Collection
{ {
return TransactionJournal::with(['transactionType', 'transactions', 'transactions.account', 'transactions.account.accountType']) return TransactionJournal::with(['transactionType', 'transactions', 'transactions.account', 'transactions.account.accountType'])
->get(); ->get();
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return bool * @return bool
*/ */
@@ -105,7 +105,7 @@ class FixTransactionTypes extends Command
return false; 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) { if ($expectedType !== $type) {
$this->line( $this->line(
sprintf( sprintf(
@@ -126,7 +126,7 @@ class FixTransactionTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Account * @return Account
* @throws FireflyException * @throws FireflyException
@@ -155,7 +155,7 @@ class FixTransactionTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Account * @return Account
* @throws FireflyException * @throws FireflyException
@@ -184,8 +184,8 @@ class FixTransactionTypes extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param string $expectedType * @param string $expectedType
*/ */
private function changeJournal(TransactionJournal $journal, string $expectedType): void private function changeJournal(TransactionJournal $journal, string $expectedType): void
{ {

View File

@@ -65,11 +65,11 @@ class FixUnevenAmount extends Command
->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]); ->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]);
/** @var stdClass $entry */ /** @var stdClass $entry */
foreach ($journals as $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); $message = sprintf('Sum of journal #%d is %s instead of zero.', $entry->transaction_journal_id, $entry->the_sum);
$this->warn($message); $this->warn($message);
Log::warning($message); Log::warning($message);
$this->fixJournal((int) $entry->transaction_journal_id); $this->fixJournal((int)$entry->transaction_journal_id);
$count++; $count++;
} }
} }
@@ -84,7 +84,7 @@ class FixUnevenAmount extends Command
} }
/** /**
* @param int $param * @param int $param
*/ */
private function fixJournal(int $param): void private function fixJournal(int $param): void
{ {
@@ -110,7 +110,7 @@ class FixUnevenAmount extends Command
return; return;
} }
$amount = bcmul('-1', (string) $source->amount); $amount = bcmul('-1', (string)$source->amount);
// fix amount of destination: // fix amount of destination:
/** @var Transaction $destination */ /** @var Transaction $destination */

View File

@@ -87,8 +87,8 @@ class RenameMetaFields extends Command
} }
/** /**
* @param string $original * @param string $original
* @param string $update * @param string $update
*/ */
private function rename(string $original, string $update): void private function rename(string $original, string $update): void
{ {

View File

@@ -32,6 +32,8 @@ use Illuminate\Console\Command;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use JsonException; use JsonException;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use stdClass; use stdClass;
/** /**
@@ -75,7 +77,7 @@ class DecryptDatabase extends Command
]; ];
/** /**
* @var string $table * @var string $table
* @var array $fields * @var array $fields
*/ */
foreach ($tables as $table => $fields) { foreach ($tables as $table => $fields) {
$this->decryptTable($table, $fields); $this->decryptTable($table, $fields);
@@ -86,8 +88,8 @@ class DecryptDatabase extends Command
} }
/** /**
* @param string $table * @param string $table
* @param array $fields * @param array $fields
*/ */
private function decryptTable(string $table, array $fields): void private function decryptTable(string $table, array $fields): void
{ {
@@ -106,11 +108,11 @@ class DecryptDatabase extends Command
} }
/** /**
* @param string $table * @param string $table
* *
* @return bool * @return bool
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isDecrypted(string $table): bool private function isDecrypted(string $table): bool
{ {
@@ -122,15 +124,15 @@ class DecryptDatabase extends Command
Log::error($e->getMessage()); Log::error($e->getMessage());
} }
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
} }
/** /**
* @param string $table * @param string $table
* @param string $field * @param string $field
*/ */
private function decryptField(string $table, string $field): void private function decryptField(string $table, string $field): void
{ {
@@ -142,9 +144,9 @@ class DecryptDatabase extends Command
} }
/** /**
* @param string $table * @param string $table
* @param string $field * @param string $field
* @param stdClass $row * @param stdClass $row
*/ */
private function decryptRow(string $table, string $field, stdClass $row): void private function decryptRow(string $table, string $field, stdClass $row): void
{ {
@@ -152,7 +154,7 @@ class DecryptDatabase extends Command
if (null === $original) { if (null === $original) {
return; return;
} }
$id = (int) $row->id; $id = (int)$row->id;
$value = ''; $value = '';
try { try {
@@ -179,7 +181,7 @@ class DecryptDatabase extends Command
/** /**
* Tries to decrypt data. Will only throw an exception when the MAC is invalid. * Tries to decrypt data. Will only throw an exception when the MAC is invalid.
* *
* @param mixed $value * @param mixed $value
* *
* @return string * @return string
* @throws FireflyException * @throws FireflyException
@@ -198,8 +200,8 @@ class DecryptDatabase extends Command
} }
/** /**
* @param int $id * @param int $id
* @param string $value * @param string $value
*/ */
private function decryptPreferencesRow(int $id, string $value): void private function decryptPreferencesRow(int $id, string $value): void
{ {
@@ -217,7 +219,7 @@ class DecryptDatabase extends Command
} }
/** @var Preference $object */ /** @var Preference $object */
$object = Preference::find((int) $id); $object = Preference::find((int)$id);
if (null !== $object) { if (null !== $object) {
$object->data = $newValue; $object->data = $newValue;
$object->save(); $object->save();

View File

@@ -184,7 +184,7 @@ class ExportData extends Command
} }
/** /**
* @param string $field * @param string $field
* *
* @return Carbon * @return Carbon
* @throws Exception * @throws Exception
@@ -234,7 +234,7 @@ class ExportData extends Command
$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) {
$accountIds = explode(',', $accountList); $accountIds = explode(',', $accountList);
$accounts = $this->accountRepository->getAccountsById($accountIds); $accounts = $this->accountRepository->getAccountsById($accountIds);
} }
@@ -262,7 +262,7 @@ class ExportData extends Command
*/ */
private function getExportDirectory(): string private function getExportDirectory(): string
{ {
$directory = (string) $this->option('export_directory'); $directory = (string)$this->option('export_directory');
if (null === $directory) { if (null === $directory) {
$directory = './'; $directory = './';
} }
@@ -274,8 +274,8 @@ class ExportData extends Command
} }
/** /**
* @param array $options * @param array $options
* @param array $data * @param array $data
* *
* @throws FireflyException * @throws FireflyException
*/ */

View File

@@ -68,7 +68,7 @@ class ReportSum extends Command
/** @var User $user */ /** @var User $user */
foreach ($userRepository->all() as $user) { foreach ($userRepository->all() as $user) {
$sum = (string) $user->transactions()->sum('amount'); $sum = (string)$user->transactions()->sum('amount');
if (0 !== bccomp($sum, '0')) { if (0 !== bccomp($sum, '0')) {
$message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum); $message = sprintf('Error: Transactions for user #%d (%s) are off by %s!', $user->id, $user->email, $sum);
$this->error($message); $this->error($message);

View File

@@ -47,19 +47,18 @@ use Illuminate\Console\Command;
*/ */
class UpdateGroupInformation extends 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. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Makes sure that every object is linked to a group'; 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. * Execute the console command.
@@ -87,19 +86,31 @@ class UpdateGroupInformation extends Command
$this->warn(sprintf('User "%s" has no group.', $user->email)); $this->warn(sprintf('User "%s" has no group.', $user->email));
return; return;
} }
$set = [Account::class, Attachment::class, AvailableBudget::class, $set = [
Bill::class, Budget::class, Category::class, CurrencyExchangeRate::class, Account::class,
Recurrence::class, RuleGroup::class, Rule::class, Tag::class, TransactionGroup::class, Attachment::class,
TransactionJournal::class, Webhook::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) { foreach ($set as $className) {
$this->updateGroupInfoForObject($user, $group, $className); $this->updateGroupInfoForObject($user, $group, $className);
} }
} }
/** /**
* @param User $user * @param User $user
* @param UserGroup $group * @param UserGroup $group
* @param string $className * @param string $className
* @return void * @return void
*/ */
private function updateGroupInfoForObject(User $user, UserGroup $group, string $className): void private function updateGroupInfoForObject(User $user, UserGroup $group, string $className): void

View File

@@ -212,7 +212,7 @@ class ApplyRules extends Command
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($this->getUser()); $accountRepository->setUser($this->getUser());
foreach ($accountList as $accountId) { foreach ($accountList as $accountId) {
$accountId = (int) $accountId; $accountId = (int)$accountId;
$account = $accountRepository->find($accountId); $account = $accountRepository->find($accountId);
if (null !== $account && in_array($account->accountType->type, $this->acceptedAccounts, true)) { if (null !== $account && in_array($account->accountType->type, $this->acceptedAccounts, true)) {
$finalList->push($account); $finalList->push($account);
@@ -242,7 +242,7 @@ class ApplyRules extends Command
$ruleGroupList = explode(',', $ruleGroupString); $ruleGroupList = explode(',', $ruleGroupString);
foreach ($ruleGroupList as $ruleGroupId) { foreach ($ruleGroupList as $ruleGroupId) {
$ruleGroup = $this->ruleGroupRepository->find((int) $ruleGroupId); $ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId);
if ($ruleGroup->active) { if ($ruleGroup->active) {
$this->ruleGroupSelection[] = $ruleGroup->id; $this->ruleGroupSelection[] = $ruleGroup->id;
} }
@@ -267,7 +267,7 @@ class ApplyRules extends Command
$ruleList = explode(',', $ruleString); $ruleList = explode(',', $ruleString);
foreach ($ruleList as $ruleId) { foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int) $ruleId); $rule = $this->ruleRepository->find((int)$ruleId);
if (null !== $rule && $rule->active) { if (null !== $rule && $rule->active) {
$this->ruleSelection[] = $rule->id; $this->ruleSelection[] = $rule->id;
} }
@@ -343,8 +343,8 @@ class ApplyRules extends Command
} }
/** /**
* @param Rule $rule * @param Rule $rule
* @param RuleGroup $group * @param RuleGroup $group
* *
* @return bool * @return bool
*/ */

View File

@@ -68,7 +68,7 @@ class Cron extends Command
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$this->error(sprintf('"%s" is not a valid date', $this->option('date'))); $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. * Fire recurring transaction cron job.
@@ -122,8 +122,35 @@ class Cron extends Command
} }
/** /**
* @param bool $force * @param bool $force
* @param Carbon|null $date * @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 * @throws FireflyException
*/ */
@@ -150,8 +177,8 @@ class Cron extends Command
} }
/** /**
* @param bool $force * @param bool $force
* @param Carbon|null $date * @param Carbon|null $date
* *
*/ */
private function autoBudgetCronJob(bool $force, ?Carbon $date): void private function autoBudgetCronJob(bool $force, ?Carbon $date): void
@@ -177,8 +204,8 @@ class Cron extends Command
} }
/** /**
* @param bool $force * @param bool $force
* @param Carbon|null $date * @param Carbon|null $date
* @throws FireflyException * @throws FireflyException
*/ */
private function billWarningCronJob(bool $force, ?Carbon $date): void 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)); $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));
}
}
} }

View File

@@ -34,6 +34,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class AccountCurrencies * Class AccountCurrencies
@@ -109,14 +111,14 @@ class AccountCurrencies extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -129,7 +131,7 @@ class AccountCurrencies extends Command
{ {
Log::debug('Now in updateAccountCurrencies()'); Log::debug('Now in updateAccountCurrencies()');
$users = $this->userRepos->all(); $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)); Log::debug(sprintf('Default currency is %s', $defaultCurrencyCode));
foreach ($users as $user) { foreach ($users as $user) {
$this->updateCurrenciesForUser($user, $defaultCurrencyCode); $this->updateCurrenciesForUser($user, $defaultCurrencyCode);
@@ -137,8 +139,8 @@ class AccountCurrencies extends Command
} }
/** /**
* @param User $user * @param User $user
* @param string $systemCurrencyCode * @param string $systemCurrencyCode
* *
* @throws FireflyException * @throws FireflyException
*/ */
@@ -172,21 +174,21 @@ class AccountCurrencies extends Command
} }
/** /**
* @param Account $account * @param Account $account
* @param TransactionCurrency $currency * @param TransactionCurrency $currency
*/ */
private function updateAccount(Account $account, TransactionCurrency $currency): void private function updateAccount(Account $account, TransactionCurrency $currency): void
{ {
Log::debug(sprintf('Now in updateAccount(%d, %s)', $account->id, $currency->code)); Log::debug(sprintf('Now in updateAccount(%d, %s)', $account->id, $currency->code));
$this->accountRepos->setUser($account->user); $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)); Log::debug(sprintf('Account currency is #%d', $accountCurrency));
$openingBalance = $this->accountRepos->getOpeningBalance($account); $openingBalance = $this->accountRepos->getOpeningBalance($account);
$obCurrency = 0; $obCurrency = 0;
if (null !== $openingBalance) { if (null !== $openingBalance) {
$obCurrency = (int) $openingBalance->transaction_currency_id; $obCurrency = (int)$openingBalance->transaction_currency_id;
Log::debug('Account has opening balance.'); Log::debug('Account has opening balance.');
} }
Log::debug(sprintf('Account OB currency is #%d.', $obCurrency)); Log::debug(sprintf('Account OB currency is #%d.', $obCurrency));

View File

@@ -27,6 +27,8 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class AppendBudgetLimitPeriods extends Command class AppendBudgetLimitPeriods extends Command
{ {
@@ -72,14 +74,14 @@ class AppendBudgetLimitPeriods extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $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) private function fixLimit(BudgetLimit $limit)
{ {
@@ -127,7 +129,7 @@ class AppendBudgetLimitPeriods extends Command
} }
/** /**
* @param BudgetLimit $limit * @param BudgetLimit $limit
* *
* @return string|null * @return string|null
*/ */

View File

@@ -32,6 +32,8 @@ use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class BackToJournals * Class BackToJournals
@@ -85,27 +87,27 @@ class BackToJournals extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isMigrated(): bool private function isMigrated(): bool
{ {
$configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false);
return (bool) $configVar->data; return (bool)$configVar->data;
} }
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $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 private function migrateBudgetsForJournal(TransactionJournal $journal): void
{ {
@@ -179,7 +181,7 @@ class BackToJournals extends Command
// both have a budget, but they don't match. // both have a budget, but they don't match.
if (null !== $budget && null !== $journalBudget && $budget->id !== $journalBudget->id) { if (null !== $budget && null !== $journalBudget && $budget->id !== $journalBudget->id) {
// sync to journal: // sync to journal:
$journal->budgets()->sync([(int) $budget->id]); $journal->budgets()->sync([(int)$budget->id]);
return; return;
} }
@@ -187,7 +189,7 @@ class BackToJournals extends Command
// transaction has a budget, but the journal doesn't. // transaction has a budget, but the journal doesn't.
if (null !== $budget && null === $journalBudget) { if (null !== $budget && null === $journalBudget) {
// sync to journal: // 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); $chunks = array_chunk($transactions, 500);
foreach ($chunks as $chunk) { foreach ($chunks as $chunk) {
$set = DB::table('transactions') // @phpstan-ignore-line $set = DB::table('transactions') // @phpstan-ignore-line
->whereIn('transactions.id', $chunk) ->whereIn('transactions.id', $chunk)
->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$array = array_merge($array, $set); $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 private function migrateCategoriesForJournal(TransactionJournal $journal): void
{ {
@@ -255,12 +257,12 @@ class BackToJournals extends Command
// both have a category, but they don't match. // both have a category, but they don't match.
if (null !== $category && null !== $journalCategory && $category->id !== $journalCategory->id) { if (null !== $category && null !== $journalCategory && $category->id !== $journalCategory->id) {
// sync to journal: // sync to journal:
$journal->categories()->sync([(int) $category->id]); $journal->categories()->sync([(int)$category->id]);
} }
// transaction has a category, but the journal doesn't. // transaction has a category, but the journal doesn't.
if (null !== $category && null === $journalCategory) { if (null !== $category && null === $journalCategory) {
$journal->categories()->sync([(int) $category->id]); $journal->categories()->sync([(int)$category->id]);
} }
} }

View File

@@ -27,6 +27,8 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use JsonException; use JsonException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class BudgetLimitCurrency * Class BudgetLimitCurrency
@@ -99,14 +101,14 @@ class BudgetLimitCurrency extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;

View File

@@ -28,6 +28,8 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class CCLiabilities * Class CCLiabilities
@@ -96,14 +98,14 @@ class CCLiabilities extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;

View File

@@ -31,6 +31,8 @@ use FireflyIII\Models\UserRole;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class CreateGroupMemberships * Class CreateGroupMemberships
@@ -77,14 +79,14 @@ class CreateGroupMemberships extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -109,7 +111,7 @@ class CreateGroupMemberships extends Command
} }
/** /**
* @param User $user * @param User $user
* *
* @return bool * @return bool
*/ */
@@ -119,7 +121,7 @@ class CreateGroupMemberships extends Command
} }
/** /**
* @param User $user * @param User $user
* *
* @throws FireflyException * @throws FireflyException
*/ */

View File

@@ -28,6 +28,8 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\Note; use FireflyIII\Models\Note;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateAttachments * Class MigrateAttachments
@@ -70,7 +72,7 @@ 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();
@@ -105,14 +107,14 @@ class MigrateAttachments extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;

View File

@@ -29,6 +29,8 @@ use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournalMeta; use FireflyIII\Models\TransactionJournalMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateJournalNotes * Class MigrateJournalNotes
@@ -105,14 +107,14 @@ class MigrateJournalNotes extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;

View File

@@ -29,6 +29,8 @@ use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceTransactionMeta; use FireflyIII\Models\RecurrenceTransactionMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use JsonException; use JsonException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateRecurrenceMeta * Class MigrateRecurrenceMeta
@@ -84,14 +86,14 @@ class MigrateRecurrenceMeta extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -115,7 +117,7 @@ class MigrateRecurrenceMeta extends Command
} }
/** /**
* @param RecurrenceMeta $meta * @param RecurrenceMeta $meta
* *
* @return int * @return int
* @throws JsonException * @throws JsonException

View File

@@ -29,6 +29,8 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateRecurrenceType * Class MigrateRecurrenceType
@@ -77,14 +79,14 @@ class MigrateRecurrenceType extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -106,7 +108,7 @@ class MigrateRecurrenceType extends Command
private function migrateRecurrence(Recurrence $recurrence): void private function migrateRecurrence(Recurrence $recurrence): void
{ {
$originalType = (int) $recurrence->transaction_type_id; $originalType = (int)$recurrence->transaction_type_id;
$newType = $this->getInvalidType(); $newType = $this->getInvalidType();
$recurrence->transaction_type_id = $newType->id; $recurrence->transaction_type_id = $newType->id;
$recurrence->save(); $recurrence->save();

View File

@@ -28,6 +28,8 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateTagLocations * Class MigrateTagLocations
@@ -74,14 +76,14 @@ class MigrateTagLocations extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -99,7 +101,7 @@ class MigrateTagLocations extends Command
} }
/** /**
* @param Tag $tag * @param Tag $tag
* *
* @return bool * @return bool
*/ */
@@ -109,7 +111,7 @@ class MigrateTagLocations extends Command
} }
/** /**
* @param Tag $tag * @param Tag $tag
*/ */
private function migrateLocationDetails(Tag $tag): void private function migrateLocationDetails(Tag $tag): void
{ {

View File

@@ -37,6 +37,8 @@ use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* This command will take split transactions and migrate them to "transaction groups". * This command will take split transactions and migrate them to "transaction groups".
@@ -129,14 +131,14 @@ class MigrateToGroups extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isMigrated(): bool private function isMigrated(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -161,7 +163,7 @@ class MigrateToGroups extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @throws Exception * @throws Exception
*/ */
@@ -303,7 +305,7 @@ class MigrateToGroups extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Collection * @return Collection
*/ */
@@ -317,8 +319,8 @@ class MigrateToGroups extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* @param Transaction $transaction * @param Transaction $transaction
* *
* @return Transaction|null * @return Transaction|null
*/ */
@@ -326,7 +328,7 @@ class MigrateToGroups extends Command
{ {
$set = $journal->transactions->filter( $set = $journal->transactions->filter(
static function (Transaction $subject) use ($transaction) { 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; $identifier = $transaction->identifier === $subject->identifier;
Log::debug(sprintf('Amount the same? %s', var_export($amount, true))); Log::debug(sprintf('Amount the same? %s', var_export($amount, true)));
Log::debug(sprintf('ID the same? %s', var_export($identifier, 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 $left
* @param Transaction $right * @param Transaction $right
* *
* @return int|null * @return int|null
*/ */
@@ -354,7 +356,7 @@ class MigrateToGroups extends Command
if (null !== $budget) { if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id)); 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: // try to get a budget ID from the right transaction:
@@ -363,7 +365,7 @@ class MigrateToGroups extends Command
if (null !== $budget) { if (null !== $budget) {
Log::debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id)); 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'); Log::debug('Neither left or right have a budget, return NULL');
@@ -372,8 +374,8 @@ class MigrateToGroups extends Command
} }
/** /**
* @param Transaction $left * @param Transaction $left
* @param Transaction $right * @param Transaction $right
* *
* @return int|null * @return int|null
*/ */
@@ -387,7 +389,7 @@ class MigrateToGroups extends Command
if (null !== $category) { if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id)); 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: // try to get a category ID from the left transaction:
@@ -396,7 +398,7 @@ class MigrateToGroups extends Command
if (null !== $category) { if (null !== $category) {
Log::debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id)); 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'); 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 private function giveGroup(array $array): void
{ {

View File

@@ -33,6 +33,8 @@ use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class MigrateToRules * Class MigrateToRules
@@ -120,14 +122,14 @@ class MigrateToRules extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -136,7 +138,7 @@ class MigrateToRules extends Command
/** /**
* Migrate bills to new rule structure for a specific user. * Migrate bills to new rule structure for a specific user.
* *
* @param User $user * @param User $user
* *
* @throws FireflyException * @throws FireflyException
*/ */
@@ -148,14 +150,14 @@ class MigrateToRules extends Command
/** @var Preference $lang */ /** @var Preference $lang */
$lang = app('preferences')->getForUser($user, 'language', 'en_US'); $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); $ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle);
if (null === $ruleGroup) { if (null === $ruleGroup) {
$ruleGroup = $this->ruleGroupRepository->store( $ruleGroup = $this->ruleGroupRepository->store(
[ [
'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $lang->data), 'title' => (string)trans('firefly.rulegroup_for_bills_title', [], $lang->data),
'description' => (string) trans('firefly.rulegroup_for_bills_description', [], $lang->data), 'description' => (string)trans('firefly.rulegroup_for_bills_description', [], $lang->data),
'active' => true, 'active' => true,
] ]
); );
@@ -169,9 +171,9 @@ class MigrateToRules extends Command
} }
/** /**
* @param RuleGroup $ruleGroup * @param RuleGroup $ruleGroup
* @param Bill $bill * @param Bill $bill
* @param Preference $language * @param Preference $language
*/ */
private function migrateBill(RuleGroup $ruleGroup, Bill $bill, Preference $language): void private function migrateBill(RuleGroup $ruleGroup, Bill $bill, Preference $language): void
{ {
@@ -186,8 +188,8 @@ class MigrateToRules extends Command
'active' => true, 'active' => true,
'strict' => false, 'strict' => false,
'stop_processing' => false, // field is no longer used. 'stop_processing' => false, // field is no longer used.
'title' => (string) trans('firefly.rule_for_bill_title', ['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), 'description' => (string)trans('firefly.rule_for_bill_description', ['name' => $bill->name], $language->data),
'trigger' => 'store-journal', 'trigger' => 'store-journal',
'triggers' => [ 'triggers' => [
[ [

View File

@@ -35,6 +35,8 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface; use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class OtherCurrenciesCorrections * Class OtherCurrenciesCorrections
@@ -115,14 +117,14 @@ class OtherCurrenciesCorrections extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -147,7 +149,7 @@ class OtherCurrenciesCorrections extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
*/ */
private function updateJournalCurrency(TransactionJournal $journal): void private function updateJournalCurrency(TransactionJournal $journal): void
{ {
@@ -188,8 +190,8 @@ class OtherCurrenciesCorrections extends Command
} }
// when mismatch in transaction: // when mismatch in transaction:
if ((int) $transaction->transaction_currency_id !== (int) $currency->id) { if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {
$transaction->foreign_currency_id = (int) $transaction->transaction_currency_id; $transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;
$transaction->foreign_amount = $transaction->amount; $transaction->foreign_amount = $transaction->amount;
$transaction->transaction_currency_id = $currency->id; $transaction->transaction_currency_id = $currency->id;
$transaction->save(); $transaction->save();
@@ -206,7 +208,7 @@ class OtherCurrenciesCorrections extends Command
* Gets the transaction that determines the transaction that "leads" and will determine * Gets the transaction that determines the transaction that "leads" and will determine
* the currency to be used by all transactions, and the journal itself. * the currency to be used by all transactions, and the journal itself.
* *
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Transaction|null * @return Transaction|null
*/ */
@@ -247,7 +249,7 @@ class OtherCurrenciesCorrections extends Command
} }
/** /**
* @param Account $account * @param Account $account
* *
* @return TransactionCurrency|null * @return TransactionCurrency|null
*/ */

View File

@@ -26,6 +26,8 @@ namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class RenameAccountMeta * Class RenameAccountMeta
@@ -99,14 +101,14 @@ class RenameAccountMeta extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;

View File

@@ -31,6 +31,8 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Schema; use Schema;
/** /**
@@ -123,14 +125,14 @@ class TransactionIdentifier extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; 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 * 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. * which has 0 as an identifier and give it the same identifier.
* *
* @param TransactionJournal $transactionJournal * @param TransactionJournal $transactionJournal
*/ */
private function updateJournalIdentifiers(TransactionJournal $transactionJournal): void private function updateJournalIdentifiers(TransactionJournal $transactionJournal): void
{ {
@@ -166,15 +168,15 @@ class TransactionIdentifier extends Command
} }
/** /**
* @param Transaction $transaction * @param Transaction $transaction
* @param array $exclude * @param array $exclude
* *
* @return Transaction|null * @return Transaction|null
*/ */
private function findOpposing(Transaction $transaction, array $exclude): ?Transaction private function findOpposing(Transaction $transaction, array $exclude): ?Transaction
{ {
// find opposing: // find opposing:
$amount = bcmul((string) $transaction->amount, '-1'); $amount = bcmul((string)$transaction->amount, '-1');
try { try {
/** @var Transaction $opposing */ /** @var Transaction $opposing */

View File

@@ -33,6 +33,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface; use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class TransferCurrenciesCorrections * Class TransferCurrenciesCorrections
@@ -69,8 +71,8 @@ class TransferCurrenciesCorrections extends Command
* *
* @return int * @return int
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
public function handle(): int public function handle(): int
{ {
@@ -137,14 +139,14 @@ class TransferCurrenciesCorrections extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -168,7 +170,7 @@ class TransferCurrenciesCorrections extends Command
} }
/** /**
* @param TransactionJournal $transfer * @param TransactionJournal $transfer
*/ */
private function updateTransferCurrency(TransactionJournal $transfer): void private function updateTransferCurrency(TransactionJournal $transfer): void
{ {
@@ -233,7 +235,7 @@ class TransferCurrenciesCorrections extends Command
/** /**
* Is this a split transaction journal? * Is this a split transaction journal?
* *
* @param TransactionJournal $transfer * @param TransactionJournal $transfer
* *
* @return bool * @return bool
* @codeCoverageIgnore * @codeCoverageIgnore
@@ -246,7 +248,7 @@ class TransferCurrenciesCorrections extends Command
/** /**
* Extract source transaction, source account + source account currency from the journal. * Extract source transaction, source account + source account currency from the journal.
* *
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
@@ -258,7 +260,7 @@ class TransferCurrenciesCorrections extends Command
} }
/** /**
* @param TransactionJournal $transfer * @param TransactionJournal $transfer
* *
* @return Transaction|null * @return Transaction|null
* @codeCoverageIgnore * @codeCoverageIgnore
@@ -269,7 +271,7 @@ class TransferCurrenciesCorrections extends Command
} }
/** /**
* @param Account $account * @param Account $account
* *
* @return TransactionCurrency|null * @return TransactionCurrency|null
*/ */
@@ -296,7 +298,7 @@ class TransferCurrenciesCorrections extends Command
/** /**
* Extract destination transaction, destination account + destination account currency from the journal. * Extract destination transaction, destination account + destination account currency from the journal.
* *
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
@@ -308,7 +310,7 @@ class TransferCurrenciesCorrections extends Command
} }
/** /**
* @param TransactionJournal $transfer * @param TransactionJournal $transfer
* *
* @return Transaction|null * @return Transaction|null
* @codeCoverageIgnore * @codeCoverageIgnore
@@ -371,7 +373,7 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) { if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
$this->sourceTransaction $this->sourceTransaction
->transaction_currency_id ->transaction_currency_id
= (int) $this->sourceCurrency->id; = (int)$this->sourceCurrency->id;
$message = sprintf( $message = sprintf(
'Transaction #%d has no currency setting, now set to %s.', 'Transaction #%d has no currency setting, now set to %s.',
$this->sourceTransaction->id, $this->sourceTransaction->id,
@@ -392,7 +394,7 @@ class TransferCurrenciesCorrections extends Command
{ {
if (null !== $this->sourceCurrency if (null !== $this->sourceCurrency
&& null === $this->sourceTransaction->foreign_amount && 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( $message = sprintf(
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.', '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); Log::debug($message);
$this->line($message); $this->line($message);
$this->count++; $this->count++;
$this->sourceTransaction->transaction_currency_id = (int) $this->sourceCurrency->id; $this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id;
$this->sourceTransaction->save(); $this->sourceTransaction->save();
} }
} }
@@ -418,7 +420,7 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) { if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
$this->destinationTransaction $this->destinationTransaction
->transaction_currency_id ->transaction_currency_id
= (int) $this->destinationCurrency->id; = (int)$this->destinationCurrency->id;
$message = sprintf( $message = sprintf(
'Transaction #%d has no currency setting, now set to %s.', 'Transaction #%d has no currency setting, now set to %s.',
$this->destinationTransaction->id, $this->destinationTransaction->id,
@@ -439,7 +441,7 @@ class TransferCurrenciesCorrections extends Command
{ {
if (null !== $this->destinationCurrency if (null !== $this->destinationCurrency
&& null === $this->destinationTransaction->foreign_amount && 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( $message = sprintf(
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.', '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); Log::debug($message);
$this->line($message); $this->line($message);
$this->count++; $this->count++;
$this->destinationTransaction->transaction_currency_id = (int) $this->destinationCurrency->id; $this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id;
$this->destinationTransaction->save(); $this->destinationTransaction->save();
} }
} }
@@ -463,7 +465,7 @@ class TransferCurrenciesCorrections extends Command
*/ */
private function fixInvalidForeignCurrency(): void 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: // update both transactions to match:
$this->sourceTransaction->foreign_amount = null; $this->sourceTransaction->foreign_amount = null;
$this->sourceTransaction->foreign_currency_id = null; $this->sourceTransaction->foreign_currency_id = null;
@@ -497,7 +499,7 @@ class TransferCurrenciesCorrections extends Command
*/ */
private function fixMismatchedForeignCurrency(): void 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->transaction_currency_id = $this->sourceCurrency->id;
$this->sourceTransaction->foreign_currency_id = $this->destinationCurrency->id; $this->sourceTransaction->foreign_currency_id = $this->destinationCurrency->id;
$this->destinationTransaction->transaction_currency_id = $this->sourceCurrency->id; $this->destinationTransaction->transaction_currency_id = $this->sourceCurrency->id;
@@ -517,7 +519,7 @@ class TransferCurrenciesCorrections extends Command
private function fixSourceNullForeignAmount(): void private function fixSourceNullForeignAmount(): void
{ {
if (null === $this->sourceTransaction->foreign_amount && null !== $this->destinationTransaction->foreign_amount) { 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->sourceTransaction->save();
$this->count++; $this->count++;
Log::debug( Log::debug(
@@ -537,7 +539,7 @@ class TransferCurrenciesCorrections extends Command
private function fixDestNullForeignAmount(): void private function fixDestNullForeignAmount(): void
{ {
if (null === $this->destinationTransaction->foreign_amount && null !== $this->sourceTransaction->foreign_amount) { 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->destinationTransaction->save();
$this->count++; $this->count++;
Log::debug( 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. * 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 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)'; $oldCurrencyCode = $journal->transactionCurrency->code ?? '(nothing)';
$journal->transaction_currency_id = $this->sourceCurrency->id; $journal->transaction_currency_id = $this->sourceCurrency->id;
$message = sprintf( $message = sprintf(

View File

@@ -121,9 +121,9 @@ class UpgradeDatabase extends Command
echo $result; echo $result;
} }
// set new DB version. // 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. // 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; return 0;
} }

View File

@@ -34,6 +34,8 @@ use FireflyIII\Services\Internal\Support\CreditRecalculateService;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Log; use Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class UpgradeLiabilities * Class UpgradeLiabilities
@@ -81,14 +83,14 @@ class UpgradeLiabilities extends Command
/** /**
* @return bool * @return bool
* @throws FireflyException * @throws FireflyException
* @throws \Psr\Container\ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { if (null !== $configVar) {
return (bool) $configVar->data; return (bool)$configVar->data;
} }
return false; return false;
@@ -108,7 +110,7 @@ class UpgradeLiabilities extends Command
} }
/** /**
* @param User $user * @param User $user
*/ */
private function upgradeForUser(User $user): void 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 private function upgradeLiability(Account $account): void
{ {
@@ -150,8 +152,8 @@ class UpgradeLiabilities extends Command
} }
/** /**
* @param Account $account * @param Account $account
* @param TransactionJournal $openingBalance * @param TransactionJournal $openingBalance
*/ */
private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void
{ {
@@ -161,10 +163,10 @@ class UpgradeLiabilities extends Command
return; return;
} }
// source MUST be the liability. // 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)); Log::debug(sprintf('Must switch around, because account #%d is the destination.', $destination->account_id));
// so if not, switch things around: // so if not, switch things around:
$sourceAccountId = (int) $source->account_id; $sourceAccountId = (int)$source->account_id;
$source->account_id = $destination->account_id; $source->account_id = $destination->account_id;
$destination->account_id = $sourceAccountId; $destination->account_id = $sourceAccountId;
$source->save(); $source->save();
@@ -175,7 +177,7 @@ class UpgradeLiabilities extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Transaction|null * @return Transaction|null
*/ */
@@ -185,7 +187,7 @@ class UpgradeLiabilities extends Command
} }
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
* *
* @return Transaction|null * @return Transaction|null
*/ */

View File

@@ -54,10 +54,10 @@ class UpgradeFireflyInstructions extends Command
public function handle(): int public function handle(): int
{ {
$this->generateInstallationId(); $this->generateInstallationId();
if ('update' === (string) $this->argument('task')) { if ('update' === (string)$this->argument('task')) {
$this->updateInstructions(); $this->updateInstructions();
} }
if ('install' === (string) $this->argument('task')) { if ('install' === (string)$this->argument('task')) {
$this->installInstructions(); $this->installInstructions();
} }
@@ -112,26 +112,26 @@ class UpgradeFireflyInstructions extends Command
/** /**
* Show a nice box. * Show a nice box.
* *
* @param string $text * @param string $text
*/ */
private function boxed(string $text): void private function boxed(string $text): void
{ {
$parts = explode("\n", wordwrap($text)); $parts = explode("\n", wordwrap($text));
foreach ($parts as $string) { foreach ($parts as $string) {
$this->line('| ' . sprintf('%-77s', $string) . '|'); $this->line('| '.sprintf('%-77s', $string).'|');
} }
} }
/** /**
* Show a nice info box. * Show a nice info box.
* *
* @param string $text * @param string $text
*/ */
private function boxedInfo(string $text): void private function boxedInfo(string $text): void
{ {
$parts = explode("\n", wordwrap($text)); $parts = explode("\n", wordwrap($text));
foreach ($parts as $string) { foreach ($parts as $string) {
$this->info('| ' . sprintf('%-77s', $string) . '|'); $this->info('| '.sprintf('%-77s', $string).'|');
} }
} }

View File

@@ -43,7 +43,7 @@ trait VerifiesAccessToken
*/ */
public function getUser(): User public function getUser(): User
{ {
$userId = (int) $this->option('user'); $userId = (int)$this->option('user');
/** @var UserRepositoryInterface $repository */ /** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class); $repository = app(UserRepositoryInterface::class);
$user = $repository->find($userId); $user = $repository->find($userId);
@@ -57,7 +57,7 @@ trait VerifiesAccessToken
/** /**
* Abstract method to make sure trait knows about method "option". * Abstract method to make sure trait knows about method "option".
* *
* @param string|null $key * @param string|null $key
* *
* @return mixed * @return mixed
*/ */
@@ -71,8 +71,8 @@ trait VerifiesAccessToken
*/ */
protected function verifyAccessToken(): bool protected function verifyAccessToken(): bool
{ {
$userId = (int) $this->option('user'); $userId = (int)$this->option('user');
$token = (string) $this->option('token'); $token = (string)$this->option('token');
/** @var UserRepositoryInterface $repository */ /** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class); $repository = app(UserRepositoryInterface::class);
$user = $repository->find($userId); $user = $repository->find($userId);

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands; namespace FireflyIII\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use League\Flysystem\FilesystemException;
use Log; use Log;
use Storage; use Storage;
@@ -50,7 +51,7 @@ class VerifySecurityAlerts extends Command
* Execute the console command. * Execute the console command.
* *
* @return int * @return int
* @throws \League\Flysystem\FilesystemException * @throws FilesystemException
*/ */
public function handle(): int public function handle(): int
{ {