diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon index bd0ff5f0c9..71862c7c85 100644 --- a/.ci/phpstan.neon +++ b/.ci/phpstan.neon @@ -10,6 +10,11 @@ parameters: - '#is neither abstract nor final#' - '#has a nullable return type declaration#' - '#with a nullable type declaration#' + - '#with null as default value#' + - + message: '#but containers should not be injected#' + paths: + - ../app/Support/Authentication/RemoteUserGuard.php - message: '#Control structures using switch should not be used.#' paths: @@ -18,6 +23,17 @@ parameters: - ../app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php - ../app/Exceptions/GracefulNotFoundHandler.php - ../app/Generator/Webhook/StandardMessageGenerator.php + - ../app/Support/Amount.php + - ../app/Support/Navigation.php + - ../app/Support/ParseDateString.php + - ../app/Support/Search/AccountSearch.php + - ../app/Support/Search/OperatorQuerySearch.php + - ../app/Support/Twig/General.php + - ../app/Transformers/RecurrenceTransformer.php + - ../app/Validation/AccountValidator.php + - ../app/Validation/RecurrenceValidation.php + - ../app/Validation/TransactionValidation.php + - message: '#Function compact\(\) should not be used#' paths: @@ -32,12 +48,21 @@ parameters: - ../app/Http/Controllers/Account/*.php - ../app/Http/Controllers/Admin/*.php - ../app/Http/Controllers/*.php + - ../app/Support/ExpandedForm.php + - ../app/Support/Form/AccountForm.php + - ../app/Support/Form/CurrencyForm.php + - ../app/Support/Form/FormSupport.php + - + message: '#Either catch a more specific exception#' + paths: + - ../app/Support/Form/FormSupport.php paths: - ../app - ../database - ../routes + - ../config - ../bootstrap/app.php # The level 8 is the highest level. original was 5 - level: 1 + level: 2 diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php index 2ec6c79590..f5aef259a6 100644 --- a/app/Handlers/Events/UserEventHandler.php +++ b/app/Handlers/Events/UserEventHandler.php @@ -251,7 +251,7 @@ class UserEventHandler try { Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url)); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception Log::error($e->getMessage()); throw new FireflyException($e->getMessage(), 0, $e); } @@ -275,7 +275,7 @@ class UserEventHandler $url = route('profile.undo-email-change', [$token->data, $hashed]); try { Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url)); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception Log::error($e->getMessage()); throw new FireflyException($e->getMessage(), 0, $e); } @@ -301,7 +301,7 @@ class UserEventHandler $url = route('invite', [$event->invitee->invite_code]); try { Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url)); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception Log::error($e->getMessage()); throw new FireflyException($e->getMessage(), 0, $e); } diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 835d7ef57c..9baeacb073 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -573,7 +573,7 @@ class GroupCollector implements GroupCollectorInterface $result['date']->setTimezone(config('app.timezone')); $result['created_at']->setTimezone(config('app.timezone')); $result['updated_at']->setTimezone(config('app.timezone')); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception Log::error($e->getMessage()); throw new FireflyException($e->getMessage(), 0, $e); } diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 3edc22846b..d68892d5dd 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -98,8 +98,8 @@ class DebugController extends Controller Log::debug('Call twig:clean...'); try { Artisan::call('twig:clean'); - } catch (Exception $e) { // @phpstan-ignore-line - // @ignoreException + } catch (Exception $e) { // intentional generic exception + throw new FireflyException($e->getMessage(), 0, $e); } Log::debug('Call view:clear...'); @@ -186,11 +186,7 @@ class DebugController extends Controller if ($handler instanceof RotatingFileHandler) { $logFile = $handler->getUrl(); if (null !== $logFile) { - try { - $logContent = file_get_contents($logFile); - } catch (Exception $e) { // @phpstan-ignore-line - // @ignoreException - } + $logContent = file_get_contents($logFile); } } } diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 89cf26a299..f782510a62 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -209,7 +209,7 @@ class InstallController extends Controller Artisan::call($command, $args); Log::debug(Artisan::output()); } - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); } // clear cache as well. diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.php index 2fbea87a78..16f21d0da0 100644 --- a/app/Http/Requests/ReportFormRequest.php +++ b/app/Http/Requests/ReportFormRequest.php @@ -155,7 +155,7 @@ class ReportFormRequest extends FormRequest if (preg_match($pattern, $string)) { try { $date = new Carbon($parts[1]); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception $error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage()); Log::error($error); throw new FireflyException($error, 0, $e); @@ -189,7 +189,7 @@ class ReportFormRequest extends FormRequest if (preg_match($pattern, $string)) { try { $date = new Carbon($parts[0]); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception $error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage()); Log::error($error); throw new FireflyException($error, 0, $e); diff --git a/app/Jobs/MailError.php b/app/Jobs/MailError.php index da66694e08..7805fb5d22 100644 --- a/app/Jobs/MailError.php +++ b/app/Jobs/MailError.php @@ -90,7 +90,7 @@ class MailError extends Job implements ShouldQueue } } ); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); } } diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 8bc336d545..9782412436 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -31,8 +31,6 @@ use FireflyIII\Helpers\Attachments\AttachmentHelper; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelper; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; -use FireflyIII\Helpers\Help\Help; -use FireflyIII\Helpers\Help\HelpInterface; use FireflyIII\Helpers\Report\NetWorth; use FireflyIII\Helpers\Report\NetWorthInterface; use FireflyIII\Helpers\Report\PopupReport; @@ -217,7 +215,6 @@ class FireflyServiceProvider extends ServiceProvider // more generators: $this->app->bind(PopupReportInterface::class, PopupReport::class); - $this->app->bind(HelpInterface::class, Help::class); $this->app->bind(ReportHelperInterface::class, ReportHelper::class); $this->app->bind(FiscalHelperInterface::class, FiscalHelper::class); $this->app->bind(UpdateRequestInterface::class, UpdateRequest::class); diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.php index e314f23551..bdd7d4b73c 100644 --- a/app/Repositories/Budget/BudgetLimitRepository.php +++ b/app/Repositories/Budget/BudgetLimitRepository.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Budget; use Carbon\Carbon; -use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionCurrencyFactory; use FireflyIII\Models\Budget; @@ -124,11 +123,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface */ public function destroyBudgetLimit(BudgetLimit $budgetLimit): void { - try { - $budgetLimit->delete(); - } catch (Exception $e) { - // @ignoreException - } + $budgetLimit->delete(); } /** @@ -424,11 +419,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface // 1 if the left_operand is larger than the right_operand, -1 otherwise. if (null !== $limit && bccomp($amount, '0') <= 0) { Log::debug(sprintf('%s is zero, delete budget limit #%d', $amount, $limit->id)); - try { - $limit->delete(); - } catch (Exception $e) { - // @ignoreException - } + $limit->delete(); return null; } diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 549d7487b9..4ba3a787ce 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -207,11 +207,7 @@ class BudgetRepository implements BudgetRepositoryInterface public function cleanupBudgets(): bool { // delete limits with amount 0: - try { - BudgetLimit::where('amount', 0)->delete(); - } catch (Exception $e) { - // @ignoreException - } + BudgetLimit::where('amount', 0)->delete(); $budgets = $this->getActiveBudgets(); /** * @var int $index @@ -335,11 +331,7 @@ class BudgetRepository implements BudgetRepositoryInterface return; } if (null !== $dbNote) { - try { $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } } } diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index 84092ab31b..4f983d051e 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -117,7 +117,7 @@ class OperationsRepository implements OperationsRepositoryInterface 'entries' => [], ]; $date = $journal['date']->format($carbonFormat); - $data[$key]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $journal['amount']); + $data[$key]['entries'][$date] = bcadd($data[$key]['entries'][$date] ?? '0', $journal['amount']); } return $data; diff --git a/app/Repositories/Journal/JournalCLIRepository.php b/app/Repositories/Journal/JournalCLIRepository.php index 3395fe3d66..c12473dfb8 100644 --- a/app/Repositories/Journal/JournalCLIRepository.php +++ b/app/Repositories/Journal/JournalCLIRepository.php @@ -25,7 +25,6 @@ namespace FireflyIII\Repositories\Journal; use Carbon\Carbon; use DB; -use Exception; use FireflyIII\Models\TransactionJournal; use FireflyIII\Support\CacheProperties; use FireflyIII\User; @@ -124,28 +123,15 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface if ($cache->has()) { $result = null; - try { - $result = new Carbon($cache->get()); - } catch (Exception $e) { - // @ignoreException - } - - return $result; + return new Carbon($cache->get()); } $entry = $journal->transactionJournalMeta()->where('name', $field)->first(); if (null === $entry) { return null; } - $value = null; - try { - $value = new Carbon($entry->data); - } catch (Exception $e) { - // @ignoreException - } - if (null !== $value) { - $cache->store($value); - } + $value = new Carbon($entry->data); + $cache->store($value); return $value; } @@ -185,11 +171,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface // return when something else: $return = (string)$value; - try { - $cache->store($return); - } catch (Exception $e) { - // @ignoreException - } + $cache->store($return); return $return; } diff --git a/app/Repositories/LinkType/LinkTypeRepository.php b/app/Repositories/LinkType/LinkTypeRepository.php index 2ed6402451..d1578db0df 100644 --- a/app/Repositories/LinkType/LinkTypeRepository.php +++ b/app/Repositories/LinkType/LinkTypeRepository.php @@ -331,13 +331,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface return; } - if (null !== $dbNote && '' === $text) { - try { - $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } - } + $dbNote?->delete(); } /** diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index dff0581e6f..4f403150af 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -339,13 +339,7 @@ trait ModifiesPiggyBanks { if ('' === $note) { $dbNote = $piggyBank->notes()->first(); - if (null !== $dbNote) { - try { - $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } - } + $dbNote?->delete(); return true; } diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php index 52bf6d61eb..a579ee0783 100644 --- a/app/Services/Internal/Destroy/AccountDestroyService.php +++ b/app/Services/Internal/Destroy/AccountDestroyService.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Destroy; use DB; -use Exception; use FireflyIII\Models\Account; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\RecurrenceTransaction; @@ -68,11 +67,7 @@ class AccountDestroyService // delete account meta: $account->accountMeta()->delete(); // delete account. - try { - $account->delete(); - } catch (Exception $e) { - // @ignoreException - } + $account->delete(); } /** diff --git a/app/Services/Internal/Destroy/BillDestroyService.php b/app/Services/Internal/Destroy/BillDestroyService.php index 48e53f0b8b..929242a6b7 100644 --- a/app/Services/Internal/Destroy/BillDestroyService.php +++ b/app/Services/Internal/Destroy/BillDestroyService.php @@ -37,10 +37,6 @@ class BillDestroyService */ public function destroy(Bill $bill): void { - try { $bill->delete(); - } catch (Exception $e) { - // @ignoreException - } } } diff --git a/app/Services/Internal/Destroy/BudgetDestroyService.php b/app/Services/Internal/Destroy/BudgetDestroyService.php index df0b279b99..fe6bbd1126 100644 --- a/app/Services/Internal/Destroy/BudgetDestroyService.php +++ b/app/Services/Internal/Destroy/BudgetDestroyService.php @@ -39,11 +39,7 @@ class BudgetDestroyService */ public function destroy(Budget $budget): void { - try { $budget->delete(); - } catch (Exception $e) { - // @ignoreException - } // also delete auto budget: foreach ($budget->autoBudgets()->get() as $autoBudget) { diff --git a/app/Services/Internal/Destroy/CategoryDestroyService.php b/app/Services/Internal/Destroy/CategoryDestroyService.php index f79ec91050..376ba11e60 100644 --- a/app/Services/Internal/Destroy/CategoryDestroyService.php +++ b/app/Services/Internal/Destroy/CategoryDestroyService.php @@ -39,11 +39,7 @@ class CategoryDestroyService */ public function destroy(Category $category): void { - try { $category->delete(); - } catch (Exception $e) { - // @ignoreException - } // also delete all relations between categories and transaction journals: DB::table('category_transaction_journal')->where('category_id', (int)$category->id)->delete(); diff --git a/app/Services/Internal/Destroy/CurrencyDestroyService.php b/app/Services/Internal/Destroy/CurrencyDestroyService.php index bbaab9d043..a62dc2a070 100644 --- a/app/Services/Internal/Destroy/CurrencyDestroyService.php +++ b/app/Services/Internal/Destroy/CurrencyDestroyService.php @@ -38,10 +38,6 @@ class CurrencyDestroyService */ public function destroy(TransactionCurrency $currency): void { - try { $currency->delete(); - } catch (Exception $e) { - // @ignoreException - } } } diff --git a/app/Services/Internal/Destroy/JournalDestroyService.php b/app/Services/Internal/Destroy/JournalDestroyService.php index 3d52a1c108..ba8de40a1b 100644 --- a/app/Services/Internal/Destroy/JournalDestroyService.php +++ b/app/Services/Internal/Destroy/JournalDestroyService.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Destroy; use DB; -use Exception; use FireflyIII\Models\Attachment; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; @@ -43,61 +42,57 @@ class JournalDestroyService */ public function destroy(TransactionJournal $journal): void { - try { - /** @var Transaction $transaction */ - foreach ($journal->transactions()->get() as $transaction) { - Log::debug(sprintf('Will now delete transaction #%d', $transaction->id)); - $transaction->delete(); + /** @var Transaction $transaction */ + foreach ($journal->transactions()->get() as $transaction) { + Log::debug(sprintf('Will now delete transaction #%d', $transaction->id)); + $transaction->delete(); + } + + // also delete journal_meta entries. + /** @var TransactionJournalMeta $meta */ + foreach ($journal->transactionJournalMeta()->get() as $meta) { + Log::debug(sprintf('Will now delete meta-entry #%d', $meta->id)); + $meta->delete(); + } + + // also delete attachments. + /** @var Attachment $attachment */ + foreach ($journal->attachments()->get() as $attachment) { + $attachment->delete(); + } + + // delete all from 'budget_transaction_journal' + DB::table('budget_transaction_journal') + ->where('transaction_journal_id', $journal->id)->delete(); + + // delete all from 'category_transaction_journal' + DB::table('category_transaction_journal') + ->where('transaction_journal_id', $journal->id)->delete(); + + // delete all from 'tag_transaction_journal' + DB::table('tag_transaction_journal') + ->where('transaction_journal_id', $journal->id)->delete(); + + // delete all links: + TransactionJournalLink::where('source_id', $journal->id)->delete(); + TransactionJournalLink::where('destination_id', $journal->id)->delete(); + + // delete all notes + $journal->notes()->delete(); + + // update events + // TODO move to repository + $journal->piggyBankEvents()->update(['transaction_journal_id' => null]); + + $journal->delete(); + + // delete group, if group is empty: + $group = $journal->transactionGroup; + if (null !== $group) { + $count = $group->transactionJournals->count(); + if (0 === $count) { + $group->delete(); } - - // also delete journal_meta entries. - /** @var TransactionJournalMeta $meta */ - foreach ($journal->transactionJournalMeta()->get() as $meta) { - Log::debug(sprintf('Will now delete meta-entry #%d', $meta->id)); - $meta->delete(); - } - - // also delete attachments. - /** @var Attachment $attachment */ - foreach ($journal->attachments()->get() as $attachment) { - $attachment->delete(); - } - - // delete all from 'budget_transaction_journal' - DB::table('budget_transaction_journal') - ->where('transaction_journal_id', $journal->id)->delete(); - - // delete all from 'category_transaction_journal' - DB::table('category_transaction_journal') - ->where('transaction_journal_id', $journal->id)->delete(); - - // delete all from 'tag_transaction_journal' - DB::table('tag_transaction_journal') - ->where('transaction_journal_id', $journal->id)->delete(); - - // delete all links: - TransactionJournalLink::where('source_id', $journal->id)->delete(); - TransactionJournalLink::where('destination_id', $journal->id)->delete(); - - // delete all notes - $journal->notes()->delete(); - - // update events - // TODO move to repository - $journal->piggyBankEvents()->update(['transaction_journal_id' => null]); - - $journal->delete(); - - // delete group, if group is empty: - $group = $journal->transactionGroup; - if (null !== $group) { - $count = $group->transactionJournals->count(); - if (0 === $count) { - $group->delete(); - } - } - } catch (Exception $e) { - // @ignoreException } } } diff --git a/app/Services/Internal/Destroy/RecurrenceDestroyService.php b/app/Services/Internal/Destroy/RecurrenceDestroyService.php index d010737f1a..88fbb27376 100644 --- a/app/Services/Internal/Destroy/RecurrenceDestroyService.php +++ b/app/Services/Internal/Destroy/RecurrenceDestroyService.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Destroy; -use Exception; use FireflyIII\Models\Recurrence; use FireflyIII\Models\RecurrenceTransaction; @@ -55,30 +54,18 @@ class RecurrenceDestroyService */ public function destroy(Recurrence $recurrence): void { - try { - // delete all meta data - $recurrence->recurrenceMeta()->delete(); - } catch (Exception $e) { - // @ignoreException - } + // delete all meta data + $recurrence->recurrenceMeta()->delete(); // delete all transactions. /** @var RecurrenceTransaction $transaction */ foreach ($recurrence->recurrenceTransactions as $transaction) { $transaction->recurrenceTransactionMeta()->delete(); - try { - $transaction->delete(); - } catch (Exception $e) { - // @ignoreException - } + $transaction->delete(); } // delete all repetitions $recurrence->recurrenceRepetitions()->delete(); // delete recurrence - try { - $recurrence->delete(); - } catch (Exception $e) { - // @ignoreException - } + $recurrence->delete(); } } diff --git a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php index cbd4bfcfa9..2f99a0e941 100644 --- a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php +++ b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Destroy; -use Exception; use FireflyIII\Events\DestroyedTransactionGroup; use FireflyIII\Models\TransactionGroup; @@ -44,11 +43,7 @@ class TransactionGroupDestroyService foreach ($transactionGroup->transactionJournals as $journal) { $service->destroy($journal); } - try { - $transactionGroup->delete(); - } catch (Exception $e) { - // @ignoreException - } + $transactionGroup->delete(); // trigger just after destruction event(new DestroyedTransactionGroup($transactionGroup)); } diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index 16a77f63e3..3f9507ee46 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Support; use Carbon\Carbon; -use Exception; use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountMetaFactory; @@ -173,11 +172,7 @@ trait AccountServiceTrait if ('' === $note) { $dbNote = $account->notes()->first(); if (null !== $dbNote) { - try { - $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } + $dbNote->delete(); } return true; diff --git a/app/Services/Internal/Support/BillServiceTrait.php b/app/Services/Internal/Support/BillServiceTrait.php index 98e17fe510..b790330ff4 100644 --- a/app/Services/Internal/Support/BillServiceTrait.php +++ b/app/Services/Internal/Support/BillServiceTrait.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Support; -use Exception; use FireflyIII\Models\Bill; use FireflyIII\Models\Note; use FireflyIII\Models\RuleAction; @@ -70,11 +69,7 @@ trait BillServiceTrait if ('' === $note) { $dbNote = $bill->notes()->first(); if (null !== $dbNote) { - try { - $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } + $dbNote->delete(); } return true; diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php index dfddffd7ac..ba96fffa78 100644 --- a/app/Services/Internal/Support/JournalServiceTrait.php +++ b/app/Services/Internal/Support/JournalServiceTrait.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Support; -use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Factory\TagFactory; @@ -395,11 +394,7 @@ trait JournalServiceTrait } if ('' === $notes && null !== $note) { // try to delete existing notes. - try { - $note->delete(); - } catch (Exception $e) { - // @ignoreException - } + $note->delete(); } } diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index c3b0665c23..a6701c49a3 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -61,11 +61,7 @@ trait RecurringTransactionTrait if ('' === $note) { $dbNote = $recurrence->notes()->first(); if (null !== $dbNote) { - try { $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } } return true; @@ -376,11 +372,9 @@ trait RecurringTransactionTrait /** @var RecurrenceTransaction $transaction */ foreach ($recurrence->recurrenceTransactions as $transaction) { $transaction->recurrenceTransactionMeta()->delete(); - try { + $transaction->delete(); - } catch (Exception $e) { - // @ignoreException - } + } } } diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php index e50e2c24be..5d01c99bf7 100644 --- a/app/Services/Internal/Update/CategoryUpdateService.php +++ b/app/Services/Internal/Update/CategoryUpdateService.php @@ -153,11 +153,9 @@ class CategoryUpdateService if ('' === $note) { $dbNote = $category->notes()->first(); if (null !== $dbNote) { - try { + $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } + } return; diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php index b670ebdbdd..4b06e72366 100644 --- a/app/Services/Internal/Update/JournalUpdateService.php +++ b/app/Services/Internal/Update/JournalUpdateService.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Update; use Carbon\Carbon; +use Carbon\Exceptions\InvalidDateException; use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TagFactory; @@ -652,9 +653,8 @@ class JournalUpdateService if ($this->hasFields([$field])) { try { $value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]); - } catch (Exception $e) { + } catch (InvalidDateException $e) { Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage())); - return; } Log::debug(sprintf('Field "%s" is present ("%s"), try to update it.', $field, $value)); diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index 329eff9886..03f9a73874 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -132,11 +132,7 @@ class RecurrenceUpdateService return; } if (null !== $dbNote && '' === $text) { - try { $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } } } diff --git a/app/Services/Password/PwndVerifierV2.php b/app/Services/Password/PwndVerifierV2.php index 39bee2ca32..c4396f4cae 100644 --- a/app/Services/Password/PwndVerifierV2.php +++ b/app/Services/Password/PwndVerifierV2.php @@ -27,7 +27,6 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\RequestException; use Log; -use RuntimeException; /** * Class PwndVerifierV2. @@ -73,12 +72,7 @@ class PwndVerifierV2 implements Verifier if (404 === $res->getStatusCode()) { return true; } - try { - $strpos = stripos($res->getBody()->getContents(), $rest); - } catch (RuntimeException $e) { - Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage())); - $strpos = false; - } + $strpos = stripos($res->getBody()->getContents(), $rest); if (false === $strpos) { Log::debug(sprintf('%s was not found in result body. Return true.', $rest)); diff --git a/app/Support/Authentication/RemoteUserGuard.php b/app/Support/Authentication/RemoteUserGuard.php index 8c9e5e5a40..46e63875a0 100644 --- a/app/Support/Authentication/RemoteUserGuard.php +++ b/app/Support/Authentication/RemoteUserGuard.php @@ -124,9 +124,9 @@ class RemoteUserGuard implements Guard /** * @inheritDoc */ - public function hasUser() + public function hasUser(): bool { - // TODO: Implement hasUser() method. + throw new FireflyException(sprintf('%s is not implemented', __METHOD__)); } /** diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index 538746df47..e9eebb4340 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Binder; use Carbon\Carbon; -use Exception; +use Carbon\Exceptions\InvalidDateException; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use Illuminate\Routing\Route; use Log; @@ -72,9 +72,10 @@ class Date implements BinderInterface try { $result = new Carbon($value); - } catch (Exception $e) { - Log::error(sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage())); - throw new NotFoundHttpException(); + } catch (InvalidDateException $e) { + $message = sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage()); + Log::error($message); + throw new NotFoundHttpException($message, $e); } return $result; diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index 23ca937c53..0729961773 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -53,6 +53,7 @@ use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\User; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use League\Csv\CannotInsertRecord; use League\Csv\Exception; use League\Csv\Writer; @@ -206,7 +207,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -280,7 +282,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -344,7 +347,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -392,7 +396,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -469,7 +474,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -630,7 +636,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -758,7 +765,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -810,7 +818,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -952,7 +961,8 @@ class ExportDataGenerator try { $string = $csv->toString(); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception + Log::error($e->getMessage()); throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e); } @@ -1072,4 +1082,20 @@ class ExportDataGenerator { $this->start = $start; } + + /** + * @inheritDoc + */ + public function get(string $key, mixed $default = null): mixed + { + return null; + } + + /** + * @inheritDoc + */ + public function has(mixed $key): mixed + { + return null; + } } diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index 2421bb6065..90ca98e25a 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -28,6 +28,7 @@ use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Configuration; use Illuminate\Database\QueryException; +use Log; /** * Class FireflyConfig. @@ -45,11 +46,7 @@ class FireflyConfig if (Cache::has($fullName)) { Cache::forget($fullName); } - try { Configuration::where('name', $name)->forceDelete(); - } catch (Exception $e) { - // @ignoreException - } } /** @@ -80,7 +77,7 @@ class FireflyConfig /** @var Configuration|null $config */ $config = Configuration::where('name', $name)->first(['id', 'name', 'data']); } catch (QueryException|Exception $e) { - throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage())); + throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage()), 0, $e); } if (null !== $config) { @@ -106,7 +103,8 @@ class FireflyConfig { try { $config = Configuration::whereName($name)->whereNull('deleted_at')->first(); - } catch (QueryException|Exception $e) { + } catch (QueryException $e) { + Log::error($e->getMessage()); $item = new Configuration(); $item->name = $name; $item->data = $value; diff --git a/app/Support/Form/FormSupport.php b/app/Support/Form/FormSupport.php index 80b9390d1c..cfcb34f661 100644 --- a/app/Support/Form/FormSupport.php +++ b/app/Support/Form/FormSupport.php @@ -24,11 +24,10 @@ declare(strict_types=1); namespace FireflyIII\Support\Form; use Carbon\Carbon; -use Exception; +use Carbon\Exceptions\InvalidDateException; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Support\MessageBag; use Log; -use RuntimeException; use Throwable; /** @@ -130,13 +129,8 @@ trait FormSupport $value = array_key_exists($name, $preFilled) && null === $value ? $preFilled[$name] : $value; } - try { - if (null !== request()->old($name)) { - $value = request()->old($name); - } - } catch (RuntimeException $e) { - // don't care about session errors. - Log::debug(sprintf('Run time: %s', $e->getMessage())); + if (null !== request()->old($name)) { + $value = request()->old($name); } if ($value instanceof Carbon) { @@ -163,8 +157,8 @@ trait FormSupport $date = null; try { $date = today(config('app.timezone')); - } catch (Exception $e) { - // @ignoreException + } catch (InvalidDateException $e) { + Log::error($e->getMessage()); } return $date; diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index 99e98c590b..60d1d2e5c6 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -415,7 +415,7 @@ trait PeriodOverview $range = app('preferences')->get('viewRange', '1M')->data; $first = $this->journalRepos->firstNull(); $start = null === $first ? new Carbon() : $first->date; - $end = $theDate ?? today(config('app.timezone')); + $end = clone $theDate; Log::debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d'))); Log::debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d'))); diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 26ac764273..31266f2bca 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -654,17 +654,17 @@ class Navigation return $fiscalHelper->endOfFiscalYear($end); } - switch ($range) { - default: - break; - case 'last7': - case 'last30': - case 'last90': - case 'last365': - case 'YTD': - case 'QTD': - case 'MTD': - return $end; + $list = [ + 'last7', + 'last30', + 'last90', + 'last365', + 'YTD', + 'QTD', + 'MTD', + ]; + if (in_array($range, $list, true)) { + return $end; } throw new FireflyException(sprintf('updateEndDate cannot handle range "%s"', $range)); diff --git a/app/Support/NullArrayObject.php b/app/Support/NullArrayObject.php index 061bceba6b..144bc1bb7d 100644 --- a/app/Support/NullArrayObject.php +++ b/app/Support/NullArrayObject.php @@ -40,6 +40,7 @@ class NullArrayObject extends ArrayObject * @param array $array * @param null $default */ + /* @phpstan-ignore-next-line */ public function __construct(array $array, $default = null) { parent::__construct($array); @@ -49,9 +50,9 @@ class NullArrayObject extends ArrayObject /** * @param mixed $key * - * @return mixed|null + * @return mixed */ - public function offsetGet($key) + public function offsetGet($key): mixed { if ($this->offsetExists($key)) { return parent::offsetGet($key); diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 78c7dfedfd..4d43830659 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -85,11 +85,7 @@ class Preferences { $preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']); if (null !== $preference && null === $preference->data) { - try { - $preference->delete(); - } catch (Exception $e) { - throw new FireflyException(sprintf('Could not delete preference #%d: %s', $preference->id, $e->getMessage()), 0, $e); - } + $preference->delete(); $preference = null; } @@ -117,11 +113,7 @@ class Preferences if (Cache::has($fullName)) { Cache::forget($fullName); } - try { Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); - } catch (Exception $e) { - throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); - } return true; } @@ -153,11 +145,7 @@ class Preferences $pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']); if (null !== $pref && null === $value) { - try { $pref->delete(); - } catch (Exception $e) { - throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); - } return new Preference(); } diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php index e91c4bbc4d..d5d5e0541d 100644 --- a/app/Support/Request/ConvertsDataTypes.php +++ b/app/Support/Request/ConvertsDataTypes.php @@ -32,6 +32,24 @@ use Log; */ trait ConvertsDataTypes { + /** + * Abstract method that always exists in the Request classes that use this + * trait, OR a stub needs to be added by any other class that uses this train. + * + * @param string $key + * @param mixed|null $default + * @return mixed + */ + abstract public function get(string $key, mixed $default = null): mixed; + + /** + * Abstract method that always exists in the Request classes that use this + * trait, OR a stub needs to be added by any other class that uses this train. + * + * @param mixed $key + * @return mixed + */ + abstract public function has(mixed $key): mixed; /** * Return integer value. * diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 2f6d149479..c29472bcbf 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -678,7 +678,7 @@ class Steam { try { $hostName = gethostbyaddr($ipAddress); - } catch (Exception $e) { + } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); } return $hostName; diff --git a/app/TransactionRules/Actions/AppendNotesToDescription.php b/app/TransactionRules/Actions/AppendNotesToDescription.php index 9ca6fdaa7a..387c1e87b2 100644 --- a/app/TransactionRules/Actions/AppendNotesToDescription.php +++ b/app/TransactionRules/Actions/AppendNotesToDescription.php @@ -82,4 +82,20 @@ class AppendNotesToDescription implements ActionInterface } return false; } + + /** + * @inheritDoc + */ + public function get(string $key, mixed $default = null): mixed + { + return null; + } + + /** + * @inheritDoc + */ + public function has(mixed $key): mixed + { + return null; + } } diff --git a/app/TransactionRules/Actions/MoveNotesToDescription.php b/app/TransactionRules/Actions/MoveNotesToDescription.php index 0825d17885..0410b9998b 100644 --- a/app/TransactionRules/Actions/MoveNotesToDescription.php +++ b/app/TransactionRules/Actions/MoveNotesToDescription.php @@ -80,4 +80,20 @@ class MoveNotesToDescription implements ActionInterface return true; } + + /** + * @inheritDoc + */ + public function get(string $key, mixed $default = null): mixed + { + return null; + } + + /** + * @inheritDoc + */ + public function has(mixed $key): mixed + { + return null; + } } diff --git a/app/Validation/Account/DepositValidation.php b/app/Validation/Account/DepositValidation.php index 917b80b0d4..d315f65e3b 100644 --- a/app/Validation/Account/DepositValidation.php +++ b/app/Validation/Account/DepositValidation.php @@ -74,7 +74,6 @@ trait DepositValidation $result = true; } } - $result = $result ?? false; Log::debug(sprintf('validateDepositDestination will return %s', var_export($result, true))); return $result; diff --git a/app/Validation/Account/OBValidation.php b/app/Validation/Account/OBValidation.php index bf58b9cee0..9f738c7b6c 100644 --- a/app/Validation/Account/OBValidation.php +++ b/app/Validation/Account/OBValidation.php @@ -74,7 +74,6 @@ trait OBValidation $result = true; } } - $result = $result ?? false; Log::debug(sprintf('validateOBDestination(%d, "%s") will return %s', $accountId, $accountName, var_export($result, true))); return $result; diff --git a/config/logging.php b/config/logging.php index ada1fbc874..4b1369bcd8 100644 --- a/config/logging.php +++ b/config/logging.php @@ -62,10 +62,6 @@ return [ 'driver' => 'stack', 'channels' => ['audit_daily', 'audit_stdout'], ], - 'scoped' => [ - 'driver' => 'custom', - 'via' => FireflyIII\Logging\CreateCustomLogger::class, - ], 'papertrail' => [ 'driver' => 'monolog', 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 3eeed01eb2..d47a5209df 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -1167,7 +1167,7 @@ try { Breadcrumbs::for( 'transactions.mass.edit', static function (Generator $breadcrumbs, array $journals): void { - if (!empty($journals)) { + if (0 !== count($journals)) { $objectType = strtolower(reset($journals)['transaction_type_type']); $breadcrumbs->parent('transactions.index', $objectType); $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', [''])); @@ -1191,7 +1191,7 @@ try { Breadcrumbs::for( 'transactions.bulk.edit', static function (Generator $breadcrumbs, array $journals): void { - if (!empty($journals)) { + if (0 !== count($journals)) { $ids = Arr::pluck($journals, 'transaction_journal_id'); $first = reset($journals); $breadcrumbs->parent('transactions.index', strtolower($first['transaction_type_type']));