From 6e5a08245caae4382c1a328a056635b9ed2832f9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 May 2025 16:39:20 +0200 Subject: [PATCH 1/4] Rector code cleanup --- .ci/rector.php | 1 + .../Autocomplete/TransactionController.php | 3 ++- .../V1/Controllers/Chart/AccountController.php | 3 ++- .../CurrencyExchangeRate/DestroyController.php | 5 +++-- .../CurrencyExchangeRate/StoreController.php | 5 +++-- .../Models/RuleGroup/TriggerController.php | 3 ++- .../TransactionCurrency/DestroyController.php | 7 ++++--- .../Models/TransactionLink/StoreController.php | 3 ++- .../TransactionLinkType/StoreController.php | 3 ++- .../TransactionLinkType/UpdateController.php | 3 ++- .../V1/Controllers/Summary/BasicController.php | 12 ++++++------ .../System/ConfigurationController.php | 3 ++- app/Api/V1/Middleware/ApiDemoUser.php | 3 ++- .../V1/Requests/Data/Bulk/TransactionRequest.php | 3 ++- app/Api/V1/Requests/Models/Bill/StoreRequest.php | 6 ++++-- app/Api/V1/Requests/System/CronRequest.php | 3 ++- .../Autocomplete/AccountController.php | 2 +- .../V2/Controllers/Chart/AccountController.php | 2 +- app/Api/V2/Controllers/Controller.php | 2 +- .../V2/Controllers/Summary/BasicController.php | 10 +++++----- .../Transaction/List/AccountController.php | 5 +++-- .../Model/Transaction/InfiniteListRequest.php | 2 +- .../V2/Request/Model/Transaction/ListRequest.php | 2 +- .../Request/Model/Transaction/UpdateRequest.php | 7 ++++--- app/Api/V2/Response/Sum/AutoSum.php | 3 ++- app/Http/Controllers/DebugController.php | 6 +++--- app/Http/Controllers/HomeController.php | 3 ++- app/Http/Controllers/Json/FrontpageController.php | 3 ++- app/Http/Controllers/Json/ReconcileController.php | 5 +++-- app/Http/Controllers/Json/RuleController.php | 5 +++-- app/Http/Controllers/PreferencesController.php | 3 ++- app/Http/Controllers/Profile/MfaController.php | 10 ++++++---- app/Http/Controllers/ProfileController.php | 15 +++++++++------ app/Http/Controllers/Report/AccountController.php | 3 ++- app/Http/Controllers/Report/BalanceController.php | 3 ++- app/Http/Controllers/Report/BillController.php | 3 ++- app/Http/Controllers/Report/BudgetController.php | 7 ++++--- .../Controllers/Report/CategoryController.php | 15 ++++++++------- app/Http/Controllers/Report/DoubleController.php | 9 +++++---- .../Controllers/Report/OperationsController.php | 7 ++++--- app/Http/Controllers/Report/TagController.php | 9 +++++---- app/Http/Controllers/Rule/EditController.php | 3 ++- app/Http/Controllers/Rule/SelectController.php | 5 +++-- .../Controllers/RuleGroup/ExecutionController.php | 3 ++- app/Http/Controllers/SearchController.php | 3 ++- app/Http/Controllers/System/InstallController.php | 9 +++++---- .../Controllers/Transaction/ConvertController.php | 6 +++--- .../Controllers/Transaction/MassController.php | 3 ++- app/Http/Middleware/Authenticate.php | 3 ++- app/Http/Middleware/Binder.php | 3 ++- app/Http/Middleware/InstallationId.php | 3 ++- app/Http/Middleware/Installer.php | 3 ++- app/Http/Middleware/InterestingMessage.php | 3 ++- app/Http/Middleware/IsAdmin.php | 3 ++- app/Http/Middleware/IsDemoUser.php | 3 ++- app/Http/Middleware/Range.php | 6 ++++-- app/Http/Middleware/RedirectIfAuthenticated.php | 3 ++- app/Http/Middleware/SecureHeaders.php | 6 ++++-- app/Http/Middleware/StartFireflySession.php | 3 ++- app/Http/Middleware/TrustHosts.php | 3 ++- app/Http/Requests/ReportFormRequest.php | 4 ++-- config/session.php | 2 +- 62 files changed, 172 insertions(+), 115 deletions(-) diff --git a/.ci/rector.php b/.ci/rector.php index 3ba2f28d41..ca37bf1431 100644 --- a/.ci/rector.php +++ b/.ci/rector.php @@ -32,6 +32,7 @@ return RectorConfig::configure() ]) ->withPaths([ // __DIR__ . '/../app', +__DIR__ . '/../app/Api', __DIR__ . '/../app/Http', // __DIR__ . '/../bootstrap', // __DIR__ . '/../config', diff --git a/app/Api/V1/Controllers/Autocomplete/TransactionController.php b/app/Api/V1/Controllers/Autocomplete/TransactionController.php index 3cba382e52..a6785dbc38 100644 --- a/app/Api/V1/Controllers/Autocomplete/TransactionController.php +++ b/app/Api/V1/Controllers/Autocomplete/TransactionController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Autocomplete; +use FireflyIII\Models\TransactionGroup; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest; use FireflyIII\Enums\UserRoleEnum; @@ -102,7 +103,7 @@ class TransactionController extends Controller if (is_numeric($data['query'])) { // search for group, not journal. $firstResult = $this->groupRepository->find((int) $data['query']); - if (null !== $firstResult) { + if ($firstResult instanceof TransactionGroup) { // group may contain multiple journals, each a result: foreach ($firstResult->transactionJournals as $journal) { $result->push($journal); diff --git a/app/Api/V1/Controllers/Chart/AccountController.php b/app/Api/V1/Controllers/Chart/AccountController.php index 21150047c0..dcd85072b9 100644 --- a/app/Api/V1/Controllers/Chart/AccountController.php +++ b/app/Api/V1/Controllers/Chart/AccountController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Chart; +use FireflyIII\Models\TransactionCurrency; use Carbon\Carbon; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Chart\ChartRequest; @@ -99,7 +100,7 @@ class AccountController extends Controller private function renderAccountData(array $params, Account $account): void { $currency = $this->repository->getAccountCurrency($account); - if (null === $currency) { + if (!$currency instanceof TransactionCurrency) { $currency = $this->default; } $currentSet = [ diff --git a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php index 9deedea808..30a3b79677 100644 --- a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php +++ b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/DestroyController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; +use Carbon\Carbon; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\DestroyRequest; use FireflyIII\Enums\UserRoleEnum; @@ -59,11 +60,11 @@ class DestroyController extends Controller public function destroy(DestroyRequest $request, TransactionCurrency $from, TransactionCurrency $to): JsonResponse { $date = $request->getDate(); - if (null === $date) { + if (!$date instanceof Carbon) { throw new ValidationException('Date is required'); } $rate = $this->repository->getSpecificRateOnDate($from, $to, $date); - if (null === $rate) { + if (!$rate instanceof CurrencyExchangeRate) { throw new NotFoundHttpException(); } $this->repository->deleteRate($rate); diff --git a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php index fcfb36ab6a..0a88531834 100644 --- a/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php +++ b/app/Api/V1/Controllers/Models/CurrencyExchangeRate/StoreController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\CurrencyExchangeRate; +use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate\StoreRequest; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface; @@ -61,11 +62,11 @@ class StoreController extends Controller // already has rate? $object = $this->repository->getSpecificRateOnDate($from, $to, $date); - if (null !== $object) { + if ($object instanceof CurrencyExchangeRate) { // just update it, no matter. $rate = $this->repository->updateExchangeRate($object, $rate, $date); } - if (null === $object) { + if (!$object instanceof CurrencyExchangeRate) { // store new $rate = $this->repository->storeExchangeRate($from, $to, $rate, $date); } diff --git a/app/Api/V1/Controllers/Models/RuleGroup/TriggerController.php b/app/Api/V1/Controllers/Models/RuleGroup/TriggerController.php index 14c480577a..4a4ef9eb69 100644 --- a/app/Api/V1/Controllers/Models/RuleGroup/TriggerController.php +++ b/app/Api/V1/Controllers/Models/RuleGroup/TriggerController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup; +use Exception; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\RuleGroup\TestRequest; use FireflyIII\Api\V1\Requests\Models\RuleGroup\TriggerRequest; @@ -128,7 +129,7 @@ class TriggerController extends Controller * * Execute the given rule group on a set of existing transactions. * - * @throws \Exception + * @throws Exception */ public function triggerGroup(TriggerRequest $request, RuleGroup $group): JsonResponse { diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php index 7da589703f..263d6bc350 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionCurrency; +use Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionCurrency; @@ -74,15 +75,15 @@ class DestroyController extends Controller if (!$this->userRepository->hasRole($admin, 'owner')) { // access denied: $messages = ['currency_code' => '200005: You need the "owner" role to do this.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } if ($this->repository->currencyInUse($currency)) { $messages = ['currency_code' => '200006: Currency in use.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } if ($this->repository->isFallbackCurrency($currency)) { $messages = ['currency_code' => '200026: Currency is fallback.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } $this->repository->destroy($currency); diff --git a/app/Api/V1/Controllers/Models/TransactionLink/StoreController.php b/app/Api/V1/Controllers/Models/TransactionLink/StoreController.php index f3083cb7fe..89219ff30a 100644 --- a/app/Api/V1/Controllers/Models/TransactionLink/StoreController.php +++ b/app/Api/V1/Controllers/Models/TransactionLink/StoreController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionLink; +use FireflyIII\Models\TransactionJournal; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\TransactionLink\StoreRequest; use FireflyIII\Exceptions\FireflyException; @@ -81,7 +82,7 @@ class StoreController extends Controller $data = $request->getAll(); $inward = $this->journalRepository->find($data['inward_id'] ?? 0); $outward = $this->journalRepository->find($data['outward_id'] ?? 0); - if (null === $inward || null === $outward) { + if (!$inward instanceof TransactionJournal || !$outward instanceof TransactionJournal) { throw new FireflyException('200024: Source or destination does not exist.'); } $data['direction'] = 'inward'; diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php index c915dd6589..b779934ea6 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionLinkType; +use Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\TransactionLinkType\StoreRequest; use FireflyIII\Exceptions\FireflyException; @@ -81,7 +82,7 @@ class StoreController extends Controller if (!$this->userRepository->hasRole($admin, 'owner')) { // access denied: $messages = ['name' => '200005: You need the "owner" role to do this.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } $data = $request->getAll(); // if currency ID is 0, find the currency by the code: diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php index 0b79bd30a1..b1f06549ce 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionLinkType; +use Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\TransactionLinkType\UpdateRequest; use FireflyIII\Exceptions\FireflyException; @@ -85,7 +86,7 @@ class UpdateController extends Controller if (!$this->userRepository->hasRole($admin, 'owner')) { $messages = ['name' => '200005: You need the "owner" role to do this.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } $data = $request->getAll(); diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.php index 25d2346ea2..1878812a27 100644 --- a/app/Api/V1/Controllers/Summary/BasicController.php +++ b/app/Api/V1/Controllers/Summary/BasicController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Summary; +use Exception; use Carbon\Carbon; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Data\DateRequest; @@ -91,7 +92,7 @@ class BasicController extends Controller * This endpoint is documented at: * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/summary/getBasicSummary * - * @throws \Exception + * @throws Exception */ public function basic(DateRequest $request): JsonResponse { @@ -467,7 +468,7 @@ class BasicController extends Controller } /** - * @throws \Exception + * @throws Exception */ private function getLeftToSpendInfo(Carbon $start, Carbon $end): array { @@ -674,15 +675,14 @@ class BasicController extends Controller */ protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference { - $result = false; if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) { - $result = true; + return true; } // start and end in the past? use $end if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) { - $result = true; + return true; } - return $result; + return false; } } diff --git a/app/Api/V1/Controllers/System/ConfigurationController.php b/app/Api/V1/Controllers/System/ConfigurationController.php index 661b6e457e..35e84f41b9 100644 --- a/app/Api/V1/Controllers/System/ConfigurationController.php +++ b/app/Api/V1/Controllers/System/ConfigurationController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\System; +use Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\System\UpdateRequest; use FireflyIII\Exceptions\FireflyException; @@ -158,7 +159,7 @@ class ConfigurationController extends Controller $rules = ['value' => 'required']; if (!$this->repository->hasRole(auth()->user(), 'owner')) { $messages = ['value' => '200005: You need the "owner" role to do this.']; - \Validator::make([], $rules, $messages)->validate(); + Validator::make([], $rules, $messages)->validate(); } $data = $request->getAll(); $shortName = str_replace('configuration.', '', $name); diff --git a/app/Api/V1/Middleware/ApiDemoUser.php b/app/Api/V1/Middleware/ApiDemoUser.php index e031bfa039..cd85e94879 100644 --- a/app/Api/V1/Middleware/ApiDemoUser.php +++ b/app/Api/V1/Middleware/ApiDemoUser.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Middleware; +use Closure; use FireflyIII\User; use Illuminate\Http\Request; @@ -36,7 +37,7 @@ class ApiDemoUser * * @return mixed */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, Closure $next) { /** @var null|User $user */ $user = $request->user(); diff --git a/app/Api/V1/Requests/Data/Bulk/TransactionRequest.php b/app/Api/V1/Requests/Data/Bulk/TransactionRequest.php index b9319e0240..da2bfb3d7c 100644 --- a/app/Api/V1/Requests/Data/Bulk/TransactionRequest.php +++ b/app/Api/V1/Requests/Data/Bulk/TransactionRequest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests\Data\Bulk; +use JsonException; use FireflyIII\Enums\ClauseType; use FireflyIII\Rules\IsValidBulkClause; use FireflyIII\Support\Request\ChecksLogin; @@ -52,7 +53,7 @@ class TransactionRequest extends FormRequest $data = [ 'query' => json_decode($this->get('query'), true, 8, JSON_THROW_ON_ERROR), ]; - } catch (\JsonException $e) { + } catch (JsonException $e) { // dont really care. the validation should catch invalid json. app('log')->error($e->getMessage()); } diff --git a/app/Api/V1/Requests/Models/Bill/StoreRequest.php b/app/Api/V1/Requests/Models/Bill/StoreRequest.php index 40194a33f4..e773942ca3 100644 --- a/app/Api/V1/Requests/Models/Bill/StoreRequest.php +++ b/app/Api/V1/Requests/Models/Bill/StoreRequest.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests\Models\Bill; +use ValueError; +use TypeError; use FireflyIII\Rules\IsBoolean; use FireflyIII\Rules\IsValidPositiveAmount; use FireflyIII\Support\Request\ChecksLogin; @@ -109,7 +111,7 @@ class StoreRequest extends FormRequest try { $result = bccomp($min, $max); - } catch (\ValueError $e) { + } catch (ValueError $e) { Log::error($e->getMessage()); $validator->errors()->add('amount_min', (string) trans('validation.generic_invalid')); $validator->errors()->add('amount_max', (string) trans('validation.generic_invalid')); @@ -124,7 +126,7 @@ class StoreRequest extends FormRequest try { $failed = $validator->fails(); - } catch (\TypeError $e) { + } catch (TypeError $e) { Log::error($e->getMessage()); $failed = false; } diff --git a/app/Api/V1/Requests/System/CronRequest.php b/app/Api/V1/Requests/System/CronRequest.php index f5d03d4cf6..ec57cfeb96 100644 --- a/app/Api/V1/Requests/System/CronRequest.php +++ b/app/Api/V1/Requests/System/CronRequest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests\System; +use Carbon\Carbon; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; @@ -58,7 +59,7 @@ class CronRequest extends FormRequest $data['date'] = $this->getCarbonDate('date'); } // catch NULL. - if (null === $data['date']) { + if (!$data['date'] instanceof Carbon) { $data['date'] = today(config('app.timezone')); } diff --git a/app/Api/V2/Controllers/Autocomplete/AccountController.php b/app/Api/V2/Controllers/Autocomplete/AccountController.php index ab52c9bddc..b267c1a09c 100644 --- a/app/Api/V2/Controllers/Autocomplete/AccountController.php +++ b/app/Api/V2/Controllers/Autocomplete/AccountController.php @@ -90,7 +90,7 @@ class AccountController extends Controller 'meta' => [ 'type' => $account->accountType->type, // TODO is multi currency property. - 'currency_id' => null === $currency ? null : (string) $currency->id, + 'currency_id' => $currency instanceof TransactionCurrency ? (string) $currency->id : null, 'currency_code' => $currency?->code, 'currency_symbol' => $currency?->symbol, 'currency_decimal_places' => $currency?->decimal_places, diff --git a/app/Api/V2/Controllers/Chart/AccountController.php b/app/Api/V2/Controllers/Chart/AccountController.php index 49c59cc26b..7f273cae3f 100644 --- a/app/Api/V2/Controllers/Chart/AccountController.php +++ b/app/Api/V2/Controllers/Chart/AccountController.php @@ -94,7 +94,7 @@ class AccountController extends Controller private function renderAccountData(array $params, Account $account): void { $currency = $this->repository->getAccountCurrency($account); - if (null === $currency) { + if (!$currency instanceof TransactionCurrency) { $currency = $this->default; } $currentSet = [ diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php index d3c5207fe2..0a2afcfac5 100644 --- a/app/Api/V2/Controllers/Controller.php +++ b/app/Api/V2/Controllers/Controller.php @@ -117,7 +117,7 @@ class Controller extends BaseController app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr((string) $date, 0, 20), $e->getMessage())); } // out of range? set to null. - if (null !== $obj && ($obj->year <= 1900 || $obj->year > 2099)) { + if ($obj instanceof Carbon && ($obj->year <= 1900 || $obj->year > 2099)) { app('log')->warning(sprintf('Refuse to use date "%s" in API v2 controller parameter check: %s', $field, $obj->toAtomString())); $obj = null; } diff --git a/app/Api/V2/Controllers/Summary/BasicController.php b/app/Api/V2/Controllers/Summary/BasicController.php index 079f7f7305..feb3798cef 100644 --- a/app/Api/V2/Controllers/Summary/BasicController.php +++ b/app/Api/V2/Controllers/Summary/BasicController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Controllers\Summary; +use Exception; use Carbon\Carbon; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Generic\DateRequest; @@ -92,7 +93,7 @@ class BasicController extends Controller * This endpoint is documented at: * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/summary/getBasicSummary * - * @throws \Exception + * @throws Exception * * @SuppressWarnings("PHPMD.UnusedFormalParameter") */ @@ -398,15 +399,14 @@ class BasicController extends Controller */ protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference { - $result = false; if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) { - $result = true; + return true; } // start and end in the past? use $end if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) { - $result = true; + return true; } - return $result; + return false; } } diff --git a/app/Api/V2/Controllers/Transaction/List/AccountController.php b/app/Api/V2/Controllers/Transaction/List/AccountController.php index 1ab79af7a9..7ba12c9940 100644 --- a/app/Api/V2/Controllers/Transaction/List/AccountController.php +++ b/app/Api/V2/Controllers/Transaction/List/AccountController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Controllers\Transaction\List; +use Carbon\Carbon; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Model\Transaction\ListRequest; use FireflyIII\Helpers\Collector\GroupCollectorInterface; @@ -62,11 +63,11 @@ class AccountController extends Controller $start = $request->getStartDate(); $end = $request->getEndDate(); - if (null !== $start) { + if ($start instanceof Carbon) { app('log')->debug(sprintf('Set start date to %s', $start->toIso8601String())); $collector->setStart($start); } - if (null !== $end) { + if ($end instanceof Carbon) { app('log')->debug(sprintf('Set end date to %s', $start->toIso8601String())); $collector->setEnd($end); } diff --git a/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php b/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php index 9f083d3935..a66e960f82 100644 --- a/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php +++ b/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php @@ -53,7 +53,7 @@ class InfiniteListRequest extends FormRequest $start = $this->getStartDate(); $end = $this->getEndDate(); - if (null !== $start && null !== $end) { + if ($start instanceof Carbon && $end instanceof Carbon) { $array['start'] = $start->format('Y-m-d'); $array['end'] = $end->format('Y-m-d'); } diff --git a/app/Api/V2/Request/Model/Transaction/ListRequest.php b/app/Api/V2/Request/Model/Transaction/ListRequest.php index ff6f767e30..17cf22b78a 100644 --- a/app/Api/V2/Request/Model/Transaction/ListRequest.php +++ b/app/Api/V2/Request/Model/Transaction/ListRequest.php @@ -49,7 +49,7 @@ class ListRequest extends FormRequest $start = $this->getStartDate(); $end = $this->getEndDate(); - if (null !== $start && null !== $end) { + if ($start instanceof Carbon && $end instanceof Carbon) { $array['start'] = $start->format('Y-m-d'); $array['end'] = $end->format('Y-m-d'); } diff --git a/app/Api/V2/Request/Model/Transaction/UpdateRequest.php b/app/Api/V2/Request/Model/Transaction/UpdateRequest.php index c4d8140c79..3aeda0e3c3 100644 --- a/app/Api/V2/Request/Model/Transaction/UpdateRequest.php +++ b/app/Api/V2/Request/Model/Transaction/UpdateRequest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Request\Model\Transaction; +use Override; use FireflyIII\Api\V1\Requests\Models\AvailableBudget\Request; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionGroup; @@ -64,7 +65,7 @@ class UpdateRequest extends Request * * @throws FireflyException */ - #[\Override] + #[Override] public function getAll(): array { app('log')->debug(sprintf('Now in %s', __METHOD__)); @@ -248,7 +249,7 @@ class UpdateRequest extends Request /** * The rules that the incoming request must be matched against. */ - #[\Override] + #[Override] public function rules(): array { app('log')->debug(sprintf('Now in %s', __METHOD__)); @@ -332,7 +333,7 @@ class UpdateRequest extends Request /** * Configure the validator instance. */ - #[\Override] + #[Override] public function withValidator(Validator $validator): void { app('log')->debug('Now in withValidator'); diff --git a/app/Api/V2/Response/Sum/AutoSum.php b/app/Api/V2/Response/Sum/AutoSum.php index c4ca249fbb..0f1d601f7c 100644 --- a/app/Api/V2/Response/Sum/AutoSum.php +++ b/app/Api/V2/Response/Sum/AutoSum.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Response\Sum; +use Closure; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionCurrency; use Illuminate\Database\Eloquent\Model; @@ -39,7 +40,7 @@ class AutoSum /** * @throws FireflyException */ - public function autoSum(Collection $objects, \Closure $getCurrency, \Closure $getSum): array + public function autoSum(Collection $objects, Closure $getCurrency, Closure $getSum): array { $return = []; diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 761070bd46..dd570b63a9 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -111,7 +111,7 @@ class DebugController extends Controller try { Artisan::call('twig:clean'); - } catch (\Exception $e) { // intentional generic exception + } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); } @@ -203,7 +203,7 @@ class DebugController extends Controller $return['build'] = trim((string) file_get_contents('/var/www/counter-main.txt')); app('log')->debug(sprintf('build is now "%s"', $return['build'])); } - } catch (\Exception $e) { + } catch (Exception $e) { app('log')->debug('Could not check build counter, but thats ok.'); app('log')->warning($e->getMessage()); } @@ -212,7 +212,7 @@ class DebugController extends Controller if (file_exists('/var/www/build-date-main.txt')) { $return['build_date'] = trim((string) file_get_contents('/var/www/build-date-main.txt')); } - } catch (\Exception $e) { + } catch (Exception $e) { app('log')->debug('Could not check build date, but thats ok.'); app('log')->warning($e->getMessage()); } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 4f300d8924..b829724308 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; +use Exception; use Carbon\Carbon; use Carbon\Exceptions\InvalidFormatException; use FireflyIII\Enums\AccountTypeEnum; @@ -57,7 +58,7 @@ class HomeController extends Controller /** * Change index date range. * - * @throws \Exception + * @throws Exception */ public function dateRange(Request $request): JsonResponse { diff --git a/app/Http/Controllers/Json/FrontpageController.php b/app/Http/Controllers/Json/FrontpageController.php index 08ed98cd53..f508c66763 100644 --- a/app/Http/Controllers/Json/FrontpageController.php +++ b/app/Http/Controllers/Json/FrontpageController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use Throwable; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\PiggyBank; @@ -89,7 +90,7 @@ class FrontpageController extends Controller if (0 !== count($info)) { try { $html = view('json.piggy-banks', compact('info', 'convertToNative', 'native'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $html = 'Could not render view.'; diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index f2122dc310..db7642cfe8 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use Throwable; use Carbon\Carbon; use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Exceptions\FireflyException; @@ -130,7 +131,7 @@ class ReconcileController extends Controller try { $view = view('accounts.reconcile.overview', compact('account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', 'startBalance', 'endBalance', 'amount', 'route', 'countCleared', 'reconSum', 'selectedIds'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('View error: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $view = sprintf('Could not render accounts.reconcile.overview: %s', $e->getMessage()); @@ -228,7 +229,7 @@ class ReconcileController extends Controller 'accounts.reconcile.transactions', compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd') )->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $html = sprintf('Could not render accounts.reconcile.transactions: %s', $e->getMessage()); diff --git a/app/Http/Controllers/Json/RuleController.php b/app/Http/Controllers/Json/RuleController.php index c91fb1c1e3..a555015150 100644 --- a/app/Http/Controllers/Json/RuleController.php +++ b/app/Http/Controllers/Json/RuleController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use Throwable; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use Illuminate\Http\JsonResponse; @@ -50,7 +51,7 @@ class RuleController extends Controller try { $view = view('rules.partials.action', compact('actions', 'count'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $view = 'Could not render view.'; @@ -80,7 +81,7 @@ class RuleController extends Controller try { $view = view('rules.partials.trigger', compact('triggers', 'count'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $view = 'Could not render view.'; diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 4f2526083c..3031037624 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; +use JsonException; use Carbon\Carbon; use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency; @@ -155,7 +156,7 @@ class PreferencesController extends Controller try { $locales = json_decode((string) file_get_contents(resource_path(sprintf('locales/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR); - } catch (\JsonException $e) { + } catch (JsonException $e) { app('log')->error($e->getMessage()); $locales = []; } diff --git a/app/Http/Controllers/Profile/MfaController.php b/app/Http/Controllers/Profile/MfaController.php index 675b95d6f3..5d70a3b3f4 100644 --- a/app/Http/Controllers/Profile/MfaController.php +++ b/app/Http/Controllers/Profile/MfaController.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Profile; +use Cookie; +use Google2FA; use Carbon\Carbon; use FireflyIII\Events\Security\DisabledMFA; use FireflyIII\Events\Security\EnabledMFA; @@ -182,7 +184,7 @@ class MfaController extends Controller // also logout current 2FA tokens. $cookieName = config('google2fa.cookie_name', 'google2fa_token'); - \Cookie::forget($cookieName); + Cookie::forget($cookieName); // send user notification. Log::channel('audit')->info(sprintf('User "%s" has disabled MFA', $user->email)); @@ -215,8 +217,8 @@ class MfaController extends Controller } $domain = $this->getDomain(); - $secret = \Google2FA::generateSecretKey(); - $image = \Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret); + $secret = Google2FA::generateSecretKey(); + $image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret); app('preferences')->set('temp-mfa-secret', $secret); @@ -272,7 +274,7 @@ class MfaController extends Controller // make sure MFA is logged out. if ('testing' !== config('app.env')) { - \Google2FA::logout(); + Google2FA::logout(); } // drop all info from session: diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 74b9dad6f3..1437138037 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -23,6 +23,9 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; +use Auth; +use Hash; +use Exception; use FireflyIII\Events\UserChangedEmail; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\ValidationException; @@ -203,7 +206,7 @@ class ProfileController extends Controller $existing = $repository->findByEmail($newEmail); if ($existing instanceof User) { // force user logout. - \Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function) + Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function) $request->session()->invalidate(); session()->flash('success', (string) trans('firefly.email_changed')); @@ -217,7 +220,7 @@ class ProfileController extends Controller event(new UserChangedEmail($user, $newEmail, $oldEmail)); // force user logout. - \Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function) + Auth::guard()->logout(); // @phpstan-ignore-line (does not recognize function) $request->session()->invalidate(); session()->flash('success', (string) trans('firefly.email_changed')); @@ -310,7 +313,7 @@ class ProfileController extends Controller return redirect(route('profile.index')); } - if (!\Hash::check($request->get('password'), auth()->user()->password)) { + if (!Hash::check($request->get('password'), auth()->user()->password)) { session()->flash('error', (string) trans('firefly.invalid_password')); return redirect(route('profile.delete-account')); @@ -343,8 +346,8 @@ class ProfileController extends Controller 'email' => auth()->user()->email, 'password' => $request->get('password'), ]; - if (\Auth::once($creds)) { - \Auth::logoutOtherDevices($request->get('password')); + if (Auth::once($creds)) { + Auth::logoutOtherDevices($request->get('password')); session()->flash('info', (string) trans('firefly.other_sessions_logged_out')); return redirect(route('profile.index')); @@ -359,7 +362,7 @@ class ProfileController extends Controller * * @return Redirector|RedirectResponse * - * @throws \Exception + * @throws Exception */ public function regenerate(Request $request) { diff --git a/app/Http/Controllers/Report/AccountController.php b/app/Http/Controllers/Report/AccountController.php index d99ec61237..dcd9464ce3 100644 --- a/app/Http/Controllers/Report/AccountController.php +++ b/app/Http/Controllers/Report/AccountController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -58,7 +59,7 @@ class AccountController extends Controller try { $result = view('reports.partials.accounts', compact('accountReport'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; diff --git a/app/Http/Controllers/Report/BalanceController.php b/app/Http/Controllers/Report/BalanceController.php index 914f12061c..41b3010a4a 100644 --- a/app/Http/Controllers/Report/BalanceController.php +++ b/app/Http/Controllers/Report/BalanceController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Exceptions\FireflyException; @@ -140,7 +141,7 @@ class BalanceController extends Controller try { $result = view('reports.partials.balance', compact('report'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.balance: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; diff --git a/app/Http/Controllers/Report/BillController.php b/app/Http/Controllers/Report/BillController.php index afbb68362c..1fd70e3c48 100644 --- a/app/Http/Controllers/Report/BillController.php +++ b/app/Http/Controllers/Report/BillController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Report\ReportHelperInterface; @@ -58,7 +59,7 @@ class BillController extends Controller try { $result = view('reports.partials.bills', compact('report'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index 67c316891d..f24dd2b551 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -176,7 +177,7 @@ class BudgetController extends Controller try { $result = view('reports.budget.partials.avg-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); app('log')->error($e->getTraceAsString()); @@ -326,7 +327,7 @@ class BudgetController extends Controller try { $result = view('reports.partials.budget-period', compact('report', 'periods'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; @@ -377,7 +378,7 @@ class BudgetController extends Controller try { $result = view('reports.budget.partials.top-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index 0168fdd75e..fc8d17421a 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -295,7 +296,7 @@ class CategoryController extends Controller try { $result = view('reports.category.partials.avg-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -345,7 +346,7 @@ class CategoryController extends Controller try { $result = view('reports.category.partials.avg-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -527,7 +528,7 @@ class CategoryController extends Controller try { $result = view('reports.partials.category-period', compact('report', 'periods'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage())); $result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage()); @@ -599,7 +600,7 @@ class CategoryController extends Controller try { $result = view('reports.partials.category-period', compact('report', 'periods'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage())); $result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage()); @@ -639,7 +640,7 @@ class CategoryController extends Controller try { $result = view('reports.partials.categories', compact('report'))->render(); $cache->store($result); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage())); $result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage()); @@ -687,7 +688,7 @@ class CategoryController extends Controller try { $result = view('reports.category.partials.top-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -735,7 +736,7 @@ class CategoryController extends Controller try { $result = view('reports.category.partials.top-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); diff --git a/app/Http/Controllers/Report/DoubleController.php b/app/Http/Controllers/Report/DoubleController.php index 79d9d5fc1e..32a1736844 100644 --- a/app/Http/Controllers/Report/DoubleController.php +++ b/app/Http/Controllers/Report/DoubleController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -102,7 +103,7 @@ class DoubleController extends Controller try { $result = view('reports.double.partials.avg-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -152,7 +153,7 @@ class DoubleController extends Controller try { $result = view('reports.double.partials.avg-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -429,7 +430,7 @@ class DoubleController extends Controller try { $result = view('reports.double.partials.top-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -477,7 +478,7 @@ class DoubleController extends Controller try { $result = view('reports.double.partials.top-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); diff --git a/app/Http/Controllers/Report/OperationsController.php b/app/Http/Controllers/Report/OperationsController.php index de27b13d04..d2aaeaa3dd 100644 --- a/app/Http/Controllers/Report/OperationsController.php +++ b/app/Http/Controllers/Report/OperationsController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -78,7 +79,7 @@ class OperationsController extends Controller try { $result = view('reports.partials.income-expenses', compact('report', 'type'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; @@ -112,7 +113,7 @@ class OperationsController extends Controller try { $result = view('reports.partials.income-expenses', compact('report', 'type'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; @@ -167,7 +168,7 @@ class OperationsController extends Controller try { $result = view('reports.partials.operations', compact('sums'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Could not render reports.partials.operations: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $result = 'Could not render view.'; diff --git a/app/Http/Controllers/Report/TagController.php b/app/Http/Controllers/Report/TagController.php index 0b8f8cde7b..22bca3fd99 100644 --- a/app/Http/Controllers/Report/TagController.php +++ b/app/Http/Controllers/Report/TagController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -292,7 +293,7 @@ class TagController extends Controller try { $result = view('reports.tag.partials.avg-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -342,7 +343,7 @@ class TagController extends Controller try { $result = view('reports.tag.partials.avg-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -490,7 +491,7 @@ class TagController extends Controller try { $result = view('reports.tag.partials.top-expenses', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); @@ -538,7 +539,7 @@ class TagController extends Controller try { $result = view('reports.tag.partials.top-income', compact('result'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage())); $result = sprintf('Could not render view: %s', $e->getMessage()); diff --git a/app/Http/Controllers/Rule/EditController.php b/app/Http/Controllers/Rule/EditController.php index c6f50d48ec..848fa259a3 100644 --- a/app/Http/Controllers/Rule/EditController.php +++ b/app/Http/Controllers/Rule/EditController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Rule; +use Throwable; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleFormRequest; @@ -177,7 +178,7 @@ class EditController extends Controller 'triggers' => $triggers, ] )->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { $message = sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()); app('log')->debug($message); app('log')->error($e->getTraceAsString()); diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index d6dae9d5fa..24c7dc0860 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Rule; +use Throwable; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -174,7 +175,7 @@ class SelectController extends Controller try { $view = view('list.journals-array-tiny', ['groups' => $collection])->render(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { app('log')->error(sprintf('Could not render view in testTriggers(): %s', $exception->getMessage())); app('log')->error($exception->getTraceAsString()); $view = sprintf('Could not render list.journals-tiny: %s', $exception->getMessage()); @@ -216,7 +217,7 @@ class SelectController extends Controller try { $view = view('list.journals-array-tiny', ['groups' => $collection])->render(); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $message = sprintf('Could not render view in testTriggersByRule(): %s', $exception->getMessage()); app('log')->error($message); app('log')->error($exception->getTraceAsString()); diff --git a/app/Http/Controllers/RuleGroup/ExecutionController.php b/app/Http/Controllers/RuleGroup/ExecutionController.php index 542d38d0a7..40419e9656 100644 --- a/app/Http/Controllers/RuleGroup/ExecutionController.php +++ b/app/Http/Controllers/RuleGroup/ExecutionController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\RuleGroup; +use Exception; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\SelectTransactionsRequest; @@ -64,7 +65,7 @@ class ExecutionController extends Controller /** * Execute the given rulegroup on a set of existing transactions. * - * @throws \Exception + * @throws Exception */ public function execute(SelectTransactionsRequest $request, RuleGroup $ruleGroup): RedirectResponse { diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index ceab9169c5..b30d1eefad 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; +use Throwable; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Support\Search\SearchInterface; @@ -118,7 +119,7 @@ class SearchController extends Controller try { $html = view('search.search', compact('groups', 'hasPages', 'searchTime'))->render(); - } catch (\Throwable $e) { + } catch (Throwable $e) { app('log')->error(sprintf('Cannot render search.search: %s', $e->getMessage())); app('log')->error($e->getTraceAsString()); $html = 'Could not render view.'; diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 55a0054632..b20228becc 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\System; +use Artisan; use Cache; use Exception; use FireflyIII\Exceptions\FireflyException; @@ -142,14 +143,14 @@ class InstallController extends Controller $this->keys(); } if ('generate-keys' !== $command) { - \Artisan::call($command, $args); - app('log')->debug(\Artisan::output()); + Artisan::call($command, $args); + app('log')->debug(Artisan::output()); } - } catch (\Exception $e) { // intentional generic exception + } catch (Exception $e) { // intentional generic exception throw new FireflyException($e->getMessage(), 0, $e); } // clear cache as well. - \Cache::clear(); + Cache::clear(); app('preferences')->mark(); return true; diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index 929d46ede7..d3b00a5738 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -82,7 +82,7 @@ class ConvertController extends Controller * * @return Factory|Redirector|RedirectResponse|View * - * @throws \Exception + * @throws Exception */ public function index(TransactionType $destinationType, TransactionGroup $group) { @@ -214,7 +214,7 @@ class ConvertController extends Controller } /** - * @throws \Exception + * @throws Exception */ private function getLiabilities(): array { @@ -238,7 +238,7 @@ class ConvertController extends Controller } /** - * @throws \Exception + * @throws Exception */ private function getAssetAccounts(): array { diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index aa44005821..bac580dc76 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Transaction; +use InvalidArgumentException; use Carbon\Carbon; use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Enums\TransactionTypeEnum; @@ -231,7 +232,7 @@ class MassController extends Controller try { $carbon = Carbon::parse($value[$journalId]); - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { Log::warning(sprintf('Could not parse "%s" but dont mind', $value[$journalId])); Log::warning($e->getMessage()); diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index a4de77717e..7f11d50cba 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Exceptions\FireflyException; use FireflyIII\User; use Illuminate\Auth\AuthenticationException; @@ -56,7 +57,7 @@ class Authenticate * @throws FireflyException * @throws AuthenticationException */ - public function handle($request, \Closure $next, ...$guards) + public function handle($request, Closure $next, ...$guards) { $this->authenticate($request, $guards); diff --git a/app/Http/Middleware/Binder.php b/app/Http/Middleware/Binder.php index 9f4413a06d..7b03830ba5 100644 --- a/app/Http/Middleware/Binder.php +++ b/app/Http/Middleware/Binder.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Support\Domain; use Illuminate\Contracts\Auth\Factory as Auth; use Illuminate\Http\Request; @@ -63,7 +64,7 @@ class Binder * * @return mixed */ - public function handle($request, \Closure $next) + public function handle($request, Closure $next) { foreach ($request->route()->parameters() as $key => $value) { if (array_key_exists($key, $this->binders)) { diff --git a/app/Http/Middleware/InstallationId.php b/app/Http/Middleware/InstallationId.php index 79ac8daedc..6c8aff7dab 100644 --- a/app/Http/Middleware/InstallationId.php +++ b/app/Http/Middleware/InstallationId.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Support\System\GeneratesInstallationId; use Illuminate\Http\Request; @@ -41,7 +42,7 @@ class InstallationId * * @return mixed */ - public function handle($request, \Closure $next) + public function handle($request, Closure $next) { $this->generateInstallationId(); diff --git a/app/Http/Middleware/Installer.php b/app/Http/Middleware/Installer.php index 1954f226bd..f7d38232ca 100644 --- a/app/Http/Middleware/Installer.php +++ b/app/Http/Middleware/Installer.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Support\System\OAuthKeys; use Illuminate\Database\QueryException; @@ -45,7 +46,7 @@ class Installer * * @throws FireflyException */ - public function handle($request, \Closure $next) + public function handle($request, Closure $next) { // Log::debug(sprintf('Installer middleware for URL %s', $request->url())); // ignore installer in test environment. diff --git a/app/Http/Middleware/InterestingMessage.php b/app/Http/Middleware/InterestingMessage.php index 49e013d5ed..30c9b65e68 100644 --- a/app/Http/Middleware/InterestingMessage.php +++ b/app/Http/Middleware/InterestingMessage.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Models\Account; use FireflyIII\Models\Bill; use FireflyIII\Models\GroupMembership; @@ -45,7 +46,7 @@ class InterestingMessage * * @return mixed */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, Closure $next) { if ($this->testing()) { return $next($request); diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php index c992713911..2412e607b7 100644 --- a/app/Http/Middleware/IsAdmin.php +++ b/app/Http/Middleware/IsAdmin.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Http\Request; @@ -40,7 +41,7 @@ class IsAdmin * * @return mixed */ - public function handle(Request $request, \Closure $next, $guard = null) + public function handle(Request $request, Closure $next, $guard = null) { if (Auth::guard($guard)->guest()) { if ($request->ajax()) { diff --git a/app/Http/Middleware/IsDemoUser.php b/app/Http/Middleware/IsDemoUser.php index c984e947a5..e792003b9a 100644 --- a/app/Http/Middleware/IsDemoUser.php +++ b/app/Http/Middleware/IsDemoUser.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Http\Request; @@ -37,7 +38,7 @@ class IsDemoUser * * @return mixed */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, Closure $next) { /** @var null|User $user */ $user = $request->user(); diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 7db74aa139..28f261e807 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; +use App; use Carbon\Carbon; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Facades\Amount; @@ -42,7 +44,7 @@ class Range * * @return mixed */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, Closure $next) { if (null !== $request->user()) { // set start, end and finish: @@ -101,7 +103,7 @@ class Range // get locale preference: $language = app('steam')->getLanguage(); $locale = app('steam')->getLocale(); - \App::setLocale($language); + App::setLocale($language); Carbon::setLocale(substr((string) $locale, 0, 2)); $localeArray = app('steam')->getLocaleArray($locale); diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 5bffbb7146..01cda1a816 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -39,7 +40,7 @@ class RedirectIfAuthenticated * * @return mixed */ - public function handle($request, \Closure $next, $guard = null) + public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return response()->redirectTo(route('index')); diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index 4ae071b11f..5f8b104992 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Closure; +use Exception; use Barryvdh\Debugbar\Facades\Debugbar; use Illuminate\Http\Request; use Illuminate\Support\Facades\Vite; @@ -38,9 +40,9 @@ class SecureHeaders * * @return mixed * - * @throws \Exception + * @throws Exception */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, Closure $next) { // generate and share nonce. $nonce = base64_encode(random_bytes(16)); diff --git a/app/Http/Middleware/StartFireflySession.php b/app/Http/Middleware/StartFireflySession.php index 03359f735a..922bc3ad8c 100644 --- a/app/Http/Middleware/StartFireflySession.php +++ b/app/Http/Middleware/StartFireflySession.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Override; use Illuminate\Contracts\Session\Session; use Illuminate\Http\Request; use Illuminate\Session\Middleware\StartSession; @@ -37,7 +38,7 @@ class StartFireflySession extends StartSession * * @param Session $session */ - #[\Override] + #[Override] protected function storeCurrentUrl(Request $request, $session): void { $url = $request->fullUrl(); diff --git a/app/Http/Middleware/TrustHosts.php b/app/Http/Middleware/TrustHosts.php index 9dcd6a249a..4446201045 100644 --- a/app/Http/Middleware/TrustHosts.php +++ b/app/Http/Middleware/TrustHosts.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; +use Override; use Illuminate\Http\Middleware\TrustHosts as Middleware; class TrustHosts extends Middleware @@ -33,7 +34,7 @@ class TrustHosts extends Middleware * * @return array */ - #[\Override] + #[Override] public function hosts(): array { return [ diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.php index bf7e4417bb..8c5de287d4 100644 --- a/app/Http/Requests/ReportFormRequest.php +++ b/app/Http/Requests/ReportFormRequest.php @@ -149,7 +149,7 @@ class ReportFormRequest extends FormRequest if (false !== $result && 0 !== $result) { try { $date = new Carbon($parts[1]); - } catch (\Exception $e) { // intentional generic exception + } catch (Exception $e) { // intentional generic exception $error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage()); app('log')->error($error); app('log')->error($e->getTraceAsString()); @@ -187,7 +187,7 @@ class ReportFormRequest extends FormRequest if (false !== $result && 0 !== $result) { try { $date = new Carbon($parts[0]); - } catch (\Exception $e) { // intentional generic exception + } catch (Exception $e) { // intentional generic exception $error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage()); app('log')->error($error); app('log')->error($e->getTraceAsString()); diff --git a/config/session.php b/config/session.php index 37a9a0b86e..84df47ec36 100644 --- a/config/session.php +++ b/config/session.php @@ -32,7 +32,7 @@ return [ 'table' => 'sessions', 'store' => null, 'lottery' => [2, 100], - 'cookie' => 'firefly_session', + 'cookie' => env('COOKIE_NAME','firefly_iii_session'), 'path' => env('COOKIE_PATH', '/'), 'domain' => env('COOKIE_DOMAIN', null), 'secure' => env('COOKIE_SECURE', null), From e333dedeecf8afb468127c0df4e25611fb39e15e Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 May 2025 17:07:12 +0200 Subject: [PATCH 2/4] Replace magic facades. --- .../TransactionCurrency/DestroyController.php | 2 +- .../TransactionLinkType/StoreController.php | 2 +- .../TransactionLinkType/UpdateController.php | 2 +- .../System/ConfigurationController.php | 2 +- app/Http/Controllers/Controller.php | 2 +- .../Controllers/Profile/MfaController.php | 4 +- app/Http/Controllers/ProfileController.php | 4 +- .../Controllers/System/InstallController.php | 4 +- app/Http/Middleware/Range.php | 2 +- app/Support/ExpandedForm.php | 4 +- .../Http/Controllers/RequestInformation.php | 2 +- app/Support/Twig/General.php | 2 +- config/app.php | 106 +----------------- 13 files changed, 19 insertions(+), 119 deletions(-) diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php index 263d6bc350..e22212bd46 100644 --- a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php +++ b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionCurrency; -use Validator; +use Illuminate\Support\Facades\Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionCurrency; diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php index b779934ea6..e9aef4aa2a 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/StoreController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionLinkType; -use Validator; +use Illuminate\Support\Facades\Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\TransactionLinkType\StoreRequest; use FireflyIII\Exceptions\FireflyException; diff --git a/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php b/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php index b1f06549ce..a530836684 100644 --- a/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php +++ b/app/Api/V1/Controllers/Models/TransactionLinkType/UpdateController.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\TransactionLinkType; +use Illuminate\Support\Facades\Validator; -use Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\Models\TransactionLinkType\UpdateRequest; use FireflyIII\Exceptions\FireflyException; diff --git a/app/Api/V1/Controllers/System/ConfigurationController.php b/app/Api/V1/Controllers/System/ConfigurationController.php index 35e84f41b9..281c0712f8 100644 --- a/app/Api/V1/Controllers/System/ConfigurationController.php +++ b/app/Api/V1/Controllers/System/ConfigurationController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\System; -use Validator; +use Illuminate\Support\Facades\Validator; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\System\UpdateRequest; use FireflyIII\Exceptions\FireflyException; diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 50fc2118a4..7756ca861b 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -36,7 +36,7 @@ use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\View; -use Route; +use Illuminate\Support\Facades\Route; /** * Class Controller. diff --git a/app/Http/Controllers/Profile/MfaController.php b/app/Http/Controllers/Profile/MfaController.php index 5d70a3b3f4..333801c380 100644 --- a/app/Http/Controllers/Profile/MfaController.php +++ b/app/Http/Controllers/Profile/MfaController.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Profile; -use Cookie; -use Google2FA; +use Illuminate\Support\Facades\Cookie; +use PragmaRX\Google2FALaravel\Facade as Google2FA; use Carbon\Carbon; use FireflyIII\Events\Security\DisabledMFA; use FireflyIII\Events\Security\EnabledMFA; diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 1437138037..b8645a31ec 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; -use Auth; -use Hash; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; use Exception; use FireflyIII\Events\UserChangedEmail; use FireflyIII\Exceptions\FireflyException; diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index b20228becc..e2acfb680f 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\System; -use Artisan; -use Cache; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Cache; use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 28f261e807..4699a454c0 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Middleware; use Closure; -use App; +use Illuminate\Support\Facades\App; use Carbon\Carbon; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Facades\Amount; diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php index f5cbb3b6e1..68e2c07064 100644 --- a/app/Support/ExpandedForm.php +++ b/app/Support/ExpandedForm.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Support; -use Eloquent; +use Illuminate\Database\Eloquent\Model; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Support\Form\FormSupport; use Illuminate\Support\Collection; @@ -205,7 +205,7 @@ class ExpandedForm $selectList[0] = '(none)'; $fields = ['title', 'name', 'description']; - /** @var \Eloquent $entry */ + /** @var Model $entry */ foreach ($set as $entry) { // All Eloquent models have an ID $entryId = $entry->id; diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index 7f18f6fe3c..96e6edcfac 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -33,7 +33,7 @@ use FireflyIII\User; use Illuminate\Contracts\Validation\Validator as ValidatorContract; use Illuminate\Routing\Route; use Illuminate\Support\Facades\Validator; -use Route as RouteFacade; +use Illuminate\Support\Facades\Route as RouteFacade; /** * Trait RequestInformation diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 96b7475dac..4ae8da0019 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -33,7 +33,7 @@ use FireflyIII\Support\Facades\Steam; use FireflyIII\Support\Search\OperatorQuerySearch; use Illuminate\Support\Facades\Log; use League\CommonMark\GithubFlavoredMarkdownConverter; -use Route; +use Illuminate\Support\Facades\Route; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; diff --git a/config/app.php b/config/app.php index dd2a1b6458..27be7859cc 100644 --- a/config/app.php +++ b/config/app.php @@ -41,16 +41,6 @@ use FireflyIII\Providers\RuleServiceProvider; use FireflyIII\Providers\SearchServiceProvider; use FireflyIII\Providers\SessionServiceProvider; use FireflyIII\Providers\TagServiceProvider; -use FireflyIII\Support\Facades\AccountForm; -use FireflyIII\Support\Facades\Amount; -use FireflyIII\Support\Facades\CurrencyForm; -use FireflyIII\Support\Facades\ExpandedForm; -use FireflyIII\Support\Facades\FireflyConfig; -use FireflyIII\Support\Facades\Navigation; -use FireflyIII\Support\Facades\PiggyBankForm; -use FireflyIII\Support\Facades\Preferences; -use FireflyIII\Support\Facades\RuleForm; -use FireflyIII\Support\Facades\Steam; use Illuminate\Auth\AuthServiceProvider; use Illuminate\Auth\Passwords\PasswordResetServiceProvider; use Illuminate\Broadcasting\BroadcastServiceProvider; @@ -58,7 +48,6 @@ use Illuminate\Bus\BusServiceProvider; use Illuminate\Cache\CacheServiceProvider; use Illuminate\Cookie\CookieServiceProvider; use Illuminate\Database\DatabaseServiceProvider; -use Illuminate\Database\Eloquent\Model; use Illuminate\Encryption\EncryptionServiceProvider; use Illuminate\Filesystem\FilesystemServiceProvider; use Illuminate\Foundation\Providers\ConsoleSupportServiceProvider; @@ -70,47 +59,9 @@ use Illuminate\Pagination\PaginationServiceProvider; use Illuminate\Pipeline\PipelineServiceProvider; use Illuminate\Queue\QueueServiceProvider; use Illuminate\Redis\RedisServiceProvider; -use Illuminate\Support\Arr; -use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Blade; -use Illuminate\Support\Facades\Broadcast; -use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Config; -use Illuminate\Support\Facades\Cookie; -use Illuminate\Support\Facades\Crypt; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\Gate; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Lang; -use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\Notification; -use Illuminate\Support\Facades\Password; -use Illuminate\Support\Facades\Queue; -use Illuminate\Support\Facades\Redirect; -use Illuminate\Support\Facades\Redis; -use Illuminate\Support\Facades\Request; -use Illuminate\Support\Facades\Response; -use Illuminate\Support\Facades\Route; -use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\Session; -use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\URL; -use Illuminate\Support\Facades\Validator; -use Illuminate\Support\Facades\View; -use Illuminate\Support\Str; use Illuminate\Translation\TranslationServiceProvider; use Illuminate\Validation\ValidationServiceProvider; use Illuminate\View\ViewServiceProvider; -use PragmaRX\Google2FALaravel\Facade; -use Spatie\Html\Facades\Html; -use TwigBridge\Facade\Twig; use TwigBridge\ServiceProvider; return [ @@ -178,60 +129,9 @@ return [ AdminServiceProvider::class, RecurringServiceProvider::class, ], - 'aliases' => [ - 'App' => App::class, - 'Artisan' => Artisan::class, - 'Auth' => Auth::class, - 'Blade' => Blade::class, - 'Broadcast' => Broadcast::class, - 'Bus' => Bus::class, - 'Cache' => Cache::class, - 'Config' => Config::class, - 'Cookie' => Cookie::class, - 'Crypt' => Crypt::class, - 'DB' => DB::class, - 'Eloquent' => Model::class, - 'Event' => Event::class, - 'File' => File::class, - 'Gate' => Gate::class, - 'Hash' => Hash::class, - 'Lang' => Lang::class, - 'Log' => Log::class, - 'Mail' => Mail::class, - 'Notification' => Notification::class, - 'Password' => Password::class, - 'Queue' => Queue::class, - 'Redirect' => Redirect::class, - 'Redis' => Redis::class, - 'Request' => Request::class, - 'Response' => Response::class, - 'Route' => Route::class, - 'Schema' => Schema::class, - 'Session' => Session::class, - 'Storage' => Storage::class, - 'URL' => URL::class, - 'Validator' => Validator::class, - 'View' => View::class, - 'Html' => Html::class, - 'Preferences' => Preferences::class, - 'FireflyConfig' => FireflyConfig::class, - 'Navigation' => Navigation::class, - 'Amount' => Amount::class, - 'Steam' => Steam::class, - 'ExpandedForm' => ExpandedForm::class, - 'CurrencyForm' => CurrencyForm::class, - 'AccountForm' => AccountForm::class, - 'PiggyBankForm' => PiggyBankForm::class, - 'RuleForm' => RuleForm::class, - 'Google2FA' => Facade::class, - 'Twig' => Twig::class, + 'aliases' => [], - 'Arr' => Arr::class, - 'Http' => Http::class, - 'Str' => Str::class, - ], - - 'asset_url' => env('ASSET_URL', null), + 'asset_url' => env('ASSET_URL', null), /* |-------------------------------------------------------------------------- @@ -244,5 +144,5 @@ return [ | */ - 'faker_locale' => 'en_US', + 'faker_locale' => 'en_US', ]; From b830bd2732010c73474c908435a41a1172be599c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 May 2025 17:15:46 +0200 Subject: [PATCH 3/4] Replace magic facades --- app/Factory/TransactionFactory.php | 3 ++- app/Handlers/Events/UserEventHandler.php | 7 ++++--- app/Jobs/MailError.php | 3 ++- app/Providers/AppServiceProvider.php | 2 +- .../Internal/Support/AccountServiceTrait.php | 3 ++- app/Support/FireflyConfig.php | 15 ++++++++------- app/Support/System/OAuthKeys.php | 5 +++-- app/Support/Twig/General.php | 6 +++--- app/User.php | 3 ++- app/Validation/FireflyValidator.php | 5 +++-- routes/api-noauth.php | 2 ++ routes/api.php | 2 ++ routes/channels.php | 1 + routes/web.php | 4 +++- 14 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/Factory/TransactionFactory.php b/app/Factory/TransactionFactory.php index 83294e2045..1065b7bda3 100644 --- a/app/Factory/TransactionFactory.php +++ b/app/Factory/TransactionFactory.php @@ -32,6 +32,7 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\UniqueIban; use FireflyIII\Services\Internal\Update\AccountUpdateService; use Illuminate\Database\QueryException; +use Illuminate\Support\Facades\Validator; /** * Class TransactionFactory @@ -152,7 +153,7 @@ class TransactionFactory return; } // validate info: - $validator = \Validator::make(['iban' => $this->accountInformation['iban']], [ + $validator = Validator::make(['iban' => $this->accountInformation['iban']], [ 'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)], ]); if ($validator->fails()) { diff --git a/app/Handlers/Events/UserEventHandler.php b/app/Handlers/Events/UserEventHandler.php index 62643d884e..261a4bda33 100644 --- a/app/Handlers/Events/UserEventHandler.php +++ b/app/Handlers/Events/UserEventHandler.php @@ -54,6 +54,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Auth\Events\Login; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Notification; use Mail; @@ -266,7 +267,7 @@ class UserEventHandler $url = route('profile.confirm-email-change', [$token->data]); try { - \Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url)); + Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url)); } catch (\Exception $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); @@ -291,7 +292,7 @@ class UserEventHandler $url = route('profile.undo-email-change', [$token->data, $hashed]); try { - \Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url)); + Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url)); } catch (\Exception $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); @@ -355,7 +356,7 @@ class UserEventHandler $url = route('invite', [$event->invitee->invite_code]); try { - \Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url)); + Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url)); } catch (\Exception $e) { app('log')->error($e->getMessage()); app('log')->error($e->getTraceAsString()); diff --git a/app/Jobs/MailError.php b/app/Jobs/MailError.php index 7b906b93a6..229a55b28d 100644 --- a/app/Jobs/MailError.php +++ b/app/Jobs/MailError.php @@ -28,6 +28,7 @@ use Illuminate\Mail\Message; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Mail; use Symfony\Component\Mailer\Exception\TransportException; /** @@ -70,7 +71,7 @@ class MailError extends Job implements ShouldQueue if ($this->attempts() < 3 && '' !== $email) { try { - \Mail::send( + Mail::send( ['emails.error-html', 'emails.error-text'], $args, static function (Message $message) use ($email): void { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ec474c598b..7de4243aaf 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -59,7 +59,7 @@ class AppServiceProvider extends ServiceProvider // blade extension Blade::directive('activeXRoutePartial', function (string $route) { - $name = \Route::getCurrentRoute()->getName() ?? ''; + $name = Route::getCurrentRoute()->getName() ?? ''; if (str_contains($name, $route)) { return 'menu-open'; } diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index 787a08c239..15fe51dfdd 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -39,6 +39,7 @@ use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService; +use Illuminate\Support\Facades\Validator; /** * Trait AccountServiceTrait @@ -54,7 +55,7 @@ trait AccountServiceTrait } $data = ['iban' => $iban]; $rules = ['iban' => 'required|iban']; - $validator = \Validator::make($data, $rules); + $validator = Validator::make($data, $rules); if ($validator->fails()) { app('log')->info(sprintf('Detected invalid IBAN ("%s"). Return NULL instead.', $iban)); diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index a9e182b519..009fc71390 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -28,6 +28,7 @@ use FireflyIII\Models\Configuration; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\EncryptException; use Illuminate\Database\QueryException; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; /** @@ -38,8 +39,8 @@ class FireflyConfig public function delete(string $name): void { $fullName = 'ff-config-'.$name; - if (\Cache::has($fullName)) { - \Cache::forget($fullName); + if (Cache::has($fullName)) { + Cache::forget($fullName); } Configuration::where('name', $name)->forceDelete(); } @@ -80,8 +81,8 @@ class FireflyConfig public function get(string $name, mixed $default = null): ?Configuration { $fullName = 'ff-config-'.$name; - if (\Cache::has($fullName)) { - return \Cache::get($fullName); + if (Cache::has($fullName)) { + return Cache::get($fullName); } try { @@ -92,7 +93,7 @@ class FireflyConfig } if (null !== $config) { - \Cache::forever($fullName, $config); + Cache::forever($fullName, $config); return $config; } @@ -122,13 +123,13 @@ class FireflyConfig $item->name = $name; $item->data = $value; $item->save(); - \Cache::forget('ff-config-'.$name); + Cache::forget('ff3-config-'.$name); return $item; } $config->data = $value; $config->save(); - \Cache::forget('ff-config-'.$name); + Cache::forget('ff3-config-'.$name); return $config; } diff --git a/app/Support/System/OAuthKeys.php b/app/Support/System/OAuthKeys.php index e0c0fa0b7a..0ba89c644d 100644 --- a/app/Support/System/OAuthKeys.php +++ b/app/Support/System/OAuthKeys.php @@ -26,6 +26,7 @@ namespace FireflyIII\Support\System; use FireflyIII\Exceptions\FireflyException; use Illuminate\Contracts\Encryption\DecryptException; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Crypt; use Laravel\Passport\Console\KeysCommand; use Psr\Container\ContainerExceptionInterface; @@ -88,8 +89,8 @@ class OAuthKeys public static function generateKeys(): void { - \Artisan::registerCommand(new KeysCommand()); - \Artisan::call('firefly-iii:laravel-passport-keys'); + Artisan::registerCommand(new KeysCommand()); + Artisan::call('firefly-iii:laravel-passport-keys'); } public static function storeKeysInDB(): void diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 4ae8da0019..6e369e4086 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -247,7 +247,7 @@ class General extends AbstractExtension static function (): string { $args = func_get_args(); $route = $args[0]; // name of the route. - $name = \Route::getCurrentRoute()->getName() ?? ''; + $name = Route::getCurrentRoute()->getName() ?? ''; if (str_contains($name, $route)) { return 'active'; } @@ -271,7 +271,7 @@ class General extends AbstractExtension if ($objectType === $activeObjectType && false !== stripos( - (string) \Route::getCurrentRoute()->getName(), + (string) Route::getCurrentRoute()->getName(), (string) $route )) { return 'active'; @@ -294,7 +294,7 @@ class General extends AbstractExtension static function (): string { $args = func_get_args(); $route = $args[0]; // name of the route. - $name = \Route::getCurrentRoute()->getName() ?? ''; + $name = Route::getCurrentRoute()->getName() ?? ''; if (str_contains($name, $route)) { return 'menu-open'; } diff --git a/app/User.php b/app/User.php index 51d27e3b6f..f6bc724e5f 100644 --- a/app/User.php +++ b/app/User.php @@ -61,6 +61,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Request; use Illuminate\Support\Str; use Laravel\Passport\HasApiTokens; use NotificationChannels\Pushover\PushoverReceiver; @@ -464,7 +465,7 @@ class User extends Authenticatable */ public function sendPasswordResetNotification($token): void { - $ipAddress = \Request::ip(); + $ipAddress = Request::ip(); event(new RequestedNewPassword($this, $token, $ipAddress)); } diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 86409ed951..0ea1c687fd 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -44,6 +44,7 @@ use Illuminate\Validation\Validator; use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; +use PragmaRX\Google2FALaravel\Facade; /** * Class FireflyValidator. @@ -79,7 +80,7 @@ class FireflyValidator extends Validator } $secret = (string) $secret; - return (bool) \Google2FA::verifyKey($secret, $value); + return (bool) Facade::verifyKey($secret, $value); } /** @@ -131,7 +132,7 @@ class FireflyValidator extends Validator } $secret = (string) $user->mfa_secret; - return (bool) \Google2FA::verifyKey($secret, $value); + return (bool) Facade::verifyKey($secret, $value); } /** diff --git a/routes/api-noauth.php b/routes/api-noauth.php index 7e4e1da126..743ec20051 100644 --- a/routes/api-noauth.php +++ b/routes/api-noauth.php @@ -22,6 +22,8 @@ declare(strict_types=1); +use Illuminate\Support\Facades\Route; + // Cron job API routes: use FireflyIII\Http\Middleware\AcceptHeaders; diff --git a/routes/api.php b/routes/api.php index 02bd5643ca..9be3f75bfa 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,6 +22,8 @@ declare(strict_types=1); +use Illuminate\Support\Facades\Route; + /* * * ____ ____ ___ .______ ______ __ __ .___________. _______ _______. diff --git a/routes/channels.php b/routes/channels.php index 702805feed..25c8051eec 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -22,6 +22,7 @@ declare(strict_types=1); +use Illuminate\Support\Facades\Broadcast; /* |-------------------------------------------------------------------------- | Broadcast Channels diff --git a/routes/web.php b/routes/web.php index ee6039a7ae..2fa1d255b6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,9 +19,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - declare(strict_types=1); +use Illuminate\Support\Facades\Route; + + if (!defined('DATEFORMAT')) { define('DATEFORMAT', '(19|20)[0-9]{2}-?[0-9]{2}-?[0-9]{2}'); } From f780de9e716b15be34aff16a6c7a3571d0d4a68d Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 24 May 2025 17:19:18 +0200 Subject: [PATCH 4/4] Replace magic facades --- app/Console/Commands/Correction/CorrectsDatabase.php | 3 ++- app/Console/Commands/Integrity/ReportsIntegrity.php | 3 ++- app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/Correction/CorrectsDatabase.php b/app/Console/Commands/Correction/CorrectsDatabase.php index 1d9ea62112..974d4a19c0 100644 --- a/app/Console/Commands/Correction/CorrectsDatabase.php +++ b/app/Console/Commands/Correction/CorrectsDatabase.php @@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Correction; use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Schema; class CorrectsDatabase extends Command { @@ -40,7 +41,7 @@ class CorrectsDatabase extends Command public function handle(): int { // if table does not exist, return false - if (!\Schema::hasTable('users')) { + if (!Schema::hasTable('users')) { $this->friendlyError('No "users"-table, will not continue.'); return 1; diff --git a/app/Console/Commands/Integrity/ReportsIntegrity.php b/app/Console/Commands/Integrity/ReportsIntegrity.php index 2ac856b24b..46e5427ad6 100644 --- a/app/Console/Commands/Integrity/ReportsIntegrity.php +++ b/app/Console/Commands/Integrity/ReportsIntegrity.php @@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Integrity; use FireflyIII\Console\Commands\ShowsFriendlyMessages; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Schema; class ReportsIntegrity extends Command { @@ -41,7 +42,7 @@ class ReportsIntegrity extends Command public function handle(): int { // if table does not exist, return false - if (!\Schema::hasTable('users')) { + if (!Schema::hasTable('users')) { return 1; } $commands = [ diff --git a/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php b/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php index 281078dee2..aa2b108dea 100644 --- a/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php +++ b/app/Console/Commands/Upgrade/AddsTransactionIdentifiers.php @@ -31,6 +31,7 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface; use Illuminate\Console\Command; use Illuminate\Database\QueryException; +use Illuminate\Support\Facades\Schema; class AddsTransactionIdentifiers extends Command { @@ -65,7 +66,7 @@ class AddsTransactionIdentifiers extends Command } // if table does not exist, return false - if (!\Schema::hasTable('transaction_journals')) { + if (!Schema::hasTable('transaction_journals')) { return 0; }