Reformat various code.

This commit is contained in:
James Cole
2022-03-29 14:59:58 +02:00
parent 29bed2547c
commit d1a09ff33b
115 changed files with 2700 additions and 2699 deletions

View File

@@ -89,7 +89,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;
}
@@ -108,7 +108,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:
@@ -135,7 +135,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.
@@ -149,7 +149,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;
@@ -210,7 +210,7 @@ class AccountUpdateService
return $account;
}
// get account type ID's because a join and an update is hard:
$oldOrder = (int)$account->order;
$oldOrder = (int) $account->order;
$newOrder = $data['order'];
Log::debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
$list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]);
@@ -248,7 +248,7 @@ class AccountUpdateService
foreach ($array as $type) {
/** @var AccountType $type */
$type = AccountType::whereType($type)->first();
$return[] = (int)$type->id;
$return[] = (int) $type->id;
}
return $return;
@@ -357,12 +357,12 @@ class AccountUpdateService
$array = $preference->data;
Log::debug('Old array is: ', $array);
Log::debug(sprintf('Must remove : %d', $account->id));
$removeAccountId = (int)$account->id;
$removeAccountId = (int) $account->id;
$new = [];
foreach ($array as $value) {
if ((int)$value !== $removeAccountId) {
if ((int) $value !== $removeAccountId) {
Log::debug(sprintf('Will include: %d', $value));
$new[] = (int)$value;
$new[] = (int) $value;
}
}
Log::debug('Final new array is', $new);

View File

@@ -56,7 +56,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')->getDefaultCurrencyByUser($bill->user);
// enable the currency if it isn't.
@@ -78,14 +78,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 = (int)$bill->order;
$newOrder = (int)($data['order'] ?? $oldOrder);
$oldOrder = (int) $bill->order;
$newOrder = (int) ($data['order'] ?? $oldOrder);
if ($oldOrder !== $newOrder) {
$this->updateOrder($bill, $oldOrder, $newOrder);
}
@@ -117,7 +117,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) {
@@ -144,20 +144,20 @@ 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'];
}
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)) {
@@ -166,10 +166,10 @@ class BillUpdateService
if (array_key_exists('active', $data)) {
$bill->active = $data['active'];
}
if(array_key_exists('end_date', $data)) {
if (array_key_exists('end_date', $data)) {
$bill->end_date = $data['end_date'];
}
if(array_key_exists('extension_date', $data)) {
if (array_key_exists('extension_date', $data)) {
$bill->extension_date = $data['extension_date'];
}

View File

@@ -40,15 +40,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 = $data['code'];
}
if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) {
if (array_key_exists('symbol', $data) && '' !== (string) $data['symbol']) {
$currency->symbol = $data['symbol'];
}
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
if (array_key_exists('name', $data) && '' !== (string) $data['name']) {
$currency->name = $data['name'];
}

View File

@@ -48,7 +48,7 @@ class GroupCloneService
$newGroup = $group->replicate();
$newGroup->save();
foreach ($group->transactionJournals as $journal) {
$this->cloneJournal($journal, $newGroup, (int)$group->id);
$this->cloneJournal($journal, $newGroup, (int) $group->id);
}
return $newGroup;

View File

@@ -215,7 +215,7 @@ class JournalUpdateService
$validator->setTransactionType($expectedType);
$validator->setUser($this->transactionJournal->user);
$result = $validator->validateSource(['id' =>$sourceId]);
$result = $validator->validateSource(['id' => $sourceId]);
Log::debug(sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true)));
// See reference nr. 95
@@ -359,7 +359,7 @@ class JournalUpdateService
}
$sourceInfo = [
'id' => (int)($this->data['source_id'] ?? null),
'id' => (int) ($this->data['source_id'] ?? null),
'name' => $this->data['source_name'] ?? null,
'iban' => $this->data['source_iban'] ?? null,
'number' => $this->data['source_number'] ?? null,
@@ -424,7 +424,7 @@ class JournalUpdateService
}
$destInfo = [
'id' => (int)($this->data['destination_id'] ?? null),
'id' => (int) ($this->data['destination_id'] ?? null),
'name' => $this->data['destination_name'] ?? null,
'iban' => $this->data['destination_iban'] ?? null,
'number' => $this->data['destination_number'] ?? null,
@@ -487,8 +487,8 @@ class JournalUpdateService
)
&& TransactionType::WITHDRAWAL === $type
) {
$billId = (int)($this->data['bill_id'] ?? 0);
$billName = (string)($this->data['bill_name'] ?? '');
$billId = (int) ($this->data['bill_id'] ?? 0);
$billName = (string) ($this->data['bill_name'] ?? '');
$bill = $this->billRepository->findBill($billId, $billName);
$this->transactionJournal->bill_id = $bill?->id;
Log::debug('Updated bill ID');
@@ -502,7 +502,7 @@ class JournalUpdateService
*/
private function updateField(string $fieldName): void
{
if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {
if (array_key_exists($fieldName, $this->data) && '' !== (string) $this->data[$fieldName]) {
$value = $this->data[$fieldName];
if ('date' === $fieldName) {
@@ -579,7 +579,7 @@ class JournalUpdateService
{
// update notes.
if ($this->hasFields(['notes'])) {
$notes = '' === (string)$this->data['notes'] ? null : $this->data['notes'];
$notes = '' === (string) $this->data['notes'] ? null : $this->data['notes'];
$this->storeNotes($this->transactionJournal, $notes);
}
}
@@ -636,7 +636,7 @@ class JournalUpdateService
foreach ($this->metaDate as $field) {
if ($this->hasFields([$field])) {
try {
$value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);
$value = '' === (string) $this->data[$field] ? null : new Carbon($this->data[$field]);
} catch (Exception $e) { // @phpstan-ignore-line
Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));

View File

@@ -78,7 +78,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'];
@@ -257,7 +257,7 @@ class RecurrenceUpdateService
unset($current['currency_id'], $current['currency_code']);
}
if (null !== $currency) {
$current['currency_id'] = (int)$currency->id;
$current['currency_id'] = (int) $currency->id;
}
if (array_key_exists('foreign_currency_id', $current) || array_key_exists('foreign_currency_code', $current)) {
$foreignCurrency = $currencyFactory->find($current['foreign_currency_id'] ?? null, $currency['foreign_currency_code'] ?? null);
@@ -266,7 +266,7 @@ class RecurrenceUpdateService
unset($current['foreign_currency_id'], $currency['foreign_currency_code']);
}
if (null !== $foreignCurrency) {
$current['foreign_currency_id'] = (int)$foreignCurrency->id;
$current['foreign_currency_id'] = (int) $foreignCurrency->id;
}
// update fields
@@ -287,27 +287,27 @@ class RecurrenceUpdateService
}
// update meta data
if (array_key_exists('budget_id', $current)) {
$this->setBudget($match, (int)$current['budget_id']);
$this->setBudget($match, (int) $current['budget_id']);
}
if (array_key_exists('bill_id', $current)) {
$this->setBill($match, (int)$current['bill_id']);
$this->setBill($match, (int) $current['bill_id']);
}
// reset category if name is set but empty:
// can be removed when v1 is retired.
if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) {
if (array_key_exists('category_name', $current) && '' === (string) $current['category_name']) {
$current['category_name'] = null;
$current['category_id'] = 0;
}
if (array_key_exists('category_id', $current)) {
$this->setCategory($match, (int)$current['category_id']);
$this->setCategory($match, (int) $current['category_id']);
}
if (array_key_exists('tags', $current) && is_array($current['tags'])) {
$this->updateTags($match, $current['tags']);
}
if (array_key_exists('piggy_bank_id', $current)) {
$this->updatePiggyBank($match, (int)$current['piggy_bank_id']);
$this->updatePiggyBank($match, (int) $current['piggy_bank_id']);
}
}
}