Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Just learned about `clamp`.
James Colea4864c4997f2
diff --git a/app/Api/V1/Controllers/Controller.php b/app/Api/V1/Controllers/Controller.phpindex 089cd5f60f..85f914c444 100644--- a/app/Api/V1/Controllers/Controller.php+++ b/app/Api/V1/Controllers/Controller.php@@ -179,7 +179,7 @@ abstract class Controller extends BaseController{$bag = new ParameterBag();$page = (int) request()->get('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$bag->set('page', $page);// some date fields:@@ -221,7 +221,7 @@ abstract class Controller extends BaseController}if (null !== $value) {$value = (int) $value;- $value = min(max(1, $value), 2 ** 16);+ $value = clamp($value, 1, 2**16);$bag->set($integer, $value);}// && 'limit' === $integerdiff --git a/app/Api/V1/Requests/PaginationRequest.php b/app/Api/V1/Requests/PaginationRequest.phpindex e86c3dd34a..5e7681609c 100644--- a/app/Api/V1/Requests/PaginationRequest.php+++ b/app/Api/V1/Requests/PaginationRequest.php@@ -70,7 +70,7 @@ class PaginationRequest extends ApiRequest$limit = (int) Preferences::getForUser($user, 'listPageSize', 50)->data;}$page = $this->convertInteger('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$offset = ($page - 1) * $limit;$sort = null !== $this->sortClass ? $this->convertSortParameters('sort', $this->sortClass) : $this->get('sort');$this->attributes->set('limit', $limit);diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.phpindex 64dd998ebf..4b072a72d3 100644--- a/app/Http/Controllers/Account/IndexController.php+++ b/app/Http/Controllers/Account/IndexController.php@@ -80,7 +80,7 @@ final class IndexController extends Controller$collection = $this->repository->getInactiveAccountsByType($types);$total = $collection->count();$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);$inactiveCount = $this->repository->getInactiveAccountsByType($types)->count();@@ -147,7 +147,7 @@ final class IndexController extends Controller$collection = $this->repository->getActiveAccountsByType($types);$total = $collection->count();$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);$inactiveCount = $this->repository->getInactiveAccountsByType($types)->count();diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.phpindex 586a03c109..76101266f2 100644--- a/app/Http/Controllers/Account/ShowController.php+++ b/app/Http/Controllers/Account/ShowController.php@@ -215,7 +215,7 @@ final class ShowController extends Controller$start = $this->repository->oldestJournalDate($account) ?? today(config('app.timezone'))->startOfMonth();$subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type);$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);diff --git a/app/Http/Controllers/Bill/ShowController.php b/app/Http/Controllers/Bill/ShowController.phpindex eb59fcda43..48629b27c4 100644--- a/app/Http/Controllers/Bill/ShowController.php+++ b/app/Http/Controllers/Bill/ShowController.php@@ -130,7 +130,7 @@ final class ShowController extends Controller$end = session('end');$year = $start->year;$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$yearAverage = $this->repository->getYearAverage($bill, $start);$overallAverage = $this->repository->getOverallAverage($bill);diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.phpindex 850004cc09..a2c9863645 100644--- a/app/Http/Controllers/Budget/ShowController.php+++ b/app/Http/Controllers/Budget/ShowController.php@@ -97,7 +97,7 @@ final class ShowController extends Controller$firstDate = $first instanceof TransactionJournal ? $first->date : $start;$periods = $this->getNoModelPeriodOverview('budget', $firstDate, $end);$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;/** @var GroupCollectorInterface $collector */@@ -132,7 +132,7 @@ final class ShowController extends Controller$start = $first instanceof TransactionJournal ? $first->date : new Carbon();$end = today(config('app.timezone'));$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;/** @var GroupCollectorInterface $collector */@@ -166,7 +166,7 @@ final class ShowController extends Controller$allStart = session('first', today(config('app.timezone'))->startOfYear());$allEnd = today();$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$limits = $this->getLimits($budget, $allStart, $allEnd);$repetition = null;@@ -217,7 +217,7 @@ final class ShowController extends Controller$currencySymbol = $budgetLimit->transactionCurrency->symbol;$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$subTitle = trans('firefly.budget_in_period', ['name' => $budget->name,diff --git a/app/Http/Controllers/Category/IndexController.php b/app/Http/Controllers/Category/IndexController.phpindex a132c8c5f8..fd715df264 100644--- a/app/Http/Controllers/Category/IndexController.php+++ b/app/Http/Controllers/Category/IndexController.php@@ -71,7 +71,7 @@ final class IndexController extends Controllerpublic function index(Request $request): Factory|\Illuminate\Contracts\View\View{$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$collection = $this->repository->getCategories();$total = $collection->count();diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.phpindex 9ade0705c6..26b489881d 100644--- a/app/Http/Controllers/Category/NoCategoryController.php+++ b/app/Http/Controllers/Category/NoCategoryController.php@@ -85,7 +85,7 @@ final class NoCategoryController extends Controller/** @var Carbon $start *//** @var Carbon $end */$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$subTitle = trans('firefly.without_category_between', ['start' => $start->isoFormat($this->monthAndDayFormat),@@ -135,7 +135,7 @@ final class NoCategoryController extends Controller$end = null;$periods = new Collection();$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;Log::debug('Start of noCategory()');$subTitle = (string) trans('firefly.all_journals_without_category');diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.phpindex 1275e96224..bf9a644800 100644--- a/app/Http/Controllers/Category/ShowController.php+++ b/app/Http/Controllers/Category/ShowController.php@@ -84,7 +84,7 @@ final class ShowController extends Controller/** @var Carbon $end */$subTitleIcon = 'bi-bookmark';$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$attachments = $this->repository->getAttachments($category);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$oldest = $this->repository->firstUseDate($category) ?? today(config('app.timezone'))->startOfYear();@@ -136,7 +136,7 @@ final class ShowController extends Controller// default values:$subTitleIcon = 'bi-bookmark';$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$start = null;$end = null;diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.phpindex aa3cd963ac..ee290a9376 100644--- a/app/Http/Controllers/Recurring/IndexController.php+++ b/app/Http/Controllers/Recurring/IndexController.php@@ -81,7 +81,7 @@ final class IndexController extends Controllerpublic function index(Request $request): Factory|\Illuminate\Contracts\View\View{$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$collection = $this->repository->get();$today = today(config('app.timezone'));diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.phpindex ec80c215a7..6cfd5e026f 100644--- a/app/Http/Controllers/SearchController.php+++ b/app/Http/Controllers/SearchController.php@@ -67,7 +67,7 @@ final class SearchController extends Controller}$fullQuery = (string) $fullQuery;$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$ruleId = (int) $request->input('rule');$ruleChanged = false;@@ -117,7 +117,7 @@ final class SearchController extends Controller}$fullQuery = (string) $entry;$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$searcher->parseQuery($fullQuery);diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.phpindex a6a780259f..e43b8e9ff8 100644--- a/app/Http/Controllers/TagController.php+++ b/app/Http/Controllers/TagController.php@@ -298,7 +298,7 @@ final class TagController extends Controller// default values:$subTitleIcon = 'bi-tag';$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$periods = [];$subTitle = (string) trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]);diff --git a/app/Http/Controllers/Transaction/IndexController.php b/app/Http/Controllers/Transaction/IndexController.phpindex 9ec6c06440..1e53b6da6a 100644--- a/app/Http/Controllers/Transaction/IndexController.php+++ b/app/Http/Controllers/Transaction/IndexController.php@@ -152,7 +152,7 @@ final class IndexController extends Controller$subTitleIcon = config('firefly.transactionIconsByType.'.$objectType);$types = config('firefly.transactionTypesByType.'.$objectType);$page = (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$path = route('transactions.index.all', [$objectType]);$first = $this->repository->firstNull();diff --git a/app/Http/Controllers/TransactionCurrency/IndexController.php b/app/Http/Controllers/TransactionCurrency/IndexController.phpindex 7bb316c38f..fdf560b452 100644--- a/app/Http/Controllers/TransactionCurrency/IndexController.php+++ b/app/Http/Controllers/TransactionCurrency/IndexController.php@@ -72,7 +72,7 @@ final class IndexController extends Controller/** @var User $user */$user = auth()->user();$page = 0 === (int) $request->input('page') ? 1 : (int) $request->input('page');- $page = min(max(1, $page), 2 ** 16);+ $page = clamp($page, 1, 2 ** 16);$pageSize = (int) Preferences::get('listPageSize', 50)->data;$collection = $this->repository->getAll();diff --git a/app/Listeners/Model/Account/UpdatesAccountInformation.php b/app/Listeners/Model/Account/UpdatesAccountInformation.phpindex 63714e2153..3d9b48a124 100644--- a/app/Listeners/Model/Account/UpdatesAccountInformation.php+++ b/app/Listeners/Model/Account/UpdatesAccountInformation.php@@ -1,24 +1,6 @@<?php-/*- * UpdatesAccountInformation.php- * Copyright (c) 2026 [email protected]- *- * This file is part of Firefly III (https://github.com/firefly-iii).- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <https://www.gnu.org/licenses/>.- */+declare(strict_types=1);diff --git a/app/Listeners/Security/System/HandlesNewUserRegistration.php b/app/Listeners/Security/System/HandlesNewUserRegistration.phpindex 982147dff3..c346d9cf04 100644--- a/app/Listeners/Security/System/HandlesNewUserRegistration.php+++ b/app/Listeners/Security/System/HandlesNewUserRegistration.php@@ -1,24 +1,6 @@<?php-/*- * HandlesNewUserRegistration.php- * Copyright (c) 2026 [email protected]- *- * This file is part of Firefly III (https://github.com/firefly-iii).- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <https://www.gnu.org/licenses/>.- */+declare(strict_types=1);