mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Events\UpdatedAccount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -68,7 +69,7 @@ class AccountUpdateService
|
||||
*/
|
||||
public function update(Account $account, array $data): Account
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$this->accountRepository->setUser($account->user);
|
||||
$this->user = $account->user;
|
||||
$account = $this->updateAccount($account, $data);
|
||||
@@ -166,21 +167,21 @@ class AccountUpdateService
|
||||
{
|
||||
// skip if no order info
|
||||
if (!array_key_exists('order', $data) || $data['order'] === $account->order) {
|
||||
app('log')->debug(sprintf('Account order will not be touched because its not set or already at %d.', $account->order));
|
||||
Log::debug(sprintf('Account order will not be touched because its not set or already at %d.', $account->order));
|
||||
|
||||
return $account;
|
||||
}
|
||||
// skip if not of orderable type.
|
||||
$type = $account->accountType->type;
|
||||
if (!in_array($type, [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], true)) {
|
||||
app('log')->debug('Will not change order of this account.');
|
||||
Log::debug('Will not change order of this account.');
|
||||
|
||||
return $account;
|
||||
}
|
||||
// get account type ID's because a join and an update is hard:
|
||||
$oldOrder = $account->order;
|
||||
$newOrder = $data['order'];
|
||||
app('log')->debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
|
||||
Log::debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
|
||||
$list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
|
||||
if (AccountTypeEnum::ASSET->value === $type) {
|
||||
$list = $this->getTypeIds([AccountTypeEnum::ASSET->value]);
|
||||
@@ -193,7 +194,7 @@ class AccountUpdateService
|
||||
->decrement('order')
|
||||
;
|
||||
$account->order = $newOrder;
|
||||
app('log')->debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
Log::debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
$account->save();
|
||||
|
||||
return $account;
|
||||
@@ -205,7 +206,7 @@ class AccountUpdateService
|
||||
->increment('order')
|
||||
;
|
||||
$account->order = $newOrder;
|
||||
app('log')->debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
Log::debug(sprintf('Order of account #%d ("%s") is now %d', $account->id, $account->name, $newOrder));
|
||||
$account->save();
|
||||
|
||||
return $account;
|
||||
@@ -298,17 +299,17 @@ class AccountUpdateService
|
||||
if (!is_array($array)) {
|
||||
$array = [$array];
|
||||
}
|
||||
app('log')->debug('Old array is: ', $array);
|
||||
app('log')->debug(sprintf('Must remove : %d', $account->id));
|
||||
Log::debug('Old array is: ', $array);
|
||||
Log::debug(sprintf('Must remove : %d', $account->id));
|
||||
$removeAccountId = $account->id;
|
||||
$new = [];
|
||||
foreach ($array as $value) {
|
||||
if ((int) $value !== $removeAccountId) {
|
||||
app('log')->debug(sprintf('Will include: %d', $value));
|
||||
Log::debug(sprintf('Will include: %d', $value));
|
||||
$new[] = (int) $value;
|
||||
}
|
||||
}
|
||||
app('log')->debug('Final new array is', $new);
|
||||
Log::debug('Final new array is', $new);
|
||||
app('preferences')->setForUser($account->user, 'frontpageAccounts', $new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
@@ -193,18 +194,18 @@ class BillUpdateService
|
||||
|
||||
private function updateBillTriggers(Bill $bill, array $oldData, array $newData): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in updateBillTriggers(%d, "%s")', $bill->id, $bill->name));
|
||||
Log::debug(sprintf('Now in updateBillTriggers(%d, "%s")', $bill->id, $bill->name));
|
||||
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($bill->user);
|
||||
$rules = $repository->getRulesForBill($bill);
|
||||
if (0 === $rules->count()) {
|
||||
app('log')->debug('Found no rules.');
|
||||
Log::debug('Found no rules.');
|
||||
|
||||
return;
|
||||
}
|
||||
app('log')->debug(sprintf('Found %d rules', $rules->count()));
|
||||
Log::debug(sprintf('Found %d rules', $rules->count()));
|
||||
$fields = [
|
||||
'name' => 'description_contains',
|
||||
'amount_min' => 'amount_more',
|
||||
@@ -216,7 +217,7 @@ class BillUpdateService
|
||||
continue;
|
||||
}
|
||||
if ($oldData[$field] === $newData[$field]) {
|
||||
app('log')->debug(sprintf('Field %s is unchanged ("%s"), continue.', $field, $oldData[$field]));
|
||||
Log::debug(sprintf('Field %s is unchanged ("%s"), continue.', $field, $oldData[$field]));
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -230,7 +231,7 @@ class BillUpdateService
|
||||
foreach ($rules as $rule) {
|
||||
$trigger = $this->getRuleTrigger($rule, $key);
|
||||
if ($trigger instanceof RuleTrigger && $trigger->trigger_value === $oldValue) {
|
||||
app('log')->debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));
|
||||
Log::debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));
|
||||
$trigger->trigger_value = $newValue;
|
||||
$trigger->save();
|
||||
|
||||
@@ -238,7 +239,7 @@ class BillUpdateService
|
||||
}
|
||||
if ($trigger instanceof RuleTrigger && $trigger->trigger_value !== $oldValue && in_array($key, ['amount_more', 'amount_less'], true)
|
||||
&& 0 === bccomp($trigger->trigger_value, $oldValue)) {
|
||||
app('log')->debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));
|
||||
Log::debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));
|
||||
$trigger->trigger_value = $newValue;
|
||||
$trigger->save();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -54,7 +55,7 @@ class CategoryUpdateService
|
||||
/**
|
||||
* @param mixed $user
|
||||
*/
|
||||
public function setUser($user): void
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
@@ -88,13 +89,13 @@ class CategoryUpdateService
|
||||
->where('rule_triggers.trigger_value', $oldName)
|
||||
->get(['rule_triggers.*'])
|
||||
;
|
||||
app('log')->debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
Log::debug(sprintf('Found %d triggers to update.', $triggers->count()));
|
||||
|
||||
/** @var RuleTrigger $trigger */
|
||||
foreach ($triggers as $trigger) {
|
||||
$trigger->trigger_value = $newName;
|
||||
$trigger->save();
|
||||
app('log')->debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,13 +108,13 @@ class CategoryUpdateService
|
||||
->where('rule_actions.action_value', $oldName)
|
||||
->get(['rule_actions.*'])
|
||||
;
|
||||
app('log')->debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
Log::debug(sprintf('Found %d actions to update.', $actions->count()));
|
||||
|
||||
/** @var RuleAction $action */
|
||||
foreach ($actions as $action) {
|
||||
$action->action_value = $newName;
|
||||
$action->save();
|
||||
app('log')->debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ class CategoryUpdateService
|
||||
*/
|
||||
private function updateNotes(Category $category, array $data): void
|
||||
{
|
||||
$note = array_key_exists('notes', $data) ? $data['notes'] : null;
|
||||
$note = $data['notes'] ?? null;
|
||||
if (null === $note) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -105,16 +105,14 @@ class GroupUpdateService
|
||||
|
||||
$result = array_diff($existing, $updated);
|
||||
Log::debug('Result of DIFF: ', $result);
|
||||
if (count($result) > 0) {
|
||||
/** @var string $deletedId */
|
||||
foreach ($result as $deletedId) {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $transactionGroup->transactionJournals()->find((int) $deletedId);
|
||||
/** @var string $deletedId */
|
||||
foreach ($result as $deletedId) {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $transactionGroup->transactionJournals()->find((int) $deletedId);
|
||||
|
||||
/** @var JournalDestroyService $service */
|
||||
$service = app(JournalDestroyService::class);
|
||||
$service->destroy($journal);
|
||||
}
|
||||
/** @var JournalDestroyService $service */
|
||||
$service = app(JournalDestroyService::class);
|
||||
$service->destroy($journal);
|
||||
}
|
||||
|
||||
app('preferences')->mark();
|
||||
|
||||
@@ -63,14 +63,29 @@ class JournalUpdateService
|
||||
private CurrencyRepositoryInterface $currencyRepository;
|
||||
private TransactionGroupRepositoryInterface $transactionGroupRepository;
|
||||
private array $data;
|
||||
private ?Account $destinationAccount;
|
||||
private ?Transaction $destinationTransaction;
|
||||
private array $metaDate;
|
||||
private array $metaString;
|
||||
private ?Account $sourceAccount;
|
||||
private ?Transaction $sourceTransaction;
|
||||
private ?TransactionGroup $transactionGroup;
|
||||
private ?TransactionJournal $transactionJournal;
|
||||
private ?Account $destinationAccount = null;
|
||||
private ?Transaction $destinationTransaction = null;
|
||||
private array $metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||
'invoice_date', ];
|
||||
private array $metaString = [
|
||||
'sepa_cc',
|
||||
'sepa_ct_op',
|
||||
'sepa_ct_id',
|
||||
'sepa_db',
|
||||
'sepa_country',
|
||||
'sepa_ep',
|
||||
'sepa_ci',
|
||||
'sepa_batch_id',
|
||||
'recurrence_id',
|
||||
'internal_reference',
|
||||
'bunq_payment_id',
|
||||
'external_id',
|
||||
'external_url',
|
||||
];
|
||||
private ?Account $sourceAccount = null;
|
||||
private ?Transaction $sourceTransaction = null;
|
||||
private ?TransactionGroup $transactionGroup = null;
|
||||
private ?TransactionJournal $transactionJournal = null;
|
||||
private string $startCompareHash = '';
|
||||
|
||||
/**
|
||||
@@ -78,12 +93,6 @@ class JournalUpdateService
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->destinationAccount = null;
|
||||
$this->destinationTransaction = null;
|
||||
$this->sourceAccount = null;
|
||||
$this->sourceTransaction = null;
|
||||
$this->transactionGroup = null;
|
||||
$this->transactionJournal = null;
|
||||
$this->billRepository = app(BillRepositoryInterface::class);
|
||||
$this->categoryRepository = app(CategoryRepositoryInterface::class);
|
||||
$this->budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
@@ -91,23 +100,6 @@ class JournalUpdateService
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
|
||||
$this->transactionGroupRepository = app(TransactionGroupRepositoryInterface::class);
|
||||
$this->metaString = [
|
||||
'sepa_cc',
|
||||
'sepa_ct_op',
|
||||
'sepa_ct_id',
|
||||
'sepa_db',
|
||||
'sepa_country',
|
||||
'sepa_ep',
|
||||
'sepa_ci',
|
||||
'sepa_batch_id',
|
||||
'recurrence_id',
|
||||
'internal_reference',
|
||||
'bunq_payment_id',
|
||||
'external_id',
|
||||
'external_url',
|
||||
];
|
||||
$this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date',
|
||||
'invoice_date', ];
|
||||
}
|
||||
|
||||
public function setData(array $data): void
|
||||
@@ -141,7 +133,7 @@ class JournalUpdateService
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
Log::debug(sprintf('Now in JournalUpdateService for journal #%d.', $this->transactionJournal->id));
|
||||
|
||||
$this->data['reconciled'] = array_key_exists('reconciled', $this->data) ? $this->data['reconciled'] : null;
|
||||
$this->data['reconciled'] ??= null;
|
||||
|
||||
// can we update account data using the new type?
|
||||
if ($this->hasValidAccounts()) {
|
||||
@@ -221,7 +213,7 @@ class JournalUpdateService
|
||||
|
||||
private function hasFields(array $fields): bool
|
||||
{
|
||||
return array_any($fields, fn ($field) => array_key_exists($field, $this->data));
|
||||
return array_any($fields, fn ($field): bool => array_key_exists($field, $this->data));
|
||||
}
|
||||
|
||||
private function getOriginalSourceAccount(): Account
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -94,7 +95,7 @@ class RecurrenceUpdateService
|
||||
|
||||
// update all repetitions
|
||||
if (array_key_exists('repetitions', $data)) {
|
||||
app('log')->debug('Will update repetitions array');
|
||||
Log::debug('Will update repetitions array');
|
||||
// update each repetition or throw error yay
|
||||
$this->updateRepetitions($recurrence, $data['repetitions'] ?? []);
|
||||
}
|
||||
@@ -135,14 +136,14 @@ class RecurrenceUpdateService
|
||||
}
|
||||
// user added or removed repetitions, delete all and recreate:
|
||||
if ($originalCount !== count($repetitions)) {
|
||||
app('log')->debug('Delete existing repetitions and create new ones.');
|
||||
Log::debug('Delete existing repetitions and create new ones.');
|
||||
$this->deleteRepetitions($recurrence);
|
||||
$this->createRepetitions($recurrence, $repetitions);
|
||||
|
||||
return;
|
||||
}
|
||||
// loop all and try to match them:
|
||||
app('log')->debug('Loop and find');
|
||||
Log::debug('Loop and find');
|
||||
foreach ($repetitions as $current) {
|
||||
$match = $this->matchRepetition($recurrence, $current);
|
||||
if (!$match instanceof RecurrenceRepetition) {
|
||||
@@ -167,7 +168,7 @@ class RecurrenceUpdateService
|
||||
{
|
||||
$originalCount = $recurrence->recurrenceRepetitions()->count();
|
||||
if (1 === $originalCount) {
|
||||
app('log')->debug('Return the first one');
|
||||
Log::debug('Return the first one');
|
||||
|
||||
/** @var null|RecurrenceRepetition */
|
||||
return $recurrence->recurrenceRepetitions()->first();
|
||||
@@ -198,12 +199,12 @@ class RecurrenceUpdateService
|
||||
*/
|
||||
private function updateTransactions(Recurrence $recurrence, array $transactions): void
|
||||
{
|
||||
app('log')->debug('Now in updateTransactions()');
|
||||
Log::debug('Now in updateTransactions()');
|
||||
$originalCount = $recurrence->recurrenceTransactions()->count();
|
||||
app('log')->debug(sprintf('Original count is %d', $originalCount));
|
||||
Log::debug(sprintf('Original count is %d', $originalCount));
|
||||
if (0 === count($transactions)) {
|
||||
// won't drop transactions, rather avoid.
|
||||
app('log')->warning('No transactions to update, too scared to continue!');
|
||||
Log::warning('No transactions to update, too scared to continue!');
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -213,7 +214,7 @@ class RecurrenceUpdateService
|
||||
foreach ($originalTransactions as $i => $originalTransaction) {
|
||||
foreach ($transactions as $ii => $submittedTransaction) {
|
||||
if (array_key_exists('id', $submittedTransaction) && (int) $originalTransaction['id'] === (int) $submittedTransaction['id']) {
|
||||
app('log')->debug(sprintf('Match original transaction #%d with an entry in the submitted array.', $originalTransaction['id']));
|
||||
Log::debug(sprintf('Match original transaction #%d with an entry in the submitted array.', $originalTransaction['id']));
|
||||
$combinations[] = [
|
||||
'original' => $originalTransaction,
|
||||
'submitted' => $submittedTransaction,
|
||||
@@ -225,7 +226,7 @@ class RecurrenceUpdateService
|
||||
// If one left of both we can match those as well and presto.
|
||||
if (1 === count($originalTransactions) && 1 === count($transactions)) {
|
||||
$first = array_shift($originalTransactions);
|
||||
app('log')->debug(sprintf('One left of each, link them (ID is #%d)', $first['id']));
|
||||
Log::debug(sprintf('One left of each, link them (ID is #%d)', $first['id']));
|
||||
$combinations[] = [
|
||||
'original' => $first,
|
||||
'submitted' => array_shift($transactions),
|
||||
@@ -240,7 +241,7 @@ class RecurrenceUpdateService
|
||||
}
|
||||
// anything left in the original transactions array can be deleted.
|
||||
foreach ($originalTransactions as $original) {
|
||||
app('log')->debug(sprintf('Original transaction #%d is unmatched, delete it!', $original['id']));
|
||||
Log::debug(sprintf('Original transaction #%d is unmatched, delete it!', $original['id']));
|
||||
$this->deleteTransaction($recurrence, (int) $original['id']);
|
||||
}
|
||||
// anything left is new.
|
||||
@@ -261,7 +262,7 @@ class RecurrenceUpdateService
|
||||
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
$transaction = $recurrence->recurrenceTransactions()->find($original['id']);
|
||||
app('log')->debug(sprintf('Now in updateCombination(#%d)', $original['id']));
|
||||
Log::debug(sprintf('Now in updateCombination(#%d)', $original['id']));
|
||||
|
||||
// loop all and try to match them:
|
||||
$currency = null;
|
||||
@@ -269,7 +270,7 @@ class RecurrenceUpdateService
|
||||
if (array_key_exists('currency_id', $submitted) || array_key_exists('currency_code', $submitted)) {
|
||||
$currency = $currencyFactory->find(
|
||||
array_key_exists('currency_id', $submitted) ? (int) $submitted['currency_id'] : null,
|
||||
array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null
|
||||
$submitted['currency_code'] ?? null
|
||||
);
|
||||
}
|
||||
if (null === $currency) {
|
||||
@@ -281,7 +282,7 @@ class RecurrenceUpdateService
|
||||
if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {
|
||||
$foreignCurrency = $currencyFactory->find(
|
||||
array_key_exists('foreign_currency_id', $submitted) ? (int) $submitted['foreign_currency_id'] : null,
|
||||
array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null
|
||||
$submitted['foreign_currency_code'] ?? null
|
||||
);
|
||||
}
|
||||
if (null === $foreignCurrency) {
|
||||
@@ -317,13 +318,13 @@ class RecurrenceUpdateService
|
||||
// reset category if name is set but empty:
|
||||
// can be removed when v1 is retired.
|
||||
if (array_key_exists('category_name', $submitted) && '' === (string) $submitted['category_name']) {
|
||||
app('log')->debug('Category name is submitted but is empty. Set category to be empty.');
|
||||
Log::debug('Category name is submitted but is empty. Set category to be empty.');
|
||||
$submitted['category_name'] = null;
|
||||
$submitted['category_id'] = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('category_id', $submitted)) {
|
||||
app('log')->debug(sprintf('Category ID is submitted, set category to be %d.', (int) $submitted['category_id']));
|
||||
Log::debug(sprintf('Category ID is submitted, set category to be %d.', (int) $submitted['category_id']));
|
||||
$this->setCategory($transaction, (int) $submitted['category_id']);
|
||||
}
|
||||
|
||||
@@ -337,7 +338,7 @@ class RecurrenceUpdateService
|
||||
|
||||
private function deleteTransaction(Recurrence $recurrence, int $transactionId): void
|
||||
{
|
||||
app('log')->debug(sprintf('Will delete transaction #%d in recurrence #%d.', $transactionId, $recurrence->id));
|
||||
Log::debug(sprintf('Will delete transaction #%d in recurrence #%d.', $transactionId, $recurrence->id));
|
||||
$recurrence->recurrenceTransactions()->where('id', $transactionId)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user