From f16b679049a0309193b31c9e6f8df7c2feadf38c Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 4 Nov 2022 05:11:05 +0100 Subject: [PATCH] Various code fixes. --- .ci/phpstan.neon | 4 + .../Report/Audit/MonthReportGenerator.php | 2 +- .../Report/Budget/MonthReportGenerator.php | 2 +- .../Report/Category/MonthReportGenerator.php | 4 +- app/Handlers/Events/UserEventHandler.php | 32 ++-- app/Helpers/Collector/GroupCollector.php | 4 +- .../Controllers/Account/CreateController.php | 27 ++-- .../Controllers/Account/IndexController.php | 2 - .../Account/ReconcileController.php | 2 +- .../Controllers/Account/ShowController.php | 2 +- app/Http/Controllers/Auth/LoginController.php | 2 - .../Auth/ResetPasswordController.php | 2 +- .../Controllers/Budget/IndexController.php | 4 +- .../Controllers/Budget/ShowController.php | 2 +- .../Category/NoCategoryController.php | 2 +- .../Controllers/Category/ShowController.php | 2 +- .../Controllers/Chart/AccountController.php | 138 +++++++++--------- .../Controllers/Chart/BudgetController.php | 6 +- .../Controllers/Chart/CategoryController.php | 46 +++--- .../Chart/DoubleReportController.php | 4 +- .../Chart/ExpenseReportController.php | 2 +- .../Chart/TransactionController.php | 69 ++++----- app/Http/Controllers/DebugController.php | 4 +- app/Http/Controllers/Json/BoxController.php | 2 +- .../Controllers/Json/FrontpageController.php | 2 +- app/Http/Controllers/Json/IntroController.php | 8 +- .../Controllers/Json/ReconcileController.php | 4 +- .../Controllers/PreferencesController.php | 2 +- .../Controllers/Report/CategoryController.php | 4 +- .../Controllers/Report/DoubleController.php | 8 +- .../Controllers/Rule/SelectController.php | 8 +- app/Http/Middleware/Authenticate.php | 2 +- app/Models/TransactionJournal.php | 2 +- .../Account/AccountRepository.php | 24 +-- .../Recurring/RecurringRepository.php | 2 +- .../Support/CreditRecalculateService.php | 4 +- .../Support/RecurringTransactionTrait.php | 4 +- .../Internal/Update/GroupUpdateService.php | 4 +- .../Update/RecurrenceUpdateService.php | 4 +- app/Support/Binder/BudgetList.php | 2 +- app/Support/Binder/CategoryList.php | 2 +- app/Support/Binder/JournalList.php | 4 +- app/Support/Binder/TagList.php | 2 +- app/Support/Export/ExportDataGenerator.php | 2 +- app/Support/Search/OperatorQuerySearch.php | 2 +- .../Factory/ActionFactory.php | 2 +- app/Validation/RecurrenceValidation.php | 4 +- app/Validation/TransactionValidation.php | 4 +- 48 files changed, 226 insertions(+), 246 deletions(-) diff --git a/.ci/phpstan.neon b/.ci/phpstan.neon index c29cf42db9..bd0ff5f0c9 100644 --- a/.ci/phpstan.neon +++ b/.ci/phpstan.neon @@ -17,6 +17,7 @@ parameters: - ../app/Console/Commands/Correction/FixAccountTypes.php - ../app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php - ../app/Exceptions/GracefulNotFoundHandler.php + - ../app/Generator/Webhook/StandardMessageGenerator.php - message: '#Function compact\(\) should not be used#' paths: @@ -28,6 +29,9 @@ parameters: - ../app/Generator/Report/Standard/MultiYearReportGenerator.php - ../app/Generator/Report/Standard/YearReportGenerator.php - ../app/Generator/Report/Tag/MonthReportGenerator.php + - ../app/Http/Controllers/Account/*.php + - ../app/Http/Controllers/Admin/*.php + - ../app/Http/Controllers/*.php paths: - ../app diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php index 167170128a..1c03c57c36 100644 --- a/app/Generator/Report/Audit/MonthReportGenerator.php +++ b/app/Generator/Report/Audit/MonthReportGenerator.php @@ -156,7 +156,7 @@ class MonthReportGenerator implements ReportGeneratorInterface return [ 'journals' => $journals, 'currency' => $currency, - 'exists' => !empty($journals), + 'exists' => 0 !== count($journals), 'end' => $this->end->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)), 'endBalance' => app('steam')->balance($account, $this->end), 'dayBefore' => $date->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)), diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.php index 9d887a714c..f0874d2355 100644 --- a/app/Generator/Report/Budget/MonthReportGenerator.php +++ b/app/Generator/Report/Budget/MonthReportGenerator.php @@ -180,7 +180,7 @@ class MonthReportGenerator implements ReportGeneratorInterface */ protected function getExpenses(): array { - if (!empty($this->expenses)) { + if (0 !== count($this->expenses)) { Log::debug('Return previous set of expenses.'); return $this->expenses; diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.php index 855827f0fb..2d0ba5d3b8 100644 --- a/app/Generator/Report/Category/MonthReportGenerator.php +++ b/app/Generator/Report/Category/MonthReportGenerator.php @@ -188,7 +188,7 @@ class MonthReportGenerator implements ReportGeneratorInterface */ protected function getExpenses(): array { - if (!empty($this->expenses)) { + if (0 !== count($this->expenses)) { Log::debug('Return previous set of expenses.'); return $this->expenses; @@ -213,7 +213,7 @@ class MonthReportGenerator implements ReportGeneratorInterface */ protected function getIncome(): array { - if (!empty($this->income)) { + if (0 !== count($this->income)) { return $this->income; } diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php index 2d2d377ba1..39bb8cf8f8 100644 --- a/app/Handlers/Events/UserEventHandler.php +++ b/app/Handlers/Events/UserEventHandler.php @@ -1,4 +1,5 @@ email; $index = 1; + /** @var UserGroup $group */ + $group = null; // create a new group. while (true === $groupExists) { @@ -163,6 +166,7 @@ class UserEventHandler throw new FireflyException('Email address can no longer be used for registrations.'); } } + /** @var UserRole $role */ $role = UserRole::where('title', UserRole::OWNER)->first(); if (null === $role) { throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?'); @@ -181,7 +185,7 @@ class UserEventHandler /** * Set the demo user back to English. * - * @param Login $event + * @param Login $event * * @throws FireflyException */ @@ -201,7 +205,7 @@ class UserEventHandler } /** - * @param DetectedNewIPAddress $event + * @param DetectedNewIPAddress $event * * @throws FireflyException */ @@ -232,7 +236,7 @@ class UserEventHandler * Send email to confirm email change. Will not be made into a notification, because * this requires some custom fields from the user and not just the "user" object. * - * @param UserChangedEmail $event + * @param UserChangedEmail $event * * @throws FireflyException */ @@ -256,7 +260,7 @@ class UserEventHandler * Send email to be able to undo email change. Will not be made into a notification, because * this requires some custom fields from the user and not just the "user" object. * - * @param UserChangedEmail $event + * @param UserChangedEmail $event * * @throws FireflyException */ @@ -266,7 +270,7 @@ class UserEventHandler $oldEmail = $event->oldEmail; $user = $event->user; $token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid'); - $hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $oldEmail)); + $hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $oldEmail)); $url = route('profile.undo-email-change', [$token->data, $hashed]); try { Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url)); @@ -278,7 +282,7 @@ class UserEventHandler /** * Send a new password to the user. - * @param RequestedNewPassword $event + * @param RequestedNewPassword $event */ public function sendNewPassword(RequestedNewPassword $event): void { @@ -289,7 +293,7 @@ class UserEventHandler * This method will send the user a registration mail, welcoming him or her to Firefly III. * This message is only sent when the configuration of Firefly III says so. * - * @param RegisteredUser $event + * @param RegisteredUser $event * */ public function sendRegistrationMail(RegisteredUser $event): void @@ -301,7 +305,7 @@ class UserEventHandler } /** - * @param RegisteredUser $event + * @param RegisteredUser $event */ public function sendAdminRegistrationNotification(RegisteredUser $event): void { @@ -319,7 +323,7 @@ class UserEventHandler } /** - * @param ActuallyLoggedIn $event + * @param ActuallyLoggedIn $event * @throws FireflyException */ public function storeUserIPAddress(ActuallyLoggedIn $event): void diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index e7f86f0bd2..04389cf846 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -372,7 +372,7 @@ class GroupCollector implements GroupCollectorInterface */ public function excludeJournalIds(array $journalIds): GroupCollectorInterface { - if (!empty($journalIds)) { + if (0 !== count($journalIds)) { // make all integers. $integerIDs = array_map('intval', $journalIds); @@ -894,7 +894,7 @@ class GroupCollector implements GroupCollectorInterface */ public function setJournalIds(array $journalIds): GroupCollectorInterface { - if (!empty($journalIds)) { + if (0 !== count($journalIds)) { // make all integers. $integerIDs = array_map('intval', $journalIds); diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index 9a6d8c9e5e..45a9ce7a73 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -61,7 +61,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string) trans('firefly.accounts')); + app('view')->share('title', (string)trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); $this->attachments = app(AttachmentHelperInterface::class); @@ -74,17 +74,16 @@ class CreateController extends Controller /** * Create a new account. * - * @param Request $request - * @param string|null $objectType + * @param Request $request + * @param string $objectType * * @return Factory|View */ - public function create(Request $request, string $objectType = null) + public function create(Request $request, string $objectType) { - $objectType = $objectType ?? 'asset'; $defaultCurrency = app('amount')->getDefaultCurrency(); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); - $subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType)); + $subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType)); $roles = $this->getRoles(); $liabilityTypes = $this->getLiabilityTypes(); $hasOldInput = null !== $request->old('_token'); @@ -103,9 +102,9 @@ class CreateController extends Controller // interest calculation periods: $interestPeriods = [ - 'daily' => (string) trans('firefly.interest_calc_daily'), - 'monthly' => (string) trans('firefly.interest_calc_monthly'), - 'yearly' => (string) trans('firefly.interest_calc_yearly'), + 'daily' => (string)trans('firefly.interest_calc_daily'), + 'monthly' => (string)trans('firefly.interest_calc_monthly'), + 'yearly' => (string)trans('firefly.interest_calc_yearly'), ]; // pre fill some data @@ -113,7 +112,7 @@ class CreateController extends Controller 'preFilled', [ 'currency_id' => $defaultCurrency->id, - 'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true, + 'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : true, ] ); @@ -133,7 +132,7 @@ class CreateController extends Controller /** * Store the new account. * - * @param AccountFormRequest $request + * @param AccountFormRequest $request * * @return RedirectResponse|Redirector * @throws FireflyException @@ -144,7 +143,7 @@ class CreateController extends Controller { $data = $request->getAccountData(); $account = $this->repository->store($data); - $request->session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name])); + $request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name])); app('preferences')->mark(); Log::channel('audit')->info('Stored new account.', $data); @@ -163,7 +162,7 @@ class CreateController extends Controller $this->attachments->saveAttachmentsForModel($account, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { @@ -172,7 +171,7 @@ class CreateController extends Controller // redirect to previous URL. $redirect = redirect($this->getPreviousUrl('accounts.create.url')); - if (1 === (int) $request->get('create_another')) { + if (1 === (int)$request->get('create_another')) { // set value so create routine will not overwrite URL: $request->session()->put('accounts.create.fromStore', true); diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index 3c981342f9..0ab41fe834 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -79,7 +79,6 @@ class IndexController extends Controller */ public function inactive(Request $request, string $objectType) { - $objectType = $objectType ?? 'asset'; $inactivePage = true; $subTitle = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); @@ -137,7 +136,6 @@ class IndexController extends Controller public function index(Request $request, string $objectType) { Log::debug(sprintf('Now at %s', __METHOD__)); - $objectType = $objectType ?? 'asset'; $subTitle = (string) trans(sprintf('firefly.%s_accounts', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 2d9c04fae6..26b98832d8 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -90,7 +90,7 @@ class ReconcileController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function reconcile(Account $account, Carbon $start = null, Carbon $end = null) + public function reconcile(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line { if (!$this->isEditableAccount($account)) { return $this->redirectAccountToAccount($account); diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 23590af022..ac860dc5ea 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -88,7 +88,7 @@ class ShowController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null) + public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line { $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 1f4b64cfcf..872714bc26 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -81,8 +81,6 @@ class LoginController extends Controller * * @param Request $request * - * @return JsonResponse|RedirectResponse - * * @throws ValidationException */ public function login(Request $request) diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 062b7e973a..af4b3087f4 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -126,7 +126,7 @@ class ResetPasswordController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function showResetForm(Request $request, $token = null) + public function showResetForm(Request $request, $token = null) // @phpstan-ignore-line { $loginProvider = config('firefly.login_provider'); if ('eloquent' !== $loginProvider) { diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index 45b6c3ec8b..801e824309 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -96,7 +96,7 @@ class IndexController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function index(Request $request, Carbon $start = null, Carbon $end = null) + public function index(Request $request, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line { Log::debug('Start of IndexController::index()'); @@ -122,7 +122,7 @@ class IndexController extends Controller $sums = $this->getSums($budgets); // get budgeted for default currency: - if (empty($availableBudgets)) { + if (0 === count($availableBudgets)) { $budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency, ); $spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency); $spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0'; diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index f41c24ecb4..653d247264 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -84,7 +84,7 @@ class ShowController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function noBudget(Request $request, Carbon $start = null, Carbon $end = null) + public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line { /** @var Carbon $start */ $start = $start ?? session('start'); diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php index 268d2a44b3..a8680cfe0c 100644 --- a/app/Http/Controllers/Category/NoCategoryController.php +++ b/app/Http/Controllers/Category/NoCategoryController.php @@ -80,7 +80,7 @@ class NoCategoryController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function show(Request $request, Carbon $start = null, Carbon $end = null) + public function show(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line { Log::debug('Start of noCategory()'); /** @var Carbon $start */ diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php index 346148c78c..adbb693fc9 100644 --- a/app/Http/Controllers/Category/ShowController.php +++ b/app/Http/Controllers/Category/ShowController.php @@ -82,7 +82,7 @@ class ShowController extends Controller * @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface */ - public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) + public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line { /** @var Carbon $start */ $start = $start ?? session('start', Carbon::now()->startOfMonth()); diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 58e1af188f..e233696d3a 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -1,4 +1,5 @@ $expenses) { - $accountId = (int) $accountId; + $accountId = (int)$accountId; // loop each expense entry (each entry can be a different currency). foreach ($expenses as $currencyId => $endAmount) { - $currencyId = (int) $currencyId; + $currencyId = (int)$currencyId; // see if there is an accompanying start amount. // grab the difference and find the currency. - $startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0'); + $startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0'); $diff = bcsub((string)$endAmount, $startAmount); $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId); if (0 !== bccomp($diff, '0')) { @@ -129,7 +130,7 @@ class AccountController extends Controller $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float) $diff, + 'diff_float' => (float)$diff, 'currency_id' => $currencyId, ]; } @@ -142,13 +143,13 @@ class AccountController extends Controller // loop all found currencies and build the data array for the chart. /** - * @var int $currencyId + * @var int $currencyId * @var TransactionCurrency $currency */ foreach ($currencies as $currencyId => $currency) { $dataSet = [ - 'label' => (string) trans('firefly.spent'), + 'label' => (string)trans('firefly.spent'), 'type' => 'bar', 'currency_symbol' => $currency->symbol, 'currency_code' => $currency->code, @@ -173,8 +174,8 @@ class AccountController extends Controller /** * Expenses per budget for all time, as shown on account overview. * - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return JsonResponse * @throws JsonException @@ -190,9 +191,9 @@ class AccountController extends Controller /** * Expenses per budget, as shown on account overview. * - * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Account $account + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -215,7 +216,7 @@ class AccountController extends Controller $budgetIds = []; /** @var array $journal */ foreach ($journals as $journal) { - $budgetId = (int) $journal['budget_id']; + $budgetId = (int)$journal['budget_id']; $key = sprintf('%d-%d', $budgetId, $journal['currency_id']); $budgetIds[] = $budgetId; if (!array_key_exists($key, $result)) { @@ -235,7 +236,7 @@ class AccountController extends Controller foreach ($result as $row) { $budgetId = $row['budget_id']; $name = $names[$budgetId]; - $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; } @@ -248,8 +249,8 @@ class AccountController extends Controller /** * Expenses grouped by category for account. * - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return JsonResponse * @throws JsonException @@ -265,9 +266,9 @@ class AccountController extends Controller /** * Expenses per category for one single account. * - * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Account $account + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -295,7 +296,7 @@ class AccountController extends Controller if (!array_key_exists($key, $result)) { $result[$key] = [ 'total' => '0', - 'category_id' => (int) $journal['category_id'], + 'category_id' => (int)$journal['category_id'], 'currency_name' => $journal['currency_name'], 'currency_symbol' => $journal['currency_symbol'], 'currency_code' => $journal['currency_code'], @@ -308,7 +309,7 @@ class AccountController extends Controller foreach ($result as $row) { $categoryId = $row['category_id']; $name = $names[$categoryId] ?? '(unknown)'; - $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; } @@ -321,7 +322,7 @@ class AccountController extends Controller /** * Shows the balances for all the user's frontpage accounts. * - * @param AccountRepositoryInterface $repository + * @param AccountRepositoryInterface $repository * * @return JsonResponse * @throws FireflyException @@ -337,7 +338,7 @@ class AccountController extends Controller Log::debug('Default set is ', $defaultSet); $frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); Log::debug('Frontpage preference set is ', $frontPage->data); - if (empty($frontPage->data)) { + if (0 === count($frontPage->data)) { app('preferences')->set('frontPageAccounts', $defaultSet); Log::debug('frontpage set is empty!'); } @@ -349,8 +350,8 @@ class AccountController extends Controller /** * Shows the income grouped by category for an account, in all time. * - * @param AccountRepositoryInterface $repository - * @param Account $account + * @param AccountRepositoryInterface $repository + * @param Account $account * * @return JsonResponse * @throws JsonException @@ -366,9 +367,9 @@ class AccountController extends Controller /** * Shows all income per account for each category. * - * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Account $account + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -410,7 +411,7 @@ class AccountController extends Controller foreach ($result as $row) { $categoryId = $row['category_id']; $name = $names[$categoryId] ?? '(unknown)'; - $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']]; } $data = $this->generator->multiCurrencyPieChart($chartData); @@ -422,10 +423,10 @@ class AccountController extends Controller /** * Shows overview of account during a single period. * - * @param Account $account - * @param Carbon $start + * @param Account $account + * @param Carbon $start * - * @param Carbon $end + * @param Carbon $end * * @return JsonResponse * @throws FireflyException @@ -461,10 +462,10 @@ class AccountController extends Controller } /** - * @param Carbon $start - * @param Carbon $end - * @param Account $account - * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * @param Account $account + * @param TransactionCurrency $currency * * @return array * @throws FireflyException @@ -478,38 +479,31 @@ class AccountController extends Controller 'label' => sprintf('%s (%s)', $account->name, $currency->symbol), 'currency_symbol' => $currency->symbol, 'currency_code' => $currency->code, - 'entries' => [], ]; $entries = []; $current = clone $start; - switch ($step) { - default: - break; - case '1D': - // per day the entire period, balance for every day. - $format = (string) trans('config.month_and_day_js', [], $locale); - $range = app('steam')->balanceInRange($account, $start, $end, $currency); - $previous = array_values($range)[0]; - while ($end >= $current) { - $theDate = $current->format('Y-m-d'); - $balance = $range[$theDate] ?? $previous; - $label = $current->isoFormat($format); - $entries[$label] = (float) $balance; - $previous = $balance; - $current->addDay(); - } - break; - case '1W': - case '1M': - case '1Y': - while ($end >= $current) { - $balance = (float) app('steam')->balance($account, $current, $currency); - $label = app('navigation')->periodShow($current, $step); - $entries[$label] = $balance; - $current = app('navigation')->addPeriod($current, $step, 0); - } - break; + if ('1D' === $step) { + // per day the entire period, balance for every day. + $format = (string)trans('config.month_and_day_js', [], $locale); + $range = app('steam')->balanceInRange($account, $start, $end, $currency); + $previous = array_values($range)[0]; + while ($end >= $current) { + $theDate = $current->format('Y-m-d'); + $balance = $range[$theDate] ?? $previous; + $label = $current->isoFormat($format); + $entries[$label] = (float)$balance; + $previous = $balance; + $current->addDay(); + } + } + if ('1W' === $step || '1M' === $step || '1Y' === $step) { + while ($end >= $current) { + $balance = (float)app('steam')->balance($account, $current, $currency); + $label = app('navigation')->periodShow($current, $step); + $entries[$label] = $balance; + $current = app('navigation')->addPeriod($current, $step, 0); + } } $result['entries'] = $entries; @@ -521,10 +515,10 @@ class AccountController extends Controller * * TODO this chart is not multi currency aware. * - * @param Collection $accounts + * @param Collection $accounts * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * @return JsonResponse * @throws FireflyException * @throws JsonException @@ -572,22 +566,22 @@ class AccountController extends Controller // loop the end balances. This is an array for each account ($expenses) foreach ($endBalances as $accountId => $expenses) { - $accountId = (int) $accountId; + $accountId = (int)$accountId; // loop each expense entry (each entry can be a different currency). foreach ($expenses as $currencyId => $endAmount) { - $currencyId = (int) $currencyId; + $currencyId = (int)$currencyId; // see if there is an accompanying start amount. // grab the difference and find the currency. $startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0'); - $diff = bcsub((string) $endAmount, $startAmount); + $diff = bcsub((string)$endAmount, $startAmount); $currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId); if (0 !== bccomp($diff, '0')) { // store the values in a temporary array. $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float) $diff, + 'diff_float' => (float)$diff, 'currency_id' => $currencyId, ]; } @@ -600,13 +594,13 @@ class AccountController extends Controller // loop all found currencies and build the data array for the chart. /** - * @var int $currencyId + * @var int $currencyId * @var TransactionCurrency $currency */ foreach ($currencies as $currencyId => $currency) { $dataSet = [ - 'label' => (string) trans('firefly.earned'), + 'label' => (string)trans('firefly.earned'), 'type' => 'bar', 'currency_symbol' => $currency->symbol, 'currency_code' => $currency->code, diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index f0a6afb361..63a7806225 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -205,7 +205,7 @@ class BudgetController extends Controller * * @return JsonResponse */ - public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse + public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line { /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -273,7 +273,7 @@ class BudgetController extends Controller * * @return JsonResponse */ - public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse + public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line { /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -337,7 +337,7 @@ class BudgetController extends Controller * * @return JsonResponse */ - public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse + public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line { /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 19ef27dbb8..74cccb1bf9 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -1,4 +1,5 @@ id; + $categoryId = (int)$category->id; // this gives us all currencies $collection = new Collection([$category]); $expenses = $opsRepository->listExpenses($start, $end, null, $collection); @@ -217,7 +209,7 @@ class CategoryController extends Controller $inKey = sprintf('%d-in', $currencyId); $chartData[$outKey] = [ - 'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currencyInfo['currency_name']), + 'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red @@ -225,7 +217,7 @@ class CategoryController extends Controller $chartData[$inKey] = [ - 'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']), + 'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green @@ -262,9 +254,9 @@ class CategoryController extends Controller * Chart for period for transactions without a category. * TODO test me. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -289,8 +281,8 @@ class CategoryController extends Controller * Chart for a specific period. * TODO test me, for category refactor. * - * @param Category $category - * @param Carbon $date + * @param Category $category + * @param Carbon $date * * @return JsonResponse * @throws FireflyException diff --git a/app/Http/Controllers/Chart/DoubleReportController.php b/app/Http/Controllers/Chart/DoubleReportController.php index c223a4463e..719b17f950 100644 --- a/app/Http/Controllers/Chart/DoubleReportController.php +++ b/app/Http/Controllers/Chart/DoubleReportController.php @@ -318,7 +318,7 @@ class DoubleReportController extends Controller $journalId = $journal['transaction_journal_id']; // no tags? also deserves a sport - if (empty($journal['tags'])) { + if (0 === count($journal['tags'])) { $includedJournals[] = $journalId; // do something $tagName = trans('firefly.no_tags'); @@ -378,7 +378,7 @@ class DoubleReportController extends Controller $journalId = $journal['transaction_journal_id']; // no tags? also deserves a sport - if (empty($journal['tags'])) { + if (0 === count($journal['tags'])) { $includedJournals[] = $journalId; // do something $tagName = trans('firefly.no_tags'); diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php index ce9783ef54..e2c4975338 100644 --- a/app/Http/Controllers/Chart/ExpenseReportController.php +++ b/app/Http/Controllers/Chart/ExpenseReportController.php @@ -189,7 +189,7 @@ class ExpenseReportController extends Controller $newSet[$key] = $entry; } } - if (empty($newSet)) { + if (0 === count($newSet)) { $newSet = $chartData; } $data = $this->generator->multiSet($newSet); diff --git a/app/Http/Controllers/Chart/TransactionController.php b/app/Http/Controllers/Chart/TransactionController.php index 01be7f6fe8..aeee55ed8c 100644 --- a/app/Http/Controllers/Chart/TransactionController.php +++ b/app/Http/Controllers/Chart/TransactionController.php @@ -115,20 +115,17 @@ class TransactionController extends Controller $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end); $collector->withCategoryInformation(); - switch ($objectType) { - default: - throw new FireflyException(sprintf('Cant handle "%s"', $objectType)); - case 'withdrawal': - $collector->setTypes([TransactionType::WITHDRAWAL]); - break; - case 'deposit': - $collector->setTypes([TransactionType::DEPOSIT]); - break; - case 'transfers': - case 'transfer': - $collector->setTypes([TransactionType::TRANSFER]); - break; + + if ('withdrawal' === $objectType) { + $collector->setTypes([TransactionType::WITHDRAWAL]); } + if ('deposit' === $objectType) { + $collector->setTypes([TransactionType::DEPOSIT]); + } + if ('transfer' === $objectType || 'transfers' === $objectType) { + $collector->setTypes([TransactionType::TRANSFER]); + } + $result = $collector->getExtractedJournals(); $data = []; @@ -172,20 +169,17 @@ class TransactionController extends Controller $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end); $collector->withAccountInformation(); - switch ($objectType) { - default: - throw new FireflyException(sprintf('Cant handle "%s"', $objectType)); - case 'withdrawal': - $collector->setTypes([TransactionType::WITHDRAWAL]); - break; - case 'deposit': - $collector->setTypes([TransactionType::DEPOSIT]); - break; - case 'transfers': - case 'transfer': - $collector->setTypes([TransactionType::TRANSFER]); - break; + + if ('withdrawal' === $objectType) { + $collector->setTypes([TransactionType::WITHDRAWAL]); } + if ('deposit' === $objectType) { + $collector->setTypes([TransactionType::DEPOSIT]); + } + if ('transfer' === $objectType || 'transfers' === $objectType) { + $collector->setTypes([TransactionType::TRANSFER]); + } + $result = $collector->getExtractedJournals(); $data = []; @@ -229,20 +223,17 @@ class TransactionController extends Controller $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end); $collector->withAccountInformation(); - switch ($objectType) { - default: - throw new FireflyException(sprintf('Cant handle "%s"', $objectType)); - case 'withdrawal': - $collector->setTypes([TransactionType::WITHDRAWAL]); - break; - case 'deposit': - $collector->setTypes([TransactionType::DEPOSIT]); - break; - case 'transfers': - case 'transfer': - $collector->setTypes([TransactionType::TRANSFER]); - break; + + if ('withdrawal' === $objectType) { + $collector->setTypes([TransactionType::WITHDRAWAL]); } + if ('deposit' === $objectType) { + $collector->setTypes([TransactionType::DEPOSIT]); + } + if ('transfer' === $objectType || 'transfers' === $objectType) { + $collector->setTypes([TransactionType::TRANSFER]); + } + $result = $collector->getExtractedJournals(); $data = []; diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 65a574bdb9..cb01d5040a 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -98,7 +98,7 @@ class DebugController extends Controller Log::debug('Call twig:clean...'); try { Artisan::call('twig:clean'); - } catch (Exception $e) { + } catch (Exception $e) { // @phpstan-ignore-line // @ignoreException } @@ -188,7 +188,7 @@ class DebugController extends Controller if (null !== $logFile) { try { $logContent = file_get_contents($logFile); - } catch (Exception $e) { + } catch (Exception $e) { // @phpstan-ignore-line // @ignoreException } } diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 15ea0675d0..c7f64a05cf 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -190,7 +190,7 @@ class BoxController extends Controller $incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false); $expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false); } - if (empty($sums)) { + if (0 === count($sums)) { $currency = app('amount')->getDefaultCurrency(); $sums[$currency->id] = app('amount')->formatAnything($currency, '0', false); $incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false); diff --git a/app/Http/Controllers/Json/FrontpageController.php b/app/Http/Controllers/Json/FrontpageController.php index d0c4008686..a0715f1032 100644 --- a/app/Http/Controllers/Json/FrontpageController.php +++ b/app/Http/Controllers/Json/FrontpageController.php @@ -68,7 +68,7 @@ class FrontpageController extends Controller } } $html = ''; - if (!empty($info)) { + if (0 !== count($info)) { try { $html = view('json.piggy-banks', compact('info'))->render(); } catch (Throwable $e) { diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php index f8791a6c9d..670a17fccd 100644 --- a/app/Http/Controllers/Json/IntroController.php +++ b/app/Http/Controllers/Json/IntroController.php @@ -43,13 +43,13 @@ class IntroController extends Controller * * @return JsonResponse */ - public function getIntroSteps(string $route, string $specificPage = null): JsonResponse + public function getIntroSteps(string $route, string $specificPage = null): JsonResponse // @phpstan-ignore-line { Log::debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage)); $specificPage = $specificPage ?? ''; $steps = $this->getBasicSteps($route); $specificSteps = $this->getSpecificSteps($route, $specificPage); - if (empty($specificSteps)) { + if (0 === count($specificSteps)) { Log::debug(sprintf('No specific steps for route "%s" and page "%s"', $route, $specificPage)); return response()->json($steps); @@ -104,7 +104,7 @@ class IntroController extends Controller * @return JsonResponse * @throws FireflyException */ - public function postEnable(string $route, string $specialPage = null): JsonResponse + public function postEnable(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line { $specialPage = $specialPage ?? ''; $route = str_replace('.', '_', $route); @@ -128,7 +128,7 @@ class IntroController extends Controller * @return JsonResponse * @throws FireflyException */ - public function postFinished(string $route, string $specialPage = null): JsonResponse + public function postFinished(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line { $specialPage = $specialPage ?? ''; $key = 'shown_demo_' . $route; diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index c8ad9782ed..9834df9bcf 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -85,7 +85,7 @@ class ReconcileController extends Controller * @throws FireflyException * @throws JsonException */ - public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse + public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse // @phpstan-ignore-line { $startBalance = $request->get('startBalance'); $endBalance = $request->get('endBalance'); @@ -226,7 +226,7 @@ class ReconcileController extends Controller * @throws FireflyException * @throws JsonException */ - public function transactions(Account $account, Carbon $start = null, Carbon $end = null) + public function transactions(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line { if (null === $start || null === $end) { throw new FireflyException('Invalid dates submitted.'); diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 401a404257..2fb6ce79fe 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -127,7 +127,7 @@ class PreferencesController extends Controller $locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales; // an important fallback is that the frontPageAccount array gets refilled automatically // when it turns up empty. - if (empty($frontPageAccounts->data)) { + if (0 === count($frontPageAccounts->data)) { $frontPageAccounts = $accountIds; } diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index f4e8fdc4f6..3134635561 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -728,7 +728,7 @@ class CategoryController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; @@ -778,7 +778,7 @@ class CategoryController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; diff --git a/app/Http/Controllers/Report/DoubleController.php b/app/Http/Controllers/Report/DoubleController.php index 413a2e5914..27f72a6b03 100644 --- a/app/Http/Controllers/Report/DoubleController.php +++ b/app/Http/Controllers/Report/DoubleController.php @@ -115,7 +115,7 @@ class DoubleController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; @@ -167,7 +167,7 @@ class DoubleController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; @@ -461,7 +461,7 @@ class DoubleController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; @@ -511,7 +511,7 @@ class DoubleController extends Controller } catch (Throwable $e) { Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); - throw new FireflyException($result, 0, $e); + throw new FireflyException($e->getMessage(), 0, $e); } return $result; diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index 4ba09d2dc9..d2346e2801 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -145,7 +145,7 @@ class SelectController extends Controller $textTriggers = $this->getValidTriggerList($request); // warn if nothing. - if (empty($textTriggers)) { + if (0 === count($textTriggers)) { return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); } @@ -169,7 +169,7 @@ class SelectController extends Controller // Warn the user if only a subset of transactions is returned $warning = ''; - if (empty($collection)) { + if (0 === count($collection)) { $warning = (string) trans('firefly.warning_no_matching_transactions'); } @@ -200,7 +200,7 @@ class SelectController extends Controller { $triggers = $rule->ruleTriggers; - if (empty($triggers)) { + if (0 === count($triggers)) { return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); } // create new rule engine: @@ -212,7 +212,7 @@ class SelectController extends Controller $collection = $collection->slice(0, 20); $warning = ''; - if (empty($collection)) { + if (0 === count($collection)) { $warning = (string) trans('firefly.warning_no_matching_transactions'); } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index e9bd2f4397..236ac192c8 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -87,7 +87,7 @@ class Authenticate */ protected function authenticate($request, array $guards) { - if (empty($guards)) { + if (0 === count($guards)) { try { // go for default guard: if ($this->auth->check()) { diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index b96879d237..a1541e13e3 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -296,7 +296,7 @@ class TransactionJournal extends Model if (!self::isJoined($query, 'transaction_types')) { $query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); } - if (!empty($types)) { + if (0 !== count($types)) { $query->whereIn('transaction_types.type', $types); } } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 752239f65c..d39282aa16 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -142,7 +142,7 @@ class AccountRepository implements AccountRepositoryInterface } ); - if (!empty($types)) { + if (0 !== count($types)) { $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->whereIn('account_types.type', $types); } @@ -160,7 +160,7 @@ class AccountRepository implements AccountRepositoryInterface { $query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban'); - if (!empty($types)) { + if (0 !== count($types)) { $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $query->whereIn('account_types.type', $types); } @@ -178,7 +178,7 @@ class AccountRepository implements AccountRepositoryInterface { $query = $this->user->accounts(); - if (!empty($types)) { + if (0 !== count($types)) { $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $query->whereIn('account_types.type', $types); } @@ -218,7 +218,7 @@ class AccountRepository implements AccountRepositoryInterface { $query = $this->user->accounts(); - if (!empty($accountIds)) { + if (0 !== count($accountIds)) { $query->whereIn('accounts.id', $accountIds); } $query->orderBy('accounts.order', 'ASC'); @@ -240,7 +240,7 @@ class AccountRepository implements AccountRepositoryInterface $query->where('name', 'account_role'); }, 'attachments'] ); - if (!empty($types)) { + if (0 !== count($types)) { $query->accountTypeIn($types); } $query->where('active', true); @@ -316,7 +316,7 @@ class AccountRepository implements AccountRepositoryInterface $query->where('name', 'account_role'); }] ); - if (!empty($types)) { + if (0 !== count($types)) { $query->accountTypeIn($types); } $query->where('active', 0); @@ -585,19 +585,19 @@ class AccountRepository implements AccountRepositoryInterface { $res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types); $query = $this->user->accounts(); - if (!empty($types)) { + if (0 !== count($types)) { $query->accountTypeIn($types); } // add sort parameters. At this point they're filtered to allowed fields to sort by: - if (!empty($sort)) { + if (0 !== count($sort)) { foreach ($sort as $param) { $query->orderBy($param[0], $param[1]); } } - if (empty($sort)) { - if (!empty($res)) { + if (0 === count($sort)) { + if (0 !== count($res)) { $query->orderBy('accounts.order', 'ASC'); } $query->orderBy('accounts.active', 'DESC'); @@ -698,7 +698,7 @@ class AccountRepository implements AccountRepositoryInterface $dbQuery->where('name', 'LIKE', $search); } } - if (!empty($types)) { + if (0 !== count($types)) { $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->whereIn('account_types.type', $types); } @@ -736,7 +736,7 @@ class AccountRepository implements AccountRepositoryInterface ); } } - if (!empty($types)) { + if (0 !== count($types)) { $dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); $dbQuery->whereIn('account_types.type', $types); } diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php index 22a0d5f19c..bd7c9d6116 100644 --- a/app/Repositories/Recurring/RecurringRepository.php +++ b/app/Repositories/Recurring/RecurringRepository.php @@ -332,7 +332,7 @@ class RecurringRepository implements RecurringRepositoryInterface foreach ($journalMeta as $journalId) { $search[] = (int) $journalId; } - if (empty($search)) { + if (0 === count($search)) { return new Collection(); } diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 71e739f01d..ebb036fffb 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -68,7 +68,7 @@ class CreditRecalculateService // work based on account. $this->processAccount(); } - if (empty($this->work)) { + if (0 === count($this->work)) { Log::debug('No work accounts, do not do CreditRecalculationService'); return; @@ -84,7 +84,7 @@ class CreditRecalculateService { /** @var TransactionJournal $journal */ foreach ($this->group->transactionJournals as $journal) { - if (empty($this->work)) { + if (0 === count($this->work)) { try { $this->findByJournal($journal); } catch (FireflyException $e) { diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index 0ed9d859db..93eedd04bc 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -339,7 +339,7 @@ trait RecurringTransactionTrait */ protected function updateTags(RecurrenceTransaction $transaction, array $tags): void { - if (!empty($tags)) { + if (0 !== count($tags)) { /** @var RecurrenceMeta|null $entry */ $entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first(); if (null === $entry) { @@ -348,7 +348,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(); } diff --git a/app/Services/Internal/Update/GroupUpdateService.php b/app/Services/Internal/Update/GroupUpdateService.php index 2d2345e6ab..2817cf8ab4 100644 --- a/app/Services/Internal/Update/GroupUpdateService.php +++ b/app/Services/Internal/Update/GroupUpdateService.php @@ -60,7 +60,7 @@ class GroupUpdateService } - if (empty($transactions)) { + if (0 === count($transactions)) { Log::debug('No transactions submitted, do nothing.'); return $transactionGroup; @@ -119,7 +119,7 @@ class GroupUpdateService private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void { Log::debug(sprintf('Now in %s', __METHOD__)); - if (empty($data)) { + if (0 === count($data)) { return; } if (1 === count($data) && array_key_exists('transaction_journal_id', $data)) { diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index e7b9737c2f..60327bc94f 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -150,7 +150,7 @@ class RecurrenceUpdateService private function updateRepetitions(Recurrence $recurrence, array $repetitions): void { $originalCount = $recurrence->recurrenceRepetitions()->count(); - if (empty($repetitions)) { + if (0 === count($repetitions)) { // wont drop repetition, rather avoid. return; } @@ -228,7 +228,7 @@ class RecurrenceUpdateService private function updateTransactions(Recurrence $recurrence, array $transactions): void { $originalCount = $recurrence->recurrenceTransactions()->count(); - if (empty($transactions)) { + if (0 === count($transactions)) { // wont drop transactions, rather avoid. return; } diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.php index a72a89ba42..a38842b2f8 100644 --- a/app/Support/Binder/BudgetList.php +++ b/app/Support/Binder/BudgetList.php @@ -54,7 +54,7 @@ class BudgetList implements BinderInterface $list = array_unique(array_map('\intval', explode(',', $value))); - if (empty($list)) { + if (0 === count($list)) { app('log')->warning('Budget list count is zero, return 404.'); throw new NotFoundHttpException(); } diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php index 65b3f7024e..f01677ada5 100644 --- a/app/Support/Binder/CategoryList.php +++ b/app/Support/Binder/CategoryList.php @@ -50,7 +50,7 @@ class CategoryList implements BinderInterface } $list = array_unique(array_map('\intval', explode(',', $value))); - if (empty($list)) { + if (0 === count($list)) { throw new NotFoundHttpException(); } diff --git a/app/Support/Binder/JournalList.php b/app/Support/Binder/JournalList.php index 916c66f4f2..909920e183 100644 --- a/app/Support/Binder/JournalList.php +++ b/app/Support/Binder/JournalList.php @@ -52,7 +52,7 @@ class JournalList implements BinderInterface $collector->withCategoryInformation()->withBudgetInformation()->withTagInformation()->withAccountInformation(); $collector->setJournalIds($list); $result = $collector->getExtractedJournals(); - if (empty($result)) { + if (0 === count($result)) { throw new NotFoundHttpException(); } @@ -69,7 +69,7 @@ class JournalList implements BinderInterface protected static function parseList(string $value): array { $list = array_unique(array_map('\intval', explode(',', $value))); - if (empty($list)) { + if (0 === count($list)) { throw new NotFoundHttpException(); } diff --git a/app/Support/Binder/TagList.php b/app/Support/Binder/TagList.php index 6dc0514ac0..6f78d35f53 100644 --- a/app/Support/Binder/TagList.php +++ b/app/Support/Binder/TagList.php @@ -52,7 +52,7 @@ class TagList implements BinderInterface $list = array_unique(array_map('\strtolower', explode(',', $value))); Log::debug('List of tags is', $list); - if (empty($list)) { + if (0 === count($list)) { Log::error('Tag list is empty.'); throw new NotFoundHttpException(); } diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index 30eccb0a20..669ba0e016 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -767,7 +767,7 @@ class ExportDataGenerator */ private function mergeTags(array $tags): string { - if (empty($tags)) { + if (0 === count($tags)) { return ''; } $smol = []; diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index e5a9ea19b4..4b018a757d 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -1993,7 +1993,7 @@ class OperatorQuerySearch implements SearchInterface */ public function searchTransactions(): LengthAwarePaginator { - if (empty($this->getWords()) && empty($this->getOperators())) { + if (0 === count($this->getWords()) && 0 === count($this->getOperators())) { return new LengthAwarePaginator([], 0, 5, 1); } diff --git a/app/TransactionRules/Factory/ActionFactory.php b/app/TransactionRules/Factory/ActionFactory.php index 23c7da3248..37a8acae7b 100644 --- a/app/TransactionRules/Factory/ActionFactory.php +++ b/app/TransactionRules/Factory/ActionFactory.php @@ -92,7 +92,7 @@ class ActionFactory */ protected static function getActionTypes(): array { - if (empty(self::$actionTypes)) { + if (0 === count(self::$actionTypes)) { self::$actionTypes = Domain::getRuleActions(); } diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index c0166a8c31..271f68ea04 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -126,7 +126,7 @@ trait RecurrenceValidation $data = $validator->getData(); $repetitions = $data['repetitions'] ?? []; // need at least one transaction - if (!is_countable($repetitions) || empty($repetitions)) { + if (!is_countable($repetitions) || 0 === count($repetitions)) { $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition')); } } @@ -144,7 +144,7 @@ trait RecurrenceValidation return; } // need at least one transaction - if (empty($repetitions)) { + if (0 === count($repetitions)) { $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition')); } } diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 8ee4d110da..44c0c9bef8 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -312,7 +312,7 @@ trait TransactionValidation $transactions = $this->getTransactionsArray($validator); // need at least one transaction - if (empty($transactions)) { + if (0 === count($transactions)) { $validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction')); } } @@ -327,7 +327,7 @@ trait TransactionValidation Log::debug('Now in validateOneTransaction()'); $transactions = $this->getTransactionsArray($validator); // need at least one transaction - if (empty($transactions)) { + if (0 === count($transactions)) { $validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction')); Log::debug('Added error: at_least_one_transaction.');