Skip to content

Firefly III: a personal finances manager

Various code cleanup.

James Colefe06a1f7a06e
diff --git a/app/Models/RecurrenceMeta.php b/app/Models/RecurrenceMeta.php
index 43af735266..60a2cf843b 100644
--- a/app/Models/RecurrenceMeta.php
+++ b/app/Models/RecurrenceMeta.php
@@ -38,7 +38,7 @@ use Illuminate\Support\Carbon;
* @property Carbon|null $deleted_at
* @property int $recurrence_id
* @property string $name
- * @property string $value
+ * @property mixed $value
* @property-read \FireflyIII\Models\Recurrence $recurrence
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newQuery()
diff --git a/app/Models/RecurrenceTransactionMeta.php b/app/Models/RecurrenceTransactionMeta.php
index f2030342c6..f71dee3bf1 100644
--- a/app/Models/RecurrenceTransactionMeta.php
+++ b/app/Models/RecurrenceTransactionMeta.php
@@ -38,7 +38,7 @@ use Illuminate\Support\Carbon;
* @property Carbon|null $deleted_at
* @property int $rt_id
* @property string $name
- * @property string $value
+ * @property mixed $value
* @property-read \FireflyIII\Models\RecurrenceTransaction $recurrenceTransaction
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newQuery()
diff --git a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
index e04736266a..c5e79feaa4 100644
--- a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
+++ b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php
@@ -46,8 +46,8 @@ class TransactionGroupDestroyService
}
try {
$transactionGroup->delete();
- } catch (Exception $e) {
- app('log')->error(sprintf('Could not delete transaction group: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php
index 0f8a7c8343..d9dabfed91 100644
--- a/app/Services/Internal/Support/AccountServiceTrait.php
+++ b/app/Services/Internal/Support/AccountServiceTrait.php
@@ -66,6 +66,7 @@ trait AccountServiceTrait
return null;
}
+
return $iban;
}
@@ -132,7 +133,7 @@ trait AccountServiceTrait
foreach ($fields as $field) {
// if the field is set but NULL, skip it.
// if the field is set but "", update it.
- if (isset($data[$field]) && null !== $data[$field]) {
+ if (array_key_exists($field, $data) && null !== $data[$field]) {
// convert boolean value:
if (is_bool($data[$field]) && false === $data[$field]) {
@@ -192,7 +193,7 @@ trait AccountServiceTrait
if ('' !== $data['opening_balance'] && 0 === bccomp($data['opening_balance'], '0')) {
$data['opening_balance'] = ''; // @codeCoverageIgnore
}
- if ('' !== $data['opening_balance'] && isset($data['opening_balance'], $data['opening_balance_date'])) {
+ if ('' !== $data['opening_balance'] && array_key_exists('opening_balance_date', $data) && '' !== $data['opening_balance_date']) {
Log::debug('Array has valid opening balance data.');
return true;
@@ -244,7 +245,7 @@ trait AccountServiceTrait
// find currency, or use default currency instead.
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
- /** @var TransactionCurrency $currency */
+ /** @var TransactionCurrency|null $currency */
$currency = $factory->find($currencyId, $currencyCode);
if (null === $currency) {
diff --git a/app/Services/Internal/Support/BillServiceTrait.php b/app/Services/Internal/Support/BillServiceTrait.php
index 17b0476a3f..bf79f2330f 100644
--- a/app/Services/Internal/Support/BillServiceTrait.php
+++ b/app/Services/Internal/Support/BillServiceTrait.php
@@ -74,8 +74,8 @@ trait BillServiceTrait
if (null !== $dbNote) {
try {
$dbNote->delete();
- } catch (Exception $e) {
- Log::debug(sprintf('Error deleting note: %s', $e->getMessage()));
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php
index 562ef03203..eef13daf2d 100644
--- a/app/Services/Internal/Support/JournalServiceTrait.php
+++ b/app/Services/Internal/Support/JournalServiceTrait.php
@@ -185,7 +185,7 @@ trait JournalServiceTrait
// final attempt, create it.
if (AccountType::ASSET === $preferredType) {
- throw new FireflyException('TransactionFactory: Cannot create asset account with these values', $data);
+ throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s',json_encode($data)));
}
// fix name of account if only IBAN is given:
if ('' === (string)$data['name'] && '' !== (string)$data['iban']) {
@@ -358,11 +358,9 @@ trait JournalServiceTrait
// try to delete existing notes.
try {
$note->delete();
- // @codeCoverageIgnoreStart
- } catch (Exception $e) {
- Log::debug(sprintf('Could not delete journal notes: %s', $e->getMessage()));
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
- // @codeCoverageIgnoreEnd
}
}
diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php
index b2974b289b..e349b33e83 100644
--- a/app/Services/Internal/Support/RecurringTransactionTrait.php
+++ b/app/Services/Internal/Support/RecurringTransactionTrait.php
@@ -41,6 +41,7 @@ use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Validation\AccountValidator;
use Log;
+
/**
* Trait RecurringTransactionTrait
*
@@ -60,8 +61,8 @@ trait RecurringTransactionTrait
if (null !== $dbNote) {
try {
$dbNote->delete();
- } catch (Exception $e) {
- Log::debug(sprintf('Error deleting note: %s', $e->getMessage()));
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
@@ -179,10 +180,9 @@ trait RecurringTransactionTrait
}
/**
- * @param array $expectedTypes
- * @param Account|null $account
- * @param int|null $accountId
- * @param string|null $accountName
+ * @param array $expectedTypes
+ * @param int|null $accountId
+ * @param string|null $accountName
*
* @return Account
*/
@@ -212,6 +212,7 @@ trait RecurringTransactionTrait
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user);
+ /** @var string $expectedType */
foreach ($expectedTypes as $expectedType) {
if (in_array($expectedType, $cannotCreate, true)) {
continue;
@@ -287,7 +288,7 @@ trait RecurringTransactionTrait
$factory->setUser($transaction->recurrence->user);
$piggyBank = $factory->find($piggyId, null);
if (null !== $piggyBank) {
- /** @var RecurrenceMeta $entry */
+ /** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'piggy_bank_id')->first();
if (null === $entry) {
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'piggy_bank_id', 'value' => $piggyBank->id]);
@@ -307,8 +308,8 @@ trait RecurringTransactionTrait
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
- if (!empty($tags)) {
- /** @var RecurrenceMeta $entry */
+ if (count($tags) > 0) {
+ /** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
if (null === $entry) {
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'tags', 'value' => json_encode($tags)]);
@@ -316,7 +317,7 @@ trait RecurringTransactionTrait
$entry->value = json_encode($tags);
$entry->save();
}
- if (empty($tags)) {
+ if (0 === count($tags)) {
// delete if present
$transaction->recurrenceTransactionMeta()->where('name', 'tags')->delete();
}
@@ -345,8 +346,8 @@ trait RecurringTransactionTrait
$transaction->recurrenceTransactionMeta()->delete();
try {
$transaction->delete();
- } catch (Exception $e) {
- Log::debug($e->getMessage());
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
}
diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php
index d6322a845c..6520cabdad 100644
--- a/app/Services/Internal/Update/CategoryUpdateService.php
+++ b/app/Services/Internal/Update/CategoryUpdateService.php
@@ -153,7 +153,7 @@ class CategoryUpdateService
if (null !== $dbNote) {
try {
$dbNote->delete();
- } catch (Exception $e) {
+ } catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}
diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.php
index 8d925d0038..f5ab52986a 100644
--- a/app/Support/Authentication/RemoteUserGuard.php
+++ b/app/Support/Authentication/RemoteUserGuard.php
@@ -47,6 +47,7 @@ class RemoteUserGuard implements Guard
*
* @return void
*/
+ // @phpstan-ignore-next-line
public function __construct(UserProvider $provider, Application $app) // @phpstan-ignore-line
{
$this->application = $app;
diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php
index 90971f9fca..7ea4dcef2b 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -275,6 +275,9 @@ class Preferences
if (null === $value) {
return new Preference;
}
+ if(null === $pref) {
+ $pref = new Preference;
+ }
$pref->data = $value;
$pref->save();
Cache::forever($fullName, $pref);