Skip to content

Firefly III: a personal finances manager

Update some code style

James Colee46958c23e10
diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon
index 87bc120a54..2aeb078212 100644
--- a/.ci/phpstan.neon
+++ b/.ci/phpstan.neon
@@ -5,7 +5,9 @@ includes:
- ../vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
parameters:
-
+ ignoreErrors:
+ - '#is not allowed to extend#'
+ - '#is neither abstract nor final#'
paths:
- ../app
- ../config
@@ -15,5 +17,6 @@ parameters:
- ../tests
- ../bootstrap/app.php
- # The level 8 is the highest level
- level: 5
+
+ # The level 8 is the highest level. original was 5
+ level: 0
diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.php
index d76ef86475..edebaaf010 100644
--- a/app/Api/V1/Controllers/Chart/AccountController.php
+++ b/app/Api/V1/Controllers/Chart/AccountController.php
@@ -210,7 +210,7 @@ class AccountController extends Controller
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->format('Y-m-d');
- $balance = isset($range[$format]) ? round($range[$format], 12) : $previous;
+ $balance = array_key_exists($format, $range) ? round($range[$format], 12) : $previous;
$previous = $balance;
$currentStart->addDay();
$currentSet['entries'][$label] = $balance;
diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.php
index 856861dcea..1101011c9e 100644
--- a/app/Api/V1/Controllers/Controller.php
+++ b/app/Api/V1/Controllers/Controller.php
@@ -40,12 +40,11 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*
* @codeCoverageIgnore
*/
-class Controller extends BaseController
+abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
- /** @var ParameterBag Parameters from the URI are stored here. */
- protected $parameters;
+ protected ParameterBag $parameters;
/**
diff --git a/app/Console/Commands/Correction/FixAccountTypes.php b/app/Console/Commands/Correction/FixAccountTypes.php
index dff350236b..cf7441d792 100644
--- a/app/Console/Commands/Correction/FixAccountTypes.php
+++ b/app/Console/Commands/Correction/FixAccountTypes.php
@@ -39,20 +39,17 @@ class FixAccountTypes extends Command
{
/**
* The console command description.
- *
* @var string
*/
protected $description = 'Make sure all journals have the correct from/to account types.';
/**
* The name and signature of the console command.
- *
* @var string
*/
protected $signature = 'firefly-iii:fix-account-types';
/** @var int */
- private $count;
- /** @var array */
- private $expected;
+ private $count;
+ private array $expected;
/** @var AccountFactory */
private $factory;
/** @var array */
@@ -61,9 +58,8 @@ class FixAccountTypes extends Command
/**
* Execute the console command.
- *
- * @throws FireflyException
* @return int
+ * @throws FireflyException
*/
public function handle(): int
{
@@ -72,21 +68,14 @@ class FixAccountTypes extends Command
$start = microtime(true);
$this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script:
- $this->fixable = [
- // transfers from asset to liability and vice versa
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN),
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT),
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE),
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET),
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET),
- sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
+ $this->fixable = [// transfers from asset to liability and vice versa
+ sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
- // withdrawals with a revenue account as destination instead of an expense account.
- sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
+ // withdrawals with a revenue account as destination instead of an expense account.
+ sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
- // deposits with an expense account as source instead of a revenue account.
- sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),
- ];
+ // deposits with an expense account as source instead of a revenue account.
+ sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),];
$this->expected = config('firefly.source_dests');
@@ -115,7 +104,6 @@ class FixAccountTypes extends Command
* @param string $type
* @param Transaction $source
* @param Transaction $dest
- *
* @throws FireflyException
*/
private function fixJournal(TransactionJournal $journal, string $type, Transaction $source, Transaction $dest): void
@@ -155,16 +143,7 @@ class FixAccountTypes extends Command
$result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE);
$dest->account()->associate($result);
$dest->save();
- $this->info(
- sprintf(
- 'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").',
- $journal->id,
- $oldDest->id,
- $oldDest->name,
- $result->id,
- $result->name
- )
- );
+ $this->info(sprintf('Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldDest->id, $oldDest->name, $result->id, $result->name));
$this->inspectJournal($journal);
break;
case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET):
@@ -175,16 +154,7 @@ class FixAccountTypes extends Command
$oldSource = $dest->account;
$source->account()->associate($result);
$source->save();
- $this->info(
- sprintf(
- 'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").',
- $journal->id,
- $oldSource->id,
- $oldSource->name,
- $result->id,
- $result->name
- )
- );
+ $this->info(sprintf('Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id, $oldSource->id, $oldSource->name, $result->id, $result->name));
$this->inspectJournal($journal);
break;
default:
@@ -198,7 +168,6 @@ class FixAccountTypes extends Command
/**
* @param TransactionJournal $journal
- *
* @return Transaction
*/
private function getDestinationTransaction(TransactionJournal $journal): Transaction
@@ -208,7 +177,6 @@ class FixAccountTypes extends Command
/**
* @param TransactionJournal $journal
- *
* @return Transaction
*/
private function getSourceTransaction(TransactionJournal $journal): Transaction
@@ -218,7 +186,6 @@ class FixAccountTypes extends Command
/**
* @param TransactionJournal $journal
- *
* @throws FireflyException
*/
private function inspectJournal(TransactionJournal $journal): void
@@ -250,7 +217,7 @@ class FixAccountTypes extends Command
$destAccount = $destTransaction->account;
$destAccountType = $destAccount->accountType->type;
- if (!isset($this->expected[$type])) {
+ if (!array_key_exists($type, $this->expected)) {
// @codeCoverageIgnoreStart
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
@@ -258,7 +225,7 @@ class FixAccountTypes extends Command
return;
// @codeCoverageIgnoreEnd
}
- if (!isset($this->expected[$type][$sourceAccountType])) {
+ if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return;
@@ -273,7 +240,6 @@ class FixAccountTypes extends Command
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
- *
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
index ce2f40f6a6..c2f082b784 100644
--- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
+++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
@@ -43,13 +43,11 @@ class OtherCurrenciesCorrections extends Command
public const CONFIG_NAME = '480_other_currencies';
/**
* The console command description.
- *
* @var string
*/
protected $description = 'Update all journal currency information.';
/**
* The name and signature of the console command.
- *
* @var string
*/
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}';
@@ -69,7 +67,6 @@ class OtherCurrenciesCorrections extends Command
/**
* Execute the console command.
- *
* @return int
*/
public function handle(): int
@@ -96,13 +93,12 @@ class OtherCurrenciesCorrections extends Command
/**
* @param Account $account
- *
* @return TransactionCurrency|null
*/
private function getCurrency(Account $account): ?TransactionCurrency
{
$accountId = $account->id;
- if (isset($this->accountCurrencies[$accountId]) && 0 === $this->accountCurrencies[$accountId]) {
+ if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
return null; // @codeCoverageIgnore
}
if (isset($this->accountCurrencies[$accountId]) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
@@ -124,9 +120,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
- *
* @return Transaction|null
*/
private function getLeadTransaction(TransactionJournal $journal): ?Transaction
@@ -142,19 +136,11 @@ class OtherCurrenciesCorrections extends Command
break;
case TransactionType::OPENING_BALANCE:
// whichever isn't an initial balance account:
- $lead = $journal->transactions()
- ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
- ->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)
- ->first(['transactions.*']);
+ $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);
break;
case TransactionType::RECONCILIATION:
// whichever isn't the reconciliation account:
- $lead = $journal->transactions()
- ->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
- ->where('account_types.type', '!=', AccountType::RECONCILIATION)
- ->first(['transactions.*']);
+ $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);
break;
}
@@ -168,7 +154,7 @@ class OtherCurrenciesCorrections extends Command
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) {
- return (bool) $configVar->data;
+ return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
@@ -186,7 +172,6 @@ class OtherCurrenciesCorrections extends Command
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
- *
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
@@ -224,36 +209,27 @@ class OtherCurrenciesCorrections extends Command
$currency = $this->getCurrency($account);
if (null === $currency) {
// @codeCoverageIgnoreStart
- $this->error(
- sprintf(
- 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
- $account->id,
- $account->name,
- $journal->id
- )
- );
+ $this->error(sprintf('Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id));
$this->count++;
return;
// @codeCoverageIgnoreEnd
}
// fix each transaction:
- $journal->transactions->each(
- static function (Transaction $transaction) use ($currency) {
- if (null === $transaction->transaction_currency_id) {
- $transaction->transaction_currency_id = $currency->id;
- $transaction->save();
- }
+ $journal->transactions->each(static function (Transaction $transaction) use ($currency) {
+ if (null === $transaction->transaction_currency_id) {
+ $transaction->transaction_currency_id = $currency->id;
+ $transaction->save();
+ }
- // when mismatch in transaction:
- 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();
- }
+ // when mismatch in transaction:
+ 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();
}
- );
+ });
// also update the journal, of course:
$journal->transaction_currency_id = $currency->id;
$this->count++;
@@ -263,21 +239,12 @@ class OtherCurrenciesCorrections extends Command
/**
* This routine verifies that withdrawals, deposits and opening balances have the correct currency settings for
* the accounts they are linked to.
- *
* Both source and destination must match the respective currency preference of the related asset account.
* So FF3 must verify all transactions.
*/
private function updateOtherJournalsCurrencies(): void
{
- $set
- = $this->cliRepos->getAllJournals(
- [
- TransactionType::WITHDRAWAL,
- TransactionType::DEPOSIT,
- TransactionType::OPENING_BALANCE,
- TransactionType::RECONCILIATION,
- ]
- );
+ $set = $this->cliRepos->getAllJournals([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]);
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index 79434b738c..e54531f614 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -34,7 +34,7 @@ use Route;
* Class Controller.
*
*/
-class Controller extends BaseController
+abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation, RequestInformation;
diff --git a/app/Support/Telemetry.php b/app/Support/Telemetry.php
index 66c96015a6..e834fc5ec5 100644
--- a/app/Support/Telemetry.php
+++ b/app/Support/Telemetry.php
@@ -135,7 +135,8 @@ class Telemetry
->where('key', $key)
->where('value', $jsonEncoded)
->count();
- } catch (QueryException|Exception $e) {
+ } catch (QueryException $e) {
+ Log::info(sprintf('Could not execute hasEntry() but this is OK: %s', $e->getMessage()));
$count = 0;
}
@@ -188,8 +189,8 @@ class Telemetry
'value' => $value,
]
);
- } catch (QueryException|Exception $e) {
- // ignore.
+ } catch (QueryException $e) {
+ Log::info(sprintf('Could not execute storeEntry() but this is OK: %s', $e->getMessage()));
}
}
}
diff --git a/app/TransactionRules/Triggers/AbstractTrigger.php b/app/TransactionRules/Triggers/AbstractTrigger.php
index ef88a920b0..b24a19c8c5 100644
--- a/app/TransactionRules/Triggers/AbstractTrigger.php
+++ b/app/TransactionRules/Triggers/AbstractTrigger.php
@@ -31,7 +31,7 @@ use FireflyIII\Models\TransactionJournal;
* Class AbstractTrigger
* @method bool triggered($object)
*/
-class AbstractTrigger
+abstract class AbstractTrigger
{
/** @var bool Whether to stop processing after this one is checked. */
public $stopProcessing;
diff --git a/app/Transformers/AbstractTransformer.php b/app/Transformers/AbstractTransformer.php
index a791bd7592..fe4e8ec761 100644
--- a/app/Transformers/AbstractTransformer.php
+++ b/app/Transformers/AbstractTransformer.php
@@ -30,10 +30,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*
* Class AbstractTransformer
*/
-class AbstractTransformer extends TransformerAbstract
+abstract class AbstractTransformer extends TransformerAbstract
{
- /** @var ParameterBag */
- protected $parameters;
+ protected ParameterBag $parameters;
/**
* @return ParameterBag
diff --git a/app/Transformers/AttachmentTransformer.php b/app/Transformers/AttachmentTransformer.php
index b2ff1d8729..5dbe9193b0 100644
--- a/app/Transformers/AttachmentTransformer.php
+++ b/app/Transformers/AttachmentTransformer.php
@@ -33,8 +33,7 @@ use Log;
*/
class AttachmentTransformer extends AbstractTransformer
{
- /** @var AttachmentRepositoryInterface */
- private $repository;
+ private AttachmentRepositoryInterface $repository;
/**
* BillTransformer constructor.
diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php
index 602c08c4e8..d5f0c6eaae 100644
--- a/app/Validation/RecurrenceValidation.php
+++ b/app/Validation/RecurrenceValidation.php
@@ -255,7 +255,7 @@ trait RecurrenceValidation
{
try {
Carbon::createFromFormat('Y-m-d', $moment);
- } catch (InvalidArgumentException|Exception $e) {
+ } catch (InvalidArgumentException $e) {
Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage()));
$validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
}