Skip to content

Firefly III: a personal finances manager

Various code cleanup.

James Colecb746200fa10
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index d17756ed9a..a55703cba1 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -96,7 +96,7 @@ class UserRepository implements UserRepositoryInterface
// update user
$user->email = $newEmail;
- $user->blocked = 1;
+ $user->blocked = true;
$user->blocked_code = 'email_changed';
$user->save();
@@ -215,7 +215,7 @@ class UserRepository implements UserRepositoryInterface
*/
public function getRoleByUser(User $user): ?string
{
- /** @var Role $role */
+ /** @var Role|null $role */
$role = $user->roles()->first();
if (null !== $role) {
return $role->name;
@@ -252,10 +252,13 @@ class UserRepository implements UserRepositoryInterface
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->where('amount', '>', 0)
->whereNull('budgets.deleted_at')
- ->where('budgets.user_id', $user->id)->get(['budget_limits.budget_id'])->count();
+ ->where('budgets.user_id', $user->id)
+ ->get(['budget_limits.budget_id'])
+ ->count();
$return['rule_groups'] = $user->ruleGroups()->count();
$return['rules'] = $user->rules()->count();
$return['tags'] = $user->tags()->count();
+ var_dump($return);exit;
return $return;
}
diff --git a/app/Rules/IsDateOrTime.php b/app/Rules/IsDateOrTime.php
index 7247f8db84..04b0331bb1 100644
--- a/app/Rules/IsDateOrTime.php
+++ b/app/Rules/IsDateOrTime.php
@@ -26,7 +26,6 @@ namespace FireflyIII\Rules;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
-use Exception;
use Illuminate\Contracts\Validation\Rule;
use Log;
@@ -65,7 +64,7 @@ class IsDateOrTime implements Rule
// probably a date format.
try {
Carbon::createFromFormat('Y-m-d', $value);
- } catch (InvalidDateException | Exception $e) {
+ } catch (InvalidDateException $e) {
Log::error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));
return false;
@@ -76,7 +75,7 @@ class IsDateOrTime implements Rule
// is an atom string, I hope?
try {
Carbon::parse($value);
- } catch (InvalidDateException | Exception $e) {
+ } catch (InvalidDateException $e) {
Log::error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));
return false;
diff --git a/app/Rules/IsValidAttachmentModel.php b/app/Rules/IsValidAttachmentModel.php
index fa67b3d0e9..df6174a3a5 100644
--- a/app/Rules/IsValidAttachmentModel.php
+++ b/app/Rules/IsValidAttachmentModel.php
@@ -110,7 +110,7 @@ class IsValidAttachmentModel implements Rule
Transaction::class => 'validateTransaction',
TransactionJournal::class => 'validateJournal',
];
- if (!isset($methods[$this->model])) {
+ if (!array_key_exists($this->model, $methods)) {
Log::error(sprintf('Cannot validate model "%s" in %s.', $this->model, __METHOD__));
return false;
diff --git a/app/Scopes/LdapFilterScope.php b/app/Scopes/LdapFilterScope.php
index 38ba147852..0def667abe 100644
--- a/app/Scopes/LdapFilterScope.php
+++ b/app/Scopes/LdapFilterScope.php
@@ -27,7 +27,8 @@ namespace FireflyIII\Scopes;
use Adldap\Laravel\Scopes\ScopeInterface;
use Adldap\Query\Builder;
-class LdapFilterScope implements ScopeInterface
+// @phpstan-ignore-next-line
+class LdapFilterScope implements ScopeInterface // @phpstan-ignore-line
{
/**
* If the ADLDAP_AUTH_FILTER is provided, apply the filter to the LDAP query.
diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php
index 2f2d4d2866..f5d1a9a27f 100644
--- a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php
+++ b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php
@@ -91,7 +91,7 @@ class UpdateRequest implements UpdateRequestInterface
'timeout' => 3.1415,
];
$res = $client->request('GET', $uri, $options);
- } catch (GuzzleException | Exception $e) {
+ } catch (GuzzleException $e) {
Log::error('Ran into Guzzle error.');
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
@@ -111,7 +111,7 @@ class UpdateRequest implements UpdateRequestInterface
try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
- } catch (JsonException | Exception $e) {
+ } catch (JsonException $e) {
Log::error('Body is not valid JSON');
Log::error($body);
$return['message'] = 'Invalid JSON :(';
@@ -119,7 +119,7 @@ class UpdateRequest implements UpdateRequestInterface
return $return;
}
- if (!isset($json['firefly_iii'][$channel])) {
+ if (!array_key_exists($channel, $json['firefly_iii'])) {
Log::error(sprintf('No valid update channel "%s"', $channel));
Log::error($body);
$return['message'] = sprintf('Unknown update channel "%s" :(', $channel);
diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php
index 9e38e7e74b..743fe59bc9 100644
--- a/app/Services/Internal/Destroy/AccountDestroyService.php
+++ b/app/Services/Internal/Destroy/AccountDestroyService.php
@@ -69,8 +69,8 @@ class AccountDestroyService
// delete account.
try {
$account->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete account: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
@@ -122,7 +122,7 @@ class AccountDestroyService
$collection = Transaction::groupBy('transaction_journal_id', 'account_id')
->where('account_id', $moveTo->id)
- ->get(['transaction_journal_id', 'account_id', DB::raw('count(*) as the_count')]);
+ ->get(['transaction_journal_id', 'account_id', DB::raw('count(*) as the_count')]); // @phpstan-ignore-line
if (0 === $collection->count()) {
return;
}
diff --git a/app/Services/Internal/Destroy/BillDestroyService.php b/app/Services/Internal/Destroy/BillDestroyService.php
index 735f282ba1..e9719679bb 100644
--- a/app/Services/Internal/Destroy/BillDestroyService.php
+++ b/app/Services/Internal/Destroy/BillDestroyService.php
@@ -40,8 +40,8 @@ class BillDestroyService
{
try {
$bill->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete bill: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Services/Internal/Destroy/BudgetDestroyService.php b/app/Services/Internal/Destroy/BudgetDestroyService.php
index 3fb5897e05..aa8c4190d8 100644
--- a/app/Services/Internal/Destroy/BudgetDestroyService.php
+++ b/app/Services/Internal/Destroy/BudgetDestroyService.php
@@ -43,8 +43,8 @@ class BudgetDestroyService
try {
$budget->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete budget: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
// also delete auto budget:
diff --git a/app/Services/Internal/Destroy/CategoryDestroyService.php b/app/Services/Internal/Destroy/CategoryDestroyService.php
index a161b16770..e93240f104 100644
--- a/app/Services/Internal/Destroy/CategoryDestroyService.php
+++ b/app/Services/Internal/Destroy/CategoryDestroyService.php
@@ -42,8 +42,8 @@ class CategoryDestroyService
{
try {
$category->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete category: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
// also delete all relations between categories and transaction journals:
diff --git a/app/Services/Internal/Destroy/CurrencyDestroyService.php b/app/Services/Internal/Destroy/CurrencyDestroyService.php
index 358f223246..53bf9026ff 100644
--- a/app/Services/Internal/Destroy/CurrencyDestroyService.php
+++ b/app/Services/Internal/Destroy/CurrencyDestroyService.php
@@ -42,8 +42,8 @@ class CurrencyDestroyService
try {
$currency->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::error(sprintf('Could not delete transaction currency: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Services/Internal/Destroy/JournalDestroyService.php b/app/Services/Internal/Destroy/JournalDestroyService.php
index 321c3be0ae..841f39a89b 100644
--- a/app/Services/Internal/Destroy/JournalDestroyService.php
+++ b/app/Services/Internal/Destroy/JournalDestroyService.php
@@ -96,8 +96,8 @@ class JournalDestroyService
}
}
- } catch (Exception $e) {
- Log::error(sprintf('Could not delete bill: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Services/Internal/Destroy/RecurrenceDestroyService.php b/app/Services/Internal/Destroy/RecurrenceDestroyService.php
index 3f7ce76bc7..efa7d95f46 100644
--- a/app/Services/Internal/Destroy/RecurrenceDestroyService.php
+++ b/app/Services/Internal/Destroy/RecurrenceDestroyService.php
@@ -60,8 +60,8 @@ class RecurrenceDestroyService
try {
// delete all meta data
$recurrence->recurrenceMeta()->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::info(sprintf('Could not delete recurrence meta: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
// delete all transactions.
/** @var RecurrenceTransaction $transaction */
@@ -69,8 +69,8 @@ class RecurrenceDestroyService
$transaction->recurrenceTransactionMeta()->delete();
try {
$transaction->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::info(sprintf('Could not delete recurrence transaction: %s', $e->getMessage())); // @codeCoverageIgnore
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
// delete all repetitions
@@ -79,8 +79,8 @@ class RecurrenceDestroyService
// delete recurrence
try {
$recurrence->delete();
- } catch (Exception $e) { // @codeCoverageIgnore
- Log::info(sprintf('Could not delete recurrence: %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 d9dabfed91..8b1a2fcd2e 100644
--- a/app/Services/Internal/Support/AccountServiceTrait.php
+++ b/app/Services/Internal/Support/AccountServiceTrait.php
@@ -162,8 +162,8 @@ trait AccountServiceTrait
if (null !== $dbNote) {
try {
$dbNote->delete();
- } catch (Exception $e) {
- Log::debug($e->getMessage());
+ } catch (Exception $e) { // @phpstan-ignore-line
+ // @ignoreException
}
}
diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php
index 7ea4dcef2b..f7d031f15a 100644
--- a/app/Support/Preferences.php
+++ b/app/Support/Preferences.php
@@ -260,7 +260,7 @@ class Preferences
{
$fullName = sprintf('preference%s%s', $user->id, $name);
Cache::forget($fullName);
- /** @var Preference $pref */
+ /** @var Preference|null $pref */
$pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']);
if (null !== $pref && null === $value) {
@@ -277,6 +277,8 @@ class Preferences
}
if(null === $pref) {
$pref = new Preference;
+ $pref->user_id = $user->id;
+ $pref->name = $name;
}
$pref->data = $value;
$pref->save();