Various code cleanup.

This commit is contained in:
James Cole
2023-12-22 20:12:38 +01:00
parent 067d160c13
commit 581e5d7330
69 changed files with 361 additions and 317 deletions

View File

@@ -88,6 +88,8 @@ trait AccountServiceTrait
/**
* Update metadata for account. Depends on type which fields are valid.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* TODO this method treats expense accounts and liabilities the same way (tries to save interest)
*/
public function updateMetaData(Account $account, array $data): void
@@ -336,7 +338,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function getCurrency(int $currencyId, string $currencyCode): TransactionCurrency
{
// find currency, or use default currency instead.
@@ -360,7 +362,7 @@ trait AccountServiceTrait
* Create the opposing "credit liability" transaction for credit liabilities.
*
* @throws FireflyException
* */
*/
protected function updateCreditTransaction(Account $account, string $direction, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -416,7 +418,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function createCreditTransaction(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug('Now going to create an createCreditTransaction.');
@@ -510,7 +512,7 @@ trait AccountServiceTrait
* Since opening balance and date can still be empty strings, it may fail.
*
* @throws FireflyException
* */
*/
protected function updateOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
@@ -566,7 +568,7 @@ trait AccountServiceTrait
/**
* @throws FireflyException
* */
*/
protected function createOBGroupV2(Account $account, string $openingBalance, Carbon $openingBalanceDate): TransactionGroup
{
app('log')->debug('Now going to create an OB group.');

View File

@@ -243,7 +243,11 @@ class CreditRecalculateService
}
/**
* A complex and long method, but rarely used luckily.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function processTransaction(Account $account, string $direction, Transaction $transaction, string $leftOfDebt): string
{

View File

@@ -87,7 +87,9 @@ trait RecurringTransactionTrait
* Store transactions of a recurring transactions. It's complex but readable.
*
* @throws FireflyException
* */
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function createTransactions(Recurrence $recurrence, array $transactions): void
{
app('log')->debug('Now in createTransactions()');
@@ -123,7 +125,7 @@ trait RecurringTransactionTrait
if (!$validator->validateDestination(['id' => $destination->id])) {
throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError));
}
if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) {
if (array_key_exists('foreign_amount', $array) && '' === (string) $array['foreign_amount']) {
unset($array['foreign_amount']);
}
// TODO typeOverrule. The account validator may have a different opinion on the type of the transaction.
@@ -135,25 +137,25 @@ trait RecurringTransactionTrait
'source_id' => $source->id,
'destination_id' => $destination->id,
'amount' => $array['amount'],
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string)$array['foreign_amount'] : null,
'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string) $array['foreign_amount'] : null,
'description' => $array['description'],
]
);
$transaction->save();
if (array_key_exists('budget_id', $array)) {
$this->setBudget($transaction, (int)$array['budget_id']);
$this->setBudget($transaction, (int) $array['budget_id']);
}
if (array_key_exists('bill_id', $array)) {
$this->setBill($transaction, (int)$array['bill_id']);
$this->setBill($transaction, (int) $array['bill_id']);
}
if (array_key_exists('category_id', $array)) {
$this->setCategory($transaction, (int)$array['category_id']);
$this->setCategory($transaction, (int) $array['category_id']);
}
// same for piggy bank
if (array_key_exists('piggy_bank_id', $array)) {
$this->updatePiggyBank($transaction, (int)$array['piggy_bank_id']);
$this->updatePiggyBank($transaction, (int) $array['piggy_bank_id']);
}
if (array_key_exists('tags', $array) && is_array($array['tags'])) {
@@ -165,8 +167,8 @@ trait RecurringTransactionTrait
protected function findAccount(array $expectedTypes, ?int $accountId, ?string $accountName): Account
{
$result = null;
$accountId = (int)$accountId;
$accountName = (string)$accountName;
$accountId = (int) $accountId;
$accountName = (string) $accountName;
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);