Clean up code and comments.

This commit is contained in:
James Cole
2023-02-22 18:14:14 +01:00
parent e6dc881f56
commit e421b29b01
249 changed files with 647 additions and 1044 deletions

View File

@@ -23,11 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use Exception;
use FireflyIII\Models\Bill;
/**
* Class BillDestroyService
*/
class BillDestroyService

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use DB;
use Exception;
use FireflyIII\Models\Budget;
/**

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use DB;
use Exception;
use FireflyIII\Models\Category;
/**

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Destroy;
use Exception;
use FireflyIII\Models\TransactionCurrency;
/**

View File

@@ -32,7 +32,6 @@ use FireflyIII\Models\TransactionJournalMeta;
use Log;
/**
* Class JournalDestroyService
*/
class JournalDestroyService

View File

@@ -27,7 +27,6 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceTransaction;
/**
* Class RecurrenceDestroyService
*/
class RecurrenceDestroyService

View File

@@ -164,7 +164,6 @@ trait AccountServiceTrait
* @param Account $account
* @param string $note
*
* @return bool
*/
public function updateNote(Account $account, string $note): bool

View File

@@ -331,7 +331,9 @@ class CreditRecalculateService
// in any other case, remove amount from left of debt.
if (in_array($type, [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER], true)) {
$newLeftOfDebt = bcadd($leftOfDebt, bcmul($usedAmount, '-1'));
Log::debug(sprintf('[5] Fallback: transaction is withdrawal/deposit/transfer, remove amount %s from left of debt, = %s.', $usedAmount, $newLeftOfDebt));
Log::debug(
sprintf('[5] Fallback: transaction is withdrawal/deposit/transfer, remove amount %s from left of debt, = %s.', $usedAmount, $newLeftOfDebt)
);
return $newLeftOfDebt;
}

View File

@@ -77,11 +77,11 @@ trait JournalServiceTrait
$result = $this->findAccountByNumber($result, $data, $expectedTypes[$transactionType]);
$numberResult = $result;
$result = $this->findAccountByName($result, $data, $expectedTypes[$transactionType]);
$nameResult =$result;
$nameResult = $result;
// if $result (find by name) is NULL, but IBAN is set, any result of the search by NAME can't overrule
// this account. In such a case, the name search must be retried with a new name.
if (null !== $nameResult && null === $numberResult && null === $ibanResult && '' !== (string)$data['iban'] && '' !== (string) $nameResult->iban) {
if (null !== $nameResult && null === $numberResult && null === $ibanResult && '' !== (string)$data['iban'] && '' !== (string)$nameResult->iban) {
$data['name'] = sprintf('%s (%s)', $data['name'], $data['iban']);
Log::debug(sprintf('Search again using the new name, "%s".', $data['name']));
$result = $this->findAccountByName(null, $data, $expectedTypes[$transactionType]);

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\BillFactory;

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\Location;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\AccountServiceTrait;
use FireflyIII\User;
use JsonException;
use Log;
/**
@@ -70,7 +71,7 @@ class AccountUpdateService
*
* @return Account
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
public function update(Account $account, array $data): Account
{
@@ -301,7 +302,9 @@ class AccountUpdateService
// if liability, make sure the amount is positive for a credit, and negative for a debit.
if ($this->isLiability($account)) {
$openingBalance = 'credit' === $data['liability_direction'] ? app('steam')->positive($openingBalance) : app('steam')->negative($openingBalance);
$openingBalance = 'credit' === $data['liability_direction'] ? app('steam')->positive($openingBalance) : app('steam')->negative(
$openingBalance
);
}
$this->updateOBGroupV2($account, $openingBalance, $openingBalanceDate);
@@ -317,37 +320,6 @@ class AccountUpdateService
}
}
/**
* @param Account $account
* @param array $data
*
* @throws FireflyException
* @deprecated In Firefly III v5.8.0 and onwards, credit transactions for liabilities are no longer created.
*/
private function updateCreditLiability(Account $account, array $data): void
{
$type = $account->accountType;
$valid = config('firefly.valid_liabilities');
if (in_array($type->type, $valid, true)) {
$direction = array_key_exists('liability_direction', $data) ? $data['liability_direction'] : 'empty';
// check if is submitted as empty, that makes it valid:
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
$openingBalance = $data['opening_balance'];
$openingBalanceDate = $data['opening_balance_date'];
if ('credit' === $direction) {
$this->updateCreditTransaction($account, $direction, $openingBalance, $openingBalanceDate);
}
}
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
$this->deleteCreditTransaction($account);
}
if ($this->validOBData($data) && !$this->isEmptyOBData($data) && 'credit' !== $direction) {
$this->deleteCreditTransaction($account);
}
}
}
/**
* @param Account $account
*
@@ -377,4 +349,35 @@ class AccountUpdateService
Log::debug('Final new array is', $new);
app('preferences')->setForUser($account->user, 'frontpageAccounts', $new);
}
/**
* @param Account $account
* @param array $data
*
* @throws FireflyException
* @deprecated In Firefly III v5.8.0 and onwards, credit transactions for liabilities are no longer created.
*/
private function updateCreditLiability(Account $account, array $data): void
{
$type = $account->accountType;
$valid = config('firefly.valid_liabilities');
if (in_array($type->type, $valid, true)) {
$direction = array_key_exists('liability_direction', $data) ? $data['liability_direction'] : 'empty';
// check if is submitted as empty, that makes it valid:
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
$openingBalance = $data['opening_balance'];
$openingBalanceDate = $data['opening_balance_date'];
if ('credit' === $direction) {
$this->updateCreditTransaction($account, $direction, $openingBalance, $openingBalanceDate);
}
}
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
$this->deleteCreditTransaction($account);
}
if ($this->validOBData($data) && !$this->isEmptyOBData($data) && 'credit' !== $direction) {
$this->deleteCreditTransaction($account);
}
}
}
}

View File

@@ -37,7 +37,6 @@ use JsonException;
use Log;
/**
* Class BillUpdateService
*/
class BillUpdateService

View File

@@ -53,11 +53,11 @@ class CurrencyUpdateService
}
if (array_key_exists('enabled', $data) && is_bool($data['enabled'])) {
$currency->enabled = (bool) $data['enabled'];
$currency->enabled = (bool)$data['enabled'];
}
if (array_key_exists('decimal_places', $data) && is_int($data['decimal_places'])) {
$currency->decimal_places = (int) $data['decimal_places'];
$currency->decimal_places = (int)$data['decimal_places'];
}
$currency->save();

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use Carbon\Carbon;
use FireflyIII\Factory\PiggyBankEventFactory;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;

View File

@@ -25,7 +25,6 @@ namespace FireflyIII\Services\Internal\Update;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TagFactory;
use FireflyIII\Factory\TransactionJournalMetaFactory;

View File

@@ -32,6 +32,7 @@ use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
use FireflyIII\User;
use JsonException;
use Log;
/**
@@ -217,7 +218,7 @@ class RecurrenceUpdateService
* @param array $transactions
*
* @throws FireflyException
* @throws \JsonException
* @throws JsonException
*/
private function updateTransactions(Recurrence $recurrence, array $transactions): void
{