mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -75,7 +75,7 @@ class AccountUpdateService
|
||||
|
||||
// find currency, or use default currency instead.
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||
$currency = $this->getCurrency((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null));
|
||||
unset($data['currency_code'], $data['currency_id']);
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class AccountUpdateService
|
||||
|
||||
// update note:
|
||||
if (array_key_exists('notes', $data) && null !== $data['notes']) {
|
||||
$this->updateNote($account, (string)$data['notes']);
|
||||
$this->updateNote($account, (string) $data['notes']);
|
||||
}
|
||||
|
||||
// update preferences if inactive:
|
||||
@@ -120,7 +120,7 @@ class AccountUpdateService
|
||||
$account->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('iban', $data)) {
|
||||
$account->iban = app('steam')->filterSpaces((string)$data['iban']);
|
||||
$account->iban = app('steam')->filterSpaces((string) $data['iban']);
|
||||
}
|
||||
|
||||
// set liability, but account must already be a liability.
|
||||
@@ -132,7 +132,7 @@ class AccountUpdateService
|
||||
// set liability, alternative method used in v1 layout:
|
||||
|
||||
if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) {
|
||||
$type = AccountType::find((int)$data['account_type_id']);
|
||||
$type = AccountType::find((int) $data['account_type_id']);
|
||||
|
||||
if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) {
|
||||
$account->account_type_id = $type->id;
|
||||
@@ -305,9 +305,9 @@ class AccountUpdateService
|
||||
$removeAccountId = $account->id;
|
||||
$new = [];
|
||||
foreach ($array as $value) {
|
||||
if ((int)$value !== $removeAccountId) {
|
||||
if ((int) $value !== $removeAccountId) {
|
||||
app('log')->debug(sprintf('Will include: %d', $value));
|
||||
$new[] = (int)$value;
|
||||
$new[] = (int) $value;
|
||||
}
|
||||
}
|
||||
app('log')->debug('Final new array is', $new);
|
||||
|
@@ -54,7 +54,7 @@ class BillUpdateService
|
||||
|
||||
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find((int)($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
|
||||
$currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null) ??
|
||||
app('amount')->getDefaultCurrencyByUserGroup($bill->user->userGroup);
|
||||
|
||||
// enable the currency if it isn't.
|
||||
@@ -76,14 +76,14 @@ class BillUpdateService
|
||||
];
|
||||
// update note:
|
||||
if (array_key_exists('notes', $data)) {
|
||||
$this->updateNote($bill, (string)$data['notes']);
|
||||
$this->updateNote($bill, (string) $data['notes']);
|
||||
}
|
||||
|
||||
// update order.
|
||||
if (array_key_exists('order', $data)) {
|
||||
// update the order of the piggy bank:
|
||||
$oldOrder = $bill->order;
|
||||
$newOrder = (int)($data['order'] ?? $oldOrder);
|
||||
$newOrder = (int) ($data['order'] ?? $oldOrder);
|
||||
if ($oldOrder !== $newOrder) {
|
||||
$this->updateOrder($bill, $oldOrder, $newOrder);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ class BillUpdateService
|
||||
}
|
||||
if (array_key_exists('object_group_id', $data)) {
|
||||
// try also with ID:
|
||||
$objectGroupId = (int)($data['object_group_id'] ?? 0);
|
||||
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if (null !== $objectGroup) {
|
||||
@@ -135,21 +135,21 @@ class BillUpdateService
|
||||
*/
|
||||
private function updateBillProperties(Bill $bill, array $data): Bill
|
||||
{
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
|
||||
$bill->name = $data['name'];
|
||||
}
|
||||
|
||||
if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) {
|
||||
if (array_key_exists('amount_min', $data) && '' !== (string) $data['amount_min']) {
|
||||
$bill->amount_min = $data['amount_min'];
|
||||
}
|
||||
if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) {
|
||||
if (array_key_exists('amount_max', $data) && '' !== (string) $data['amount_max']) {
|
||||
$bill->amount_max = $data['amount_max'];
|
||||
}
|
||||
if (array_key_exists('date', $data) && '' !== (string)$data['date']) {
|
||||
if (array_key_exists('date', $data) && '' !== (string) $data['date']) {
|
||||
$bill->date = $data['date'];
|
||||
$bill->date_tz = $data['date']->format('e');
|
||||
}
|
||||
if (array_key_exists('repeat_freq', $data) && '' !== (string)$data['repeat_freq']) {
|
||||
if (array_key_exists('repeat_freq', $data) && '' !== (string) $data['repeat_freq']) {
|
||||
$bill->repeat_freq = $data['repeat_freq'];
|
||||
}
|
||||
if (array_key_exists('skip', $data)) {
|
||||
|
@@ -33,15 +33,15 @@ class CurrencyUpdateService
|
||||
{
|
||||
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
|
||||
{
|
||||
if (array_key_exists('code', $data) && '' !== (string)$data['code']) {
|
||||
if (array_key_exists('code', $data) && '' !== (string) $data['code']) {
|
||||
$currency->code = e($data['code']);
|
||||
}
|
||||
|
||||
if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) {
|
||||
if (array_key_exists('symbol', $data) && '' !== (string) $data['symbol']) {
|
||||
$currency->symbol = e($data['symbol']);
|
||||
}
|
||||
|
||||
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
|
||||
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
|
||||
$currency->name = e($data['name']);
|
||||
}
|
||||
|
||||
|
@@ -108,7 +108,7 @@ class GroupUpdateService
|
||||
/** @var string $deletedId */
|
||||
foreach ($result as $deletedId) {
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $transactionGroup->transactionJournals()->find((int)$deletedId);
|
||||
$journal = $transactionGroup->transactionJournals()->find((int) $deletedId);
|
||||
|
||||
/** @var JournalDestroyService $service */
|
||||
$service = app(JournalDestroyService::class);
|
||||
@@ -163,7 +163,7 @@ class GroupUpdateService
|
||||
*/
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
app('log')->debug(sprintf('Now at #%d of %d', $index + 1, count($transactions)), $transaction);
|
||||
$journalId = (int)($transaction['transaction_journal_id'] ?? 0);
|
||||
$journalId = (int) ($transaction['transaction_journal_id'] ?? 0);
|
||||
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = $transactionGroup->transactionJournals()->find($journalId);
|
||||
|
@@ -74,7 +74,7 @@ class RecurrenceUpdateService
|
||||
$recurrence->repetitions = 0;
|
||||
}
|
||||
if (array_key_exists('nr_of_repetitions', $info)) {
|
||||
if (0 !== (int)$info['nr_of_repetitions']) {
|
||||
if (0 !== (int) $info['nr_of_repetitions']) {
|
||||
$recurrence->repeat_until = null;
|
||||
}
|
||||
$recurrence->repetitions = $info['nr_of_repetitions'];
|
||||
@@ -212,7 +212,7 @@ class RecurrenceUpdateService
|
||||
// First, make sure to loop all existing transactions and match them to a counterpart in the submitted transactions array.
|
||||
foreach ($originalTransactions as $i => $originalTransaction) {
|
||||
foreach ($transactions as $ii => $submittedTransaction) {
|
||||
if (array_key_exists('id', $submittedTransaction) && (int)$originalTransaction['id'] === (int)$submittedTransaction['id']) {
|
||||
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']));
|
||||
$combinations[] = [
|
||||
'original' => $originalTransaction,
|
||||
@@ -241,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']));
|
||||
$this->deleteTransaction($recurrence, (int)$original['id']);
|
||||
$this->deleteTransaction($recurrence, (int) $original['id']);
|
||||
}
|
||||
// anything left is new.
|
||||
$this->createTransactions($recurrence, $transactions);
|
||||
@@ -268,7 +268,7 @@ class RecurrenceUpdateService
|
||||
$foreignCurrency = null;
|
||||
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_id', $submitted) ? (int) $submitted['currency_id'] : null,
|
||||
array_key_exists('currency_code', $submitted) ? $submitted['currency_code'] : null
|
||||
);
|
||||
}
|
||||
@@ -280,7 +280,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_id', $submitted) ? (int) $submitted['foreign_currency_id'] : null,
|
||||
array_key_exists('foreign_currency_code', $submitted) ? $submitted['foreign_currency_code'] : null
|
||||
);
|
||||
}
|
||||
@@ -309,29 +309,29 @@ class RecurrenceUpdateService
|
||||
}
|
||||
// update meta data
|
||||
if (array_key_exists('budget_id', $submitted)) {
|
||||
$this->setBudget($transaction, (int)$submitted['budget_id']);
|
||||
$this->setBudget($transaction, (int) $submitted['budget_id']);
|
||||
}
|
||||
if (array_key_exists('bill_id', $submitted)) {
|
||||
$this->setBill($transaction, (int)$submitted['bill_id']);
|
||||
$this->setBill($transaction, (int) $submitted['bill_id']);
|
||||
}
|
||||
// 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']) {
|
||||
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.');
|
||||
$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']));
|
||||
$this->setCategory($transaction, (int)$submitted['category_id']);
|
||||
app('log')->debug(sprintf('Category ID is submitted, set category to be %d.', (int) $submitted['category_id']));
|
||||
$this->setCategory($transaction, (int) $submitted['category_id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('tags', $submitted) && is_array($submitted['tags'])) {
|
||||
$this->updateTags($transaction, $submitted['tags']);
|
||||
}
|
||||
if (array_key_exists('piggy_bank_id', $submitted)) {
|
||||
$this->updatePiggyBank($transaction, (int)$submitted['piggy_bank_id']);
|
||||
$this->updatePiggyBank($transaction, (int) $submitted['piggy_bank_id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user