Skip to content

Firefly III: a personal finances manager

Fix calls to isset

James Cole63ab0fba8d14
diff --git a/app/Repositories/Category/NoCategoryRepository.php b/app/Repositories/Category/NoCategoryRepository.php
index 17c59c0af6..868de47868 100644
--- a/app/Repositories/Category/NoCategoryRepository.php
+++ b/app/Repositories/Category/NoCategoryRepository.php
@@ -85,8 +85,8 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
'currency_code' => (string) $journal['currency_code'],
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
'foreign_currency_id' => (int) ($journal['foreign_currency_id'] ?? 0),
- 'foreign_amount' => isset($journal['foreign_amount']) ? Steam::negative((string) $journal['foreign_amount']) : null,
- 'pc_amount' => isset($journal['pc_amount']) ? Steam::negative((string) $journal['pc_amount']) : null,
+ 'foreign_amount' => array_key_exists('foreign_amount', $journal) && null !== $journal['foreign_amount'] ? Steam::negative((string) $journal['foreign_amount']) : null,
+ 'pc_amount' => array_key_exists('pc_amount', $journal) && null !== $journal['pc_amount'] ? Steam::negative((string) $journal['pc_amount']) : null,
'date' => $journal['date'],
];
}
@@ -139,8 +139,8 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
'currency_code' => (string) $journal['currency_code'],
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
'foreign_currency_id' => (int) ($journal['foreign_currency_id'] ?? 0),
- 'foreign_amount' => isset($journal['foreign_amount']) ? Steam::positive((string) $journal['foreign_amount']) : null,
- 'pc_amount' => isset($journal['pc_amount']) ? Steam::positive((string) $journal['pc_amount']) : null,
+ 'foreign_amount' => array_key_exists('foreign_amount', $journal) && null !== $journal['foreign_amount'] ? Steam::positive((string) $journal['foreign_amount']) : null,
+ 'pc_amount' => array_key_exists('pc_amount', $journal) && null !== $journal['pc_amount'] ? Steam::positive((string) $journal['pc_amount']) : null,
'date' => $journal['date'],
];
}
diff --git a/app/Repositories/Category/OperationsRepository.php b/app/Repositories/Category/OperationsRepository.php
index 663f96f9f7..ea20e0c815 100644
--- a/app/Repositories/Category/OperationsRepository.php
+++ b/app/Repositories/Category/OperationsRepository.php
@@ -159,8 +159,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
'currency_code' => (string) $journal['currency_code'],
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
'foreign_currency_id' => (int) ($journal['foreign_currency_id'] ?? 0),
- 'foreign_amount' => isset($journal['foreign_amount']) ? Steam::negative((string) $journal['foreign_amount']) : null,
- 'pc_amount' => isset($journal['pc_amount']) ? Steam::negative((string) $journal['pc_amount']) : null,
+ 'foreign_amount' => array_key_exists('foreign_amount', $journal) && null !== $journal['foreign_amount'] ? Steam::negative((string) $journal['foreign_amount']) : null,
+ 'pc_amount' => array_key_exists('pc_amount', $journal) && null !== $journal['pc_amount'] ? Steam::negative((string) $journal['pc_amount']) : null,
'date' => $journal['date'],
'source_account_id' => (string) $journal['source_account_id'],
'budget_name' => $journal['budget_name'],
@@ -237,8 +237,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
'currency_code' => (string) $journal['currency_code'],
'currency_decimal_places' => (int) $journal['currency_decimal_places'],
'foreign_currency_id' => (int) ($journal['foreign_currency_id'] ?? 0),
- 'foreign_amount' => isset($journal['foreign_amount']) ? Steam::positive((string) $journal['foreign_amount']) : null,
- 'pc_amount' => isset($journal['pc_amount']) ? Steam::positive((string) $journal['pc_amount']) : null,
+ 'foreign_amount' => array_key_exists('foreign_amount', $journal) && null !== $journal['foreign_amount'] ? Steam::positive((string) $journal['foreign_amount']) : null,
+ 'pc_amount' => array_key_exists('pc_amount', $journal) && null !== $journal['pc_amount'] ? Steam::positive((string) $journal['pc_amount']) : null,
'date' => $journal['date'],
'source_account_id' => (string) $journal['source_account_id'],
'destination_account_id' => (string) $journal['destination_account_id'],
diff --git a/app/Support/Steam.php b/app/Support/Steam.php
index abd7dda9d0..aff5d47441 100644
--- a/app/Support/Steam.php
+++ b/app/Support/Steam.php
@@ -357,7 +357,7 @@ class Steam
$primary = Amount::getPrimaryCurrencyByUserGroup($account->user->userGroup);
}
// account balance thing.
- $currencyPresent = isset($account->meta) && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
+ $currencyPresent = property_exists($account, 'meta') && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
if ($currencyPresent) {
$accountCurrency = $account->meta['currency'];
}
@@ -846,7 +846,7 @@ class Steam
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
- $currencyPresent = isset($account->meta) && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
+ $currencyPresent = property_exists($account, 'meta') && array_key_exists('currency', $account->meta) && null !== $account->meta['currency'];
if ($currencyPresent) {
$currencyId = $account->meta['currency']->id;
$currencies[$currencyId] ??= $account->meta['currency'];