Update some code style

This commit is contained in:
James Cole
2020-07-31 15:12:26 +02:00
parent c3d8d70b34
commit e46958c23e
11 changed files with 51 additions and 117 deletions

View File

@@ -5,7 +5,9 @@ includes:
- ../vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon - ../vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
parameters: parameters:
ignoreErrors:
- '#is not allowed to extend#'
- '#is neither abstract nor final#'
paths: paths:
- ../app - ../app
- ../config - ../config
@@ -15,5 +17,6 @@ parameters:
- ../tests - ../tests
- ../bootstrap/app.php - ../bootstrap/app.php
# The level 8 is the highest level
level: 5 # The level 8 is the highest level. original was 5
level: 0

View File

@@ -210,7 +210,7 @@ class AccountController extends Controller
while ($currentStart <= $end) { while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d'); $format = $currentStart->format('Y-m-d');
$label = $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; $previous = $balance;
$currentStart->addDay(); $currentStart->addDay();
$currentSet['entries'][$label] = $balance; $currentSet['entries'][$label] = $balance;

View File

@@ -40,12 +40,11 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Controller extends BaseController abstract class Controller extends BaseController
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
/** @var ParameterBag Parameters from the URI are stored here. */ protected ParameterBag $parameters;
protected $parameters;
/** /**

View File

@@ -39,20 +39,17 @@ class FixAccountTypes extends Command
{ {
/** /**
* The console command description. * The console command description.
*
* @var string * @var string
*/ */
protected $description = 'Make sure all journals have the correct from/to account types.'; protected $description = 'Make sure all journals have the correct from/to account types.';
/** /**
* The name and signature of the console command. * The name and signature of the console command.
*
* @var string * @var string
*/ */
protected $signature = 'firefly-iii:fix-account-types'; protected $signature = 'firefly-iii:fix-account-types';
/** @var int */ /** @var int */
private $count; private $count;
/** @var array */ private array $expected;
private $expected;
/** @var AccountFactory */ /** @var AccountFactory */
private $factory; private $factory;
/** @var array */ /** @var array */
@@ -61,9 +58,8 @@ class FixAccountTypes extends Command
/** /**
* Execute the console command. * Execute the console command.
*
* @throws FireflyException
* @return int * @return int
* @throws FireflyException
*/ */
public function handle(): int public function handle(): int
{ {
@@ -72,21 +68,14 @@ class FixAccountTypes extends Command
$start = microtime(true); $start = microtime(true);
$this->factory = app(AccountFactory::class); $this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script: // some combinations can be fixed by this script:
$this->fixable = [ $this->fixable = [// transfers from asset to liability and vice versa
// 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),
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. // withdrawals with a revenue account as destination instead of an expense account.
sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE), sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
// deposits with an expense account as source instead of a revenue account. // deposits with an expense account as source instead of a revenue account.
sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET), sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),];
];
$this->expected = config('firefly.source_dests'); $this->expected = config('firefly.source_dests');
@@ -115,7 +104,6 @@ class FixAccountTypes extends Command
* @param string $type * @param string $type
* @param Transaction $source * @param Transaction $source
* @param Transaction $dest * @param Transaction $dest
*
* @throws FireflyException * @throws FireflyException
*/ */
private function fixJournal(TransactionJournal $journal, string $type, Transaction $source, Transaction $dest): void 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); $result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE);
$dest->account()->associate($result); $dest->account()->associate($result);
$dest->save(); $dest->save();
$this->info( $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));
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); $this->inspectJournal($journal);
break; break;
case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET): case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET):
@@ -175,16 +154,7 @@ class FixAccountTypes extends Command
$oldSource = $dest->account; $oldSource = $dest->account;
$source->account()->associate($result); $source->account()->associate($result);
$source->save(); $source->save();
$this->info( $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));
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); $this->inspectJournal($journal);
break; break;
default: default:
@@ -198,7 +168,6 @@ class FixAccountTypes extends Command
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
*
* @return Transaction * @return Transaction
*/ */
private function getDestinationTransaction(TransactionJournal $journal): Transaction private function getDestinationTransaction(TransactionJournal $journal): Transaction
@@ -208,7 +177,6 @@ class FixAccountTypes extends Command
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
*
* @return Transaction * @return Transaction
*/ */
private function getSourceTransaction(TransactionJournal $journal): Transaction private function getSourceTransaction(TransactionJournal $journal): Transaction
@@ -218,7 +186,6 @@ class FixAccountTypes extends Command
/** /**
* @param TransactionJournal $journal * @param TransactionJournal $journal
*
* @throws FireflyException * @throws FireflyException
*/ */
private function inspectJournal(TransactionJournal $journal): void private function inspectJournal(TransactionJournal $journal): void
@@ -250,7 +217,7 @@ class FixAccountTypes extends Command
$destAccount = $destTransaction->account; $destAccount = $destTransaction->account;
$destAccountType = $destAccount->accountType->type; $destAccountType = $destAccount->accountType->type;
if (!isset($this->expected[$type])) { if (!array_key_exists($type, $this->expected)) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
Log::info(sprintf('No source/destination info for transaction type %s.', $type)); Log::info(sprintf('No source/destination info for transaction type %s.', $type));
$this->info(sprintf('No source/destination info for transaction type %s.', $type)); $this->info(sprintf('No source/destination info for transaction type %s.', $type));
@@ -258,7 +225,7 @@ class FixAccountTypes extends Command
return; return;
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
if (!isset($this->expected[$type][$sourceAccountType])) { if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction); $this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return; return;
@@ -273,7 +240,6 @@ class FixAccountTypes extends Command
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * 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 * 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. * be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
private function stupidLaravel(): void private function stupidLaravel(): void

View File

@@ -43,13 +43,11 @@ class OtherCurrenciesCorrections extends Command
public const CONFIG_NAME = '480_other_currencies'; public const CONFIG_NAME = '480_other_currencies';
/** /**
* The console command description. * The console command description.
*
* @var string * @var string
*/ */
protected $description = 'Update all journal currency information.'; protected $description = 'Update all journal currency information.';
/** /**
* The name and signature of the console command. * The name and signature of the console command.
*
* @var string * @var string
*/ */
protected $signature = 'firefly-iii:other-currencies {--F|force : Force the execution of this command.}'; 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. * Execute the console command.
*
* @return int * @return int
*/ */
public function handle(): int public function handle(): int
@@ -96,13 +93,12 @@ class OtherCurrenciesCorrections extends Command
/** /**
* @param Account $account * @param Account $account
*
* @return TransactionCurrency|null * @return TransactionCurrency|null
*/ */
private function getCurrency(Account $account): ?TransactionCurrency private function getCurrency(Account $account): ?TransactionCurrency
{ {
$accountId = $account->id; $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 return null; // @codeCoverageIgnore
} }
if (isset($this->accountCurrencies[$accountId]) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) { 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 * 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
*/ */
private function getLeadTransaction(TransactionJournal $journal): ?Transaction private function getLeadTransaction(TransactionJournal $journal): ?Transaction
@@ -142,19 +136,11 @@ class OtherCurrenciesCorrections extends Command
break; break;
case TransactionType::OPENING_BALANCE: case TransactionType::OPENING_BALANCE:
// whichever isn't an initial balance account: // whichever isn't an initial balance account:
$lead = $journal->transactions() $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.*']);
->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; break;
case TransactionType::RECONCILIATION: case TransactionType::RECONCILIATION:
// whichever isn't the reconciliation account: // whichever isn't the reconciliation account:
$lead = $journal->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.*']);
->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; break;
} }
@@ -186,7 +172,6 @@ class OtherCurrenciesCorrections extends Command
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is * 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 * 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. * be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
private function stupidLaravel(): void private function stupidLaravel(): void
@@ -224,22 +209,14 @@ class OtherCurrenciesCorrections extends Command
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
if (null === $currency) { if (null === $currency) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$this->error( $this->error(sprintf('Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', $account->id, $account->name, $journal->id));
sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
$account->id,
$account->name,
$journal->id
)
);
$this->count++; $this->count++;
return; return;
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
// fix each transaction: // fix each transaction:
$journal->transactions->each( $journal->transactions->each(static function (Transaction $transaction) use ($currency) {
static function (Transaction $transaction) use ($currency) {
if (null === $transaction->transaction_currency_id) { if (null === $transaction->transaction_currency_id) {
$transaction->transaction_currency_id = $currency->id; $transaction->transaction_currency_id = $currency->id;
$transaction->save(); $transaction->save();
@@ -252,8 +229,7 @@ class OtherCurrenciesCorrections extends Command
$transaction->transaction_currency_id = $currency->id; $transaction->transaction_currency_id = $currency->id;
$transaction->save(); $transaction->save();
} }
} });
);
// also update the journal, of course: // also update the journal, of course:
$journal->transaction_currency_id = $currency->id; $journal->transaction_currency_id = $currency->id;
$this->count++; $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 * This routine verifies that withdrawals, deposits and opening balances have the correct currency settings for
* the accounts they are linked to. * the accounts they are linked to.
*
* Both source and destination must match the respective currency preference of the related asset account. * Both source and destination must match the respective currency preference of the related asset account.
* So FF3 must verify all transactions. * So FF3 must verify all transactions.
*/ */
private function updateOtherJournalsCurrencies(): void private function updateOtherJournalsCurrencies(): void
{ {
$set $set = $this->cliRepos->getAllJournals([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]);
= $this->cliRepos->getAllJournals(
[
TransactionType::WITHDRAWAL,
TransactionType::DEPOSIT,
TransactionType::OPENING_BALANCE,
TransactionType::RECONCILIATION,
]
);
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
foreach ($set as $journal) { foreach ($set as $journal) {

View File

@@ -34,7 +34,7 @@ use Route;
* Class Controller. * Class Controller.
* *
*/ */
class Controller extends BaseController abstract class Controller extends BaseController
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation, RequestInformation; use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation, RequestInformation;

View File

@@ -135,7 +135,8 @@ class Telemetry
->where('key', $key) ->where('key', $key)
->where('value', $jsonEncoded) ->where('value', $jsonEncoded)
->count(); ->count();
} catch (QueryException|Exception $e) { } catch (QueryException $e) {
Log::info(sprintf('Could not execute hasEntry() but this is OK: %s', $e->getMessage()));
$count = 0; $count = 0;
} }
@@ -188,8 +189,8 @@ class Telemetry
'value' => $value, 'value' => $value,
] ]
); );
} catch (QueryException|Exception $e) { } catch (QueryException $e) {
// ignore. Log::info(sprintf('Could not execute storeEntry() but this is OK: %s', $e->getMessage()));
} }
} }
} }

View File

@@ -31,7 +31,7 @@ use FireflyIII\Models\TransactionJournal;
* Class AbstractTrigger * Class AbstractTrigger
* @method bool triggered($object) * @method bool triggered($object)
*/ */
class AbstractTrigger abstract class AbstractTrigger
{ {
/** @var bool Whether to stop processing after this one is checked. */ /** @var bool Whether to stop processing after this one is checked. */
public $stopProcessing; public $stopProcessing;

View File

@@ -30,10 +30,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
* *
* Class AbstractTransformer * Class AbstractTransformer
*/ */
class AbstractTransformer extends TransformerAbstract abstract class AbstractTransformer extends TransformerAbstract
{ {
/** @var ParameterBag */ protected ParameterBag $parameters;
protected $parameters;
/** /**
* @return ParameterBag * @return ParameterBag

View File

@@ -33,8 +33,7 @@ use Log;
*/ */
class AttachmentTransformer extends AbstractTransformer class AttachmentTransformer extends AbstractTransformer
{ {
/** @var AttachmentRepositoryInterface */ private AttachmentRepositoryInterface $repository;
private $repository;
/** /**
* BillTransformer constructor. * BillTransformer constructor.

View File

@@ -255,7 +255,7 @@ trait RecurrenceValidation
{ {
try { try {
Carbon::createFromFormat('Y-m-d', $moment); Carbon::createFromFormat('Y-m-d', $moment);
} catch (InvalidArgumentException|Exception $e) { } catch (InvalidArgumentException $e) {
Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage())); 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')); $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment'));
} }