From 6cfdc58cb1fbb5c5391cd13dfd89fa7c00661c48 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 29 Dec 2022 19:42:26 +0100 Subject: [PATCH] Various PSR12 code cleanup --- .../ObjectGroup/DeleteController.php | 10 +- .../ObjectGroup/EditController.php | 14 +- .../ObjectGroup/IndexController.php | 10 +- .../PiggyBank/AmountController.php | 30 +- .../PiggyBank/CreateController.php | 12 +- .../PiggyBank/DeleteController.php | 10 +- .../Controllers/PiggyBank/IndexController.php | 58 +- .../Controllers/PiggyBank/ShowController.php | 4 +- .../Controllers/Popup/ReportController.php | 3 +- .../Recurring/CreateController.php | 54 +- .../Recurring/DeleteController.php | 14 +- .../Controllers/Recurring/EditController.php | 42 +- .../Controllers/Recurring/IndexController.php | 15 +- .../Recurring/TriggerController.php | 1 + .../Controllers/Report/AccountController.php | 8 +- .../Controllers/Report/BalanceController.php | 37 +- .../Controllers/Report/BillController.php | 7 +- .../Controllers/Report/BudgetController.php | 173 ++-- .../Controllers/Report/CategoryController.php | 341 ++++---- .../Controllers/Report/DoubleController.php | 281 +++---- .../Report/OperationsController.php | 38 +- app/Http/Controllers/Report/TagController.php | 280 +++---- .../Controllers/Rule/CreateController.php | 53 +- .../Controllers/Rule/DeleteController.php | 10 +- app/Http/Controllers/Rule/EditController.php | 28 +- app/Http/Controllers/Rule/IndexController.php | 15 +- .../Controllers/Rule/SelectController.php | 24 +- .../RuleGroup/CreateController.php | 10 +- .../RuleGroup/DeleteController.php | 14 +- .../Controllers/RuleGroup/EditController.php | 28 +- .../RuleGroup/ExecutionController.php | 12 +- .../System/HealthcheckController.php | 1 + .../Controllers/System/InstallController.php | 14 +- .../Transaction/BulkController.php | 34 +- .../Transaction/ConvertController.php | 57 +- .../Transaction/CreateController.php | 23 +- .../Transaction/DeleteController.php | 11 +- .../Transaction/EditController.php | 4 +- .../Transaction/IndexController.php | 50 +- .../Transaction/LinkController.php | 31 +- .../Transaction/MassController.php | 51 +- .../Transaction/ShowController.php | 22 +- .../Controllers/Webhooks/CreateController.php | 4 +- .../Controllers/Webhooks/DeleteController.php | 9 +- .../Controllers/Webhooks/EditController.php | 9 +- .../Controllers/Webhooks/IndexController.php | 5 +- .../Controllers/Webhooks/ShowController.php | 9 +- app/Http/Middleware/AcceptHeaders.php | 7 +- app/Http/Middleware/Authenticate.php | 18 +- app/Http/Middleware/Binder.php | 13 +- app/Http/Middleware/EncryptCookies.php | 1 + app/Http/Middleware/InstallationId.php | 4 +- app/Http/Middleware/Installer.php | 16 +- app/Http/Middleware/InterestingMessage.php | 73 +- app/Http/Middleware/IsAdmin.php | 7 +- app/Http/Middleware/IsDemoUser.php | 7 +- app/Http/Middleware/Range.php | 11 +- .../Middleware/RedirectIfAuthenticated.php | 7 +- app/Http/Middleware/SecureHeaders.php | 12 +- app/Http/Middleware/StartFireflySession.php | 5 +- app/Http/Middleware/TrimStrings.php | 1 + app/Http/Middleware/TrustProxies.php | 3 +- app/Http/Middleware/VerifyCsrfToken.php | 1 + app/Http/Requests/AccountFormRequest.php | 9 +- app/Http/Requests/AttachmentFormRequest.php | 1 + app/Http/Requests/BillStoreRequest.php | 1 + app/Http/Requests/BillUpdateRequest.php | 1 + app/Http/Requests/BudgetFormStoreRequest.php | 3 +- app/Http/Requests/BudgetFormUpdateRequest.php | 5 +- app/Http/Requests/BudgetIncomeRequest.php | 1 + app/Http/Requests/BulkEditJournalRequest.php | 1 + app/Http/Requests/CategoryFormRequest.php | 3 +- app/Http/Requests/ConfigurationRequest.php | 1 + app/Http/Requests/CurrencyFormRequest.php | 1 + .../Requests/DeleteAccountFormRequest.php | 1 + app/Http/Requests/EmailFormRequest.php | 1 + app/Http/Requests/JournalLinkRequest.php | 3 +- app/Http/Requests/LinkTypeFormRequest.php | 1 + .../Requests/MassDeleteJournalRequest.php | 1 + app/Http/Requests/MassEditJournalRequest.php | 1 + app/Http/Requests/NewUserFormRequest.php | 1 + app/Http/Requests/ObjectGroupFormRequest.php | 1 + app/Http/Requests/PiggyBankStoreRequest.php | 1 + app/Http/Requests/PiggyBankUpdateRequest.php | 1 + app/Http/Requests/ProfileFormRequest.php | 1 + app/Http/Requests/RecurrenceFormRequest.php | 26 +- app/Http/Requests/ReportFormRequest.php | 15 +- app/Http/Requests/RuleGroupFormRequest.php | 3 +- .../Requests/SelectTransactionsRequest.php | 5 +- app/Http/Requests/TagFormRequest.php | 3 +- app/Http/Requests/TestRuleFormRequest.php | 3 +- app/Http/Requests/TokenFormRequest.php | 1 + .../Requests/TriggerRecurrenceRequest.php | 1 + app/Http/Requests/UserFormRequest.php | 1 + app/Http/Requests/UserRegistrationRequest.php | 1 + app/Jobs/CreateAutoBudgetLimits.php | 30 +- app/Jobs/CreateRecurringTransactions.php | 22 +- app/Jobs/DownloadExchangeRates.php | 36 +- app/Jobs/Job.php | 1 + app/Jobs/MailError.php | 15 +- app/Jobs/SendWebhookMessage.php | 2 +- app/Jobs/WarnAboutBills.php | 20 +- app/Mail/AccessTokenCreatedMail.php | 2 +- app/Mail/AdminTestMail.php | 3 +- app/Mail/BillWarningMail.php | 10 +- app/Mail/ConfirmEmailChangeMail.php | 9 +- app/Mail/InvitationMail.php | 14 +- app/Mail/NewIPAddressWarningMail.php | 6 +- app/Mail/OAuthTokenCreatedMail.php | 4 +- app/Mail/RegisteredUser.php | 4 +- app/Mail/ReportNewJournalsMail.php | 5 +- app/Mail/RequestedNewPassword.php | 4 +- app/Mail/UndoEmailChangeMail.php | 9 +- app/Models/Account.php | 109 +-- app/Models/AccountMeta.php | 17 +- app/Models/AccountType.php | 11 +- app/Models/Attachment.php | 65 +- app/Models/AuditLogEntry.php | 37 +- app/Models/AutoBudget.php | 23 +- app/Models/AvailableBudget.php | 35 +- app/Models/Bill.php | 112 +-- app/Models/Budget.php | 69 +- app/Models/BudgetLimit.php | 31 +- app/Models/Category.php | 56 +- app/Models/Configuration.php | 11 +- app/Models/CurrencyExchangeRate.php | 41 +- app/Models/GroupMembership.php | 18 +- app/Models/InvitedUser.php | 30 +- app/Models/LinkType.php | 25 +- app/Models/Location.php | 24 +- app/Models/Note.php | 17 +- app/Models/ObjectGroup.php | 48 +- app/Models/PiggyBank.php | 55 +- app/Models/PiggyBankEvent.php | 23 +- app/Models/PiggyBankRepetition.php | 25 +- app/Models/Preference.php | 17 +- app/Models/Recurrence.php | 76 +- app/Models/RecurrenceMeta.php | 14 +- app/Models/RecurrenceRepetition.php | 19 +- app/Models/RecurrenceTransaction.php | 52 +- app/Models/RecurrenceTransactionMeta.php | 14 +- app/Models/Role.php | 15 +- app/Models/Rule.php | 63 +- app/Models/RuleAction.php | 17 +- app/Models/RuleGroup.php | 49 +- app/Models/RuleTrigger.php | 17 +- app/Models/Tag.php | 61 +- app/Models/Transaction.php | 84 +- app/Models/TransactionCurrency.php | 33 +- app/Models/TransactionGroup.php | 41 +- app/Models/TransactionJournal.php | 142 ++-- app/Models/TransactionJournalLink.php | 29 +- app/Models/TransactionJournalMeta.php | 21 +- app/Models/TransactionType.php | 16 +- app/Models/UserGroup.php | 12 +- app/Models/UserRole.php | 16 +- app/Models/Webhook.php | 196 ++--- app/Models/WebhookAttempt.php | 20 +- app/Models/WebhookMessage.php | 30 +- app/Notifications/Admin/TestNotification.php | 72 +- app/Notifications/Admin/UserInvitation.php | 74 +- app/Notifications/Admin/UserRegistration.php | 72 +- .../Admin/VersionCheckResult.php | 78 +- app/Notifications/User/BillReminder.php | 38 +- app/Notifications/User/NewAccessToken.php | 69 +- .../User/TransactionCreation.php | 49 +- app/Notifications/User/UserLogin.php | 26 +- app/Notifications/User/UserNewPassword.php | 48 +- app/Notifications/User/UserRegistration.php | 48 +- app/Providers/AccountServiceProvider.php | 1 + app/Providers/AdminServiceProvider.php | 1 + app/Providers/AppServiceProvider.php | 7 +- app/Providers/AttachmentServiceProvider.php | 1 + app/Providers/AuthServiceProvider.php | 1 + app/Providers/BillServiceProvider.php | 1 + app/Providers/BroadcastServiceProvider.php | 1 + app/Providers/BudgetServiceProvider.php | 1 + app/Providers/CategoryServiceProvider.php | 1 + app/Providers/CurrencyServiceProvider.php | 1 + app/Providers/EventServiceProvider.php | 34 +- app/Providers/FireflyServiceProvider.php | 1 + app/Providers/FireflySessionProvider.php | 1 + app/Providers/JournalServiceProvider.php | 1 + app/Providers/PiggyBankServiceProvider.php | 1 + app/Providers/RecurringServiceProvider.php | 1 + app/Providers/RouteServiceProvider.php | 1 + app/Providers/RuleGroupServiceProvider.php | 1 + app/Providers/RuleServiceProvider.php | 1 + app/Providers/SearchServiceProvider.php | 1 + app/Providers/SessionServiceProvider.php | 1 + app/Providers/TagServiceProvider.php | 1 + .../Account/AccountRepository.php | 168 ++-- .../Account/AccountRepositoryInterface.php | 91 +- app/Repositories/Account/AccountTasker.php | 122 +-- .../Account/AccountTaskerInterface.php | 21 +- .../Account/OperationsRepository.php | 256 +++--- .../Account/OperationsRepositoryInterface.php | 86 +- .../Attachment/AttachmentRepository.php | 91 +- .../AttachmentRepositoryInterface.php | 17 +- .../AuditLogEntry/ALERepository.php | 16 +- .../AuditLogEntry/ALERepositoryInterface.php | 14 +- app/Repositories/Bill/BillRepository.php | 790 +++++++++--------- .../Bill/BillRepositoryInterface.php | 145 ++-- .../Budget/AvailableBudgetRepository.php | 126 +-- .../AvailableBudgetRepositoryInterface.php | 56 +- .../Budget/BudgetLimitRepository.php | 134 +-- .../Budget/BudgetLimitRepositoryInterface.php | 50 +- app/Repositories/Budget/BudgetRepository.php | 509 +++++------ .../Budget/BudgetRepositoryInterface.php | 55 +- .../Budget/NoBudgetRepository.php | 76 +- .../Budget/NoBudgetRepositoryInterface.php | 22 +- .../Budget/OperationsRepository.php | 155 ++-- .../Budget/OperationsRepositoryInterface.php | 40 +- .../Category/CategoryRepository.php | 65 +- .../Category/CategoryRepositoryInterface.php | 49 +- .../Category/NoCategoryRepository.php | 140 ++-- .../NoCategoryRepositoryInterface.php | 32 +- .../Category/OperationsRepository.php | 226 ++--- .../OperationsRepositoryInterface.php | 58 +- .../Currency/CurrencyRepository.php | 153 ++-- .../Currency/CurrencyRepositoryInterface.php | 79 +- .../Journal/JournalAPIRepository.php | 8 +- .../Journal/JournalAPIRepositoryInterface.php | 10 +- .../Journal/JournalCLIRepository.php | 37 +- .../Journal/JournalCLIRepositoryInterface.php | 20 +- .../Journal/JournalRepository.php | 60 +- .../Journal/JournalRepositoryInterface.php | 41 +- .../LinkType/LinkTypeRepository.php | 129 +-- .../LinkType/LinkTypeRepositoryInterface.php | 51 +- .../ObjectGroup/CreatesObjectGroups.php | 10 +- .../ObjectGroup/ObjectGroupRepository.php | 12 +- .../ObjectGroupRepositoryInterface.php | 20 +- .../PiggyBank/ModifiesPiggyBanks.php | 80 +- .../PiggyBank/PiggyBankRepository.php | 75 +- .../PiggyBankRepositoryInterface.php | 72 +- .../Recurring/RecurringRepository.php | 108 +-- .../RecurringRepositoryInterface.php | 14 +- app/Repositories/Rule/RuleRepository.php | 105 +-- .../Rule/RuleRepositoryInterface.php | 51 +- .../RuleGroup/RuleGroupRepository.php | 65 +- .../RuleGroupRepositoryInterface.php | 39 +- app/Repositories/Tag/OperationsRepository.php | 116 +-- .../Tag/OperationsRepositoryInterface.php | 34 +- app/Repositories/Tag/TagRepository.php | 113 +-- .../Tag/TagRepositoryInterface.php | 55 +- .../TransactionGroupRepository.php | 157 ++-- .../TransactionGroupRepositoryInterface.php | 38 +- .../TransactionTypeRepository.php | 10 +- .../TransactionTypeRepositoryInterface.php | 10 +- app/Repositories/User/UserRepository.php | 107 +-- .../User/UserRepositoryInterface.php | 89 +- .../Webhook/WebhookRepositoryInterface.php | 20 +- app/Rules/BelongsUser.php | 48 +- app/Rules/IsAssetAccountId.php | 7 +- app/Rules/IsBoolean.php | 6 +- app/Rules/IsDateOrTime.php | 8 +- app/Rules/IsTransferAccount.php | 12 +- app/Rules/IsValidAttachmentModel.php | 30 +- app/Rules/IsValidBulkClause.php | 20 +- app/Rules/LessThanPiggyTarget.php | 6 +- app/Rules/UniqueAccountNumber.php | 24 +- app/Rules/UniqueIban.php | 14 +- app/Rules/ValidJournals.php | 6 +- app/Rules/ValidRecurrenceRepetitionType.php | 8 +- app/Rules/ValidRecurrenceRepetitionValue.php | 24 +- .../FireflyIIIOrg/Update/UpdateRequest.php | 34 +- .../Update/UpdateRequestInterface.php | 2 +- .../Destroy/AccountDestroyService.php | 36 +- .../Internal/Destroy/BillDestroyService.php | 2 +- .../Internal/Destroy/BudgetDestroyService.php | 6 +- .../Destroy/CategoryDestroyService.php | 6 +- .../Destroy/CurrencyDestroyService.php | 2 +- .../Destroy/JournalDestroyService.php | 2 +- .../Destroy/RecurrenceDestroyService.php | 4 +- .../TransactionGroupDestroyService.php | 2 +- .../Internal/Support/AccountServiceTrait.php | 3 +- .../Internal/Support/BillServiceTrait.php | 10 +- .../Support/CreditRecalculateService.php | 4 +- .../Internal/Support/JournalServiceTrait.php | 78 +- .../Internal/Support/LocationServiceTrait.php | 4 +- .../Support/RecurringTransactionTrait.php | 63 +- .../Internal/Support/TransactionTypeTrait.php | 2 +- .../Internal/Update/AccountUpdateService.php | 66 +- .../Internal/Update/BillUpdateService.php | 61 +- .../Internal/Update/CategoryUpdateService.php | 32 +- .../Internal/Update/CurrencyUpdateService.php | 10 +- .../Internal/Update/GroupCloneService.php | 28 +- .../Internal/Update/GroupUpdateService.php | 27 +- .../Internal/Update/JournalUpdateService.php | 42 +- .../Update/RecurrenceUpdateService.php | 51 +- app/Services/Password/PwndVerifierV2.php | 6 +- app/Services/Password/Verifier.php | 3 +- .../Webhook/WebhookSenderInterface.php | 2 +- app/Support/Amount.php | 7 +- .../Authentication/RemoteUserGuard.php | 6 +- app/Support/Binder/AccountList.php | 5 +- app/Support/Binder/BinderInterface.php | 5 +- app/Support/Binder/BudgetList.php | 6 +- app/Support/Binder/CLIToken.php | 6 +- app/Support/Binder/CategoryList.php | 5 +- app/Support/Binder/CurrencyCode.php | 5 +- app/Support/Binder/Date.php | 5 +- app/Support/Binder/DynamicConfigKey.php | 4 +- app/Support/Binder/EitherConfigKey.php | 4 +- app/Support/Binder/JournalList.php | 7 +- app/Support/Binder/TagList.php | 7 +- app/Support/Binder/TagOrId.php | 7 +- app/Support/CacheProperties.php | 7 +- .../Chart/Budget/FrontpageChartGenerator.php | 48 +- .../Category/FrontpageChartGenerator.php | 42 +- .../Category/WholePeriodChartGenerator.php | 28 +- app/Support/ChartColour.php | 3 +- app/Support/Cronjobs/AbstractCronjob.php | 4 +- app/Support/Cronjobs/AutoBudgetCronjob.php | 4 +- app/Support/Cronjobs/BillWarningCronjob.php | 12 +- app/Support/Cronjobs/ExchangeRatesCronjob.php | 4 +- app/Support/Cronjobs/RecurringCronjob.php | 12 +- app/Support/Domain.php | 1 + app/Support/ExpandedForm.php | 89 +- app/Support/Export/ExportDataGenerator.php | 335 ++++++-- app/Support/Facades/AccountForm.php | 1 + app/Support/Facades/Amount.php | 1 + app/Support/Facades/CurrencyForm.php | 1 + app/Support/Facades/ExpandedForm.php | 1 + app/Support/Facades/FireflyConfig.php | 1 + app/Support/Facades/Navigation.php | 1 + app/Support/Facades/PiggyBankForm.php | 1 + app/Support/Facades/Preferences.php | 2 +- app/Support/Facades/RuleForm.php | 1 + app/Support/Facades/Steam.php | 1 + app/Support/FireflyConfig.php | 47 +- app/Support/Form/AccountForm.php | 40 +- app/Support/Form/CurrencyForm.php | 58 +- app/Support/Form/FormSupport.php | 28 +- app/Support/Form/PiggyBankForm.php | 20 +- app/Support/Form/RuleForm.php | 16 +- app/Support/Http/Api/AccountFilter.php | 20 +- app/Support/Http/Api/ApiSupport.php | 4 +- .../Http/Api/ConvertsExchangeRates.php | 114 +-- app/Support/Http/Api/TransactionFilter.php | 11 +- app/Support/Http/Controllers/AugumentData.php | 41 +- .../Http/Controllers/BasicDataSupport.php | 8 +- .../Http/Controllers/ChartGeneration.php | 10 +- app/Support/Http/Controllers/CreateStuff.php | 20 +- app/Support/Http/Controllers/CronRunner.php | 8 +- .../Http/Controllers/DateCalculation.php | 20 +- .../Http/Controllers/GetConfigurationData.php | 48 +- .../Http/Controllers/ModelInformation.php | 24 +- .../Http/Controllers/PeriodOverview.php | 81 +- .../Http/Controllers/RenderPartialViews.php | 28 +- .../Http/Controllers/RequestInformation.php | 6 +- .../Http/Controllers/RuleManagement.php | 20 +- .../Controllers/TransactionCalculation.php | 56 +- .../Http/Controllers/UserNavigation.php | 14 +- app/Support/Logging/AuditLogger.php | 2 +- app/Support/Logging/AuditProcessor.php | 2 +- app/Support/Navigation.php | 109 +-- app/Support/NullArrayObject.php | 6 +- app/Support/ParseDateString.php | 43 +- app/Support/Preferences.php | 245 +++--- .../Report/Budget/BudgetReportGenerator.php | 135 +-- .../Category/CategoryReportGenerator.php | 66 +- .../Recurring/CalculateRangeOccurrences.php | 42 +- .../Recurring/CalculateXOccurrences.php | 42 +- .../Recurring/CalculateXOccurrencesSince.php | 52 +- .../Recurring/FiltersWeekends.php | 6 +- app/Support/Request/AppendsLocationData.php | 22 +- app/Support/Request/ConvertsDataTypes.php | 70 +- app/Support/Request/GetRecurrenceData.php | 16 +- app/Support/Search/AccountSearch.php | 11 +- app/Support/Search/OperatorQuerySearch.php | 122 +-- app/Support/Search/SearchInterface.php | 11 +- app/Support/Steam.php | 84 +- .../System/GeneratesInstallationId.php | 2 +- app/Support/System/OAuthKeys.php | 8 +- app/Support/Twig/AmountFormat.php | 1 + app/Support/Twig/General.php | 15 +- app/Support/Twig/Rule.php | 9 +- app/Support/Twig/TransactionGroupTwig.php | 24 +- app/Support/Twig/Translation.php | 3 +- .../Actions/ActionInterface.php | 3 +- app/TransactionRules/Actions/AddTag.php | 3 +- .../Actions/AppendDescription.php | 3 +- .../Actions/AppendDescriptionToNotes.php | 4 +- app/TransactionRules/Actions/AppendNotes.php | 11 +- .../Actions/AppendNotesToDescription.php | 6 +- app/TransactionRules/Actions/ClearBudget.php | 5 +- .../Actions/ClearCategory.php | 5 +- app/TransactionRules/Actions/ClearNotes.php | 5 +- .../Actions/ConvertToDeposit.php | 6 +- .../Actions/ConvertToTransfer.php | 10 +- .../Actions/ConvertToWithdrawal.php | 4 +- .../Actions/DeleteTransaction.php | 3 +- app/TransactionRules/Actions/LinkToBill.php | 13 +- .../Actions/MoveDescriptionToNotes.php | 6 +- .../Actions/MoveNotesToDescription.php | 8 +- .../Actions/PrependDescription.php | 3 +- app/TransactionRules/Actions/PrependNotes.php | 11 +- .../Actions/RemoveAllTags.php | 3 +- app/TransactionRules/Actions/RemoveTag.php | 7 +- app/TransactionRules/Actions/SetBudget.php | 3 +- app/TransactionRules/Actions/SetCategory.php | 3 +- .../Actions/SetDescription.php | 5 +- .../Actions/SetDestinationAccount.php | 9 +- app/TransactionRules/Actions/SetNotes.php | 3 +- .../Actions/SetSourceAccount.php | 9 +- .../Actions/UpdatePiggybank.php | 30 +- .../Engine/RuleEngineInterface.php | 8 +- .../Engine/SearchRuleEngine.php | 52 +- .../Factory/ActionFactory.php | 9 +- app/Transformers/AbstractTransformer.php | 2 +- app/Transformers/AccountTransformer.php | 38 +- app/Transformers/AttachmentTransformer.php | 10 +- .../AvailableBudgetTransformer.php | 10 +- app/Transformers/BillTransformer.php | 36 +- 415 files changed, 7462 insertions(+), 6874 deletions(-) diff --git a/app/Http/Controllers/ObjectGroup/DeleteController.php b/app/Http/Controllers/ObjectGroup/DeleteController.php index 367ea85a53..b53c5fa710 100644 --- a/app/Http/Controllers/ObjectGroup/DeleteController.php +++ b/app/Http/Controllers/ObjectGroup/DeleteController.php @@ -50,7 +50,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-envelope-o'); - app('view')->share('title', (string) trans('firefly.object_groups_page_title')); + app('view')->share('title', (string)trans('firefly.object_groups_page_title')); $this->repository = app(ObjectGroupRepositoryInterface::class); @@ -62,13 +62,13 @@ class DeleteController extends Controller /** * Delete a piggy bank. * - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return Factory|View */ public function delete(ObjectGroup $objectGroup) { - $subTitle = (string) trans('firefly.delete_object_group', ['title' => $objectGroup->title]); + $subTitle = (string)trans('firefly.delete_object_group', ['title' => $objectGroup->title]); $piggyBanks = $objectGroup->piggyBanks()->count(); // put previous url in session @@ -80,13 +80,13 @@ class DeleteController extends Controller /** * Destroy the piggy bank. * - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return RedirectResponse */ public function destroy(ObjectGroup $objectGroup): RedirectResponse { - session()->flash('success', (string) trans('firefly.deleted_object_group', ['title' => $objectGroup->title])); + session()->flash('success', (string)trans('firefly.deleted_object_group', ['title' => $objectGroup->title])); app('preferences')->mark(); $this->repository->destroy($objectGroup); diff --git a/app/Http/Controllers/ObjectGroup/EditController.php b/app/Http/Controllers/ObjectGroup/EditController.php index 55c0f21366..cdb35c0b81 100644 --- a/app/Http/Controllers/ObjectGroup/EditController.php +++ b/app/Http/Controllers/ObjectGroup/EditController.php @@ -53,7 +53,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-envelope-o'); - app('view')->share('title', (string) trans('firefly.object_groups_page_title')); + app('view')->share('title', (string)trans('firefly.object_groups_page_title')); $this->repository = app(ObjectGroupRepositoryInterface::class); @@ -65,13 +65,13 @@ class EditController extends Controller /** * Edit an object group. * - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return Factory|View */ public function edit(ObjectGroup $objectGroup) { - $subTitle = (string) trans('firefly.edit_object_group', ['title' => $objectGroup->title]); + $subTitle = (string)trans('firefly.edit_object_group', ['title' => $objectGroup->title]); $subTitleIcon = 'fa-pencil'; if (true !== session('object-groups.edit.fromUpdate')) { @@ -85,8 +85,8 @@ class EditController extends Controller /** * Update a piggy bank. * - * @param ObjectGroupFormRequest $request - * @param ObjectGroup $objectGroup + * @param ObjectGroupFormRequest $request + * @param ObjectGroup $objectGroup * * @return Application|RedirectResponse|Redirector */ @@ -95,12 +95,12 @@ class EditController extends Controller $data = $request->getObjectGroupData(); $piggyBank = $this->repository->update($objectGroup, $data); - session()->flash('success', (string) trans('firefly.updated_object_group', ['title' => $objectGroup->title])); + session()->flash('success', (string)trans('firefly.updated_object_group', ['title' => $objectGroup->title])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUrl('object-groups.edit.url')); - if (1 === (int) $request->get('return_to_edit')) { + if (1 === (int)$request->get('return_to_edit')) { session()->put('object-groups.edit.fromUpdate', true); $redirect = redirect(route('object-groups.edit', [$piggyBank->id])); diff --git a/app/Http/Controllers/ObjectGroup/IndexController.php b/app/Http/Controllers/ObjectGroup/IndexController.php index def792d0df..5a5c0fc59e 100644 --- a/app/Http/Controllers/ObjectGroup/IndexController.php +++ b/app/Http/Controllers/ObjectGroup/IndexController.php @@ -53,7 +53,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-envelope-o'); - app('view')->share('title', (string) trans('firefly.object_groups_page_title')); + app('view')->share('title', (string)trans('firefly.object_groups_page_title')); $this->repository = app(ObjectGroupRepositoryInterface::class); return $next($request); @@ -68,22 +68,22 @@ class IndexController extends Controller { $this->repository->deleteEmpty(); $this->repository->resetOrder(); - $subTitle = (string) trans('firefly.object_groups_index'); + $subTitle = (string)trans('firefly.object_groups_index'); $objectGroups = $this->repository->get(); return view('object-groups.index', compact('subTitle', 'objectGroups')); } /** - * @param Request $request - * @param ObjectGroup $objectGroup + * @param Request $request + * @param ObjectGroup $objectGroup * * @return JsonResponse */ public function setOrder(Request $request, ObjectGroup $objectGroup) { Log::debug(sprintf('Found object group #%d "%s"', $objectGroup->id, $objectGroup->title)); - $newOrder = (int) $request->get('order'); + $newOrder = (int)$request->get('order'); $this->repository->setOrder($objectGroup, $newOrder); return response()->json([]); diff --git a/app/Http/Controllers/PiggyBank/AmountController.php b/app/Http/Controllers/PiggyBank/AmountController.php index a5d00f662e..b7e4d3af04 100644 --- a/app/Http/Controllers/PiggyBank/AmountController.php +++ b/app/Http/Controllers/PiggyBank/AmountController.php @@ -54,7 +54,7 @@ class AmountController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); @@ -68,7 +68,7 @@ class AmountController extends Controller /** * Add money to piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ @@ -89,7 +89,7 @@ class AmountController extends Controller /** * Add money to piggy bank (for mobile devices). * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ @@ -113,8 +113,8 @@ class AmountController extends Controller /** * Add money to piggy bank. * - * @param Request $request - * @param PiggyBank $piggyBank + * @param Request $request + * @param PiggyBank $piggyBank * * @return RedirectResponse */ @@ -130,7 +130,7 @@ class AmountController extends Controller $this->piggyRepos->addAmount($piggyBank, $amount); session()->flash( 'success', - (string) trans( + (string)trans( 'firefly.added_amount_to_piggy', ['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name] ) @@ -140,10 +140,10 @@ class AmountController extends Controller return redirect(route('piggy-banks.index')); } - Log::error('Cannot add ' . $amount . ' because canAddAmount returned false.'); + Log::error('Cannot add '.$amount.' because canAddAmount returned false.'); session()->flash( 'error', - (string) trans( + (string)trans( 'firefly.cannot_add_amount_piggy', ['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)] ) @@ -155,8 +155,8 @@ class AmountController extends Controller /** * Remove money from piggy bank. * - * @param Request $request - * @param PiggyBank $piggyBank + * @param Request $request + * @param PiggyBank $piggyBank * * @return RedirectResponse */ @@ -172,7 +172,7 @@ class AmountController extends Controller $this->piggyRepos->removeAmount($piggyBank, $amount); session()->flash( 'success', - (string) trans( + (string)trans( 'firefly.removed_amount_from_piggy', ['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => $piggyBank->name] ) @@ -181,11 +181,11 @@ class AmountController extends Controller return redirect(route('piggy-banks.index')); } - $amount = (string) $request->get('amount'); + $amount = (string)$request->get('amount'); session()->flash( 'error', - (string) trans( + (string)trans( 'firefly.cannot_remove_from_piggy', ['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)] ) @@ -197,7 +197,7 @@ class AmountController extends Controller /** * Remove money from piggy bank form. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ @@ -212,7 +212,7 @@ class AmountController extends Controller /** * Remove money from piggy bank (for mobile devices). * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ diff --git a/app/Http/Controllers/PiggyBank/CreateController.php b/app/Http/Controllers/PiggyBank/CreateController.php index c0da9bd1b7..9347bda81b 100644 --- a/app/Http/Controllers/PiggyBank/CreateController.php +++ b/app/Http/Controllers/PiggyBank/CreateController.php @@ -53,7 +53,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->attachments = app(AttachmentHelperInterface::class); @@ -71,7 +71,7 @@ class CreateController extends Controller */ public function create() { - $subTitle = (string) trans('firefly.new_piggy_bank'); + $subTitle = (string)trans('firefly.new_piggy_bank'); $subTitleIcon = 'fa-plus'; // put previous url in session if not redirect from store (not "create another"). @@ -86,7 +86,7 @@ class CreateController extends Controller /** * Store a new piggy bank. * - * @param PiggyBankStoreRequest $request + * @param PiggyBankStoreRequest $request * * @return RedirectResponse|Redirector * @throws FireflyException @@ -99,7 +99,7 @@ class CreateController extends Controller } $piggyBank = $this->piggyRepos->store($data); - session()->flash('success', (string) trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name])); + session()->flash('success', (string)trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name])); app('preferences')->mark(); // store attachment(s): @@ -109,7 +109,7 @@ class CreateController extends Controller $this->attachments->saveAttachmentsForModel($piggyBank, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { @@ -117,7 +117,7 @@ class CreateController extends Controller } $redirect = redirect($this->getPreviousUrl('piggy-banks.create.url')); - if (1 === (int) $request->get('create_another')) { + if (1 === (int)$request->get('create_another')) { session()->put('piggy-banks.create.fromStore', true); $redirect = redirect(route('piggy-banks.create'))->withInput(); diff --git a/app/Http/Controllers/PiggyBank/DeleteController.php b/app/Http/Controllers/PiggyBank/DeleteController.php index 4fdcf47e83..1c019b2839 100644 --- a/app/Http/Controllers/PiggyBank/DeleteController.php +++ b/app/Http/Controllers/PiggyBank/DeleteController.php @@ -49,7 +49,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); @@ -62,13 +62,13 @@ class DeleteController extends Controller /** * Delete a piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ public function delete(PiggyBank $piggyBank) { - $subTitle = (string) trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]); + $subTitle = (string)trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]); // put previous url in session $this->rememberPreviousUrl('piggy-banks.delete.url'); @@ -79,13 +79,13 @@ class DeleteController extends Controller /** * Destroy the piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return RedirectResponse */ public function destroy(PiggyBank $piggyBank): RedirectResponse { - session()->flash('success', (string) trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name])); + session()->flash('success', (string)trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name])); app('preferences')->mark(); $this->piggyRepos->destroy($piggyBank); diff --git a/app/Http/Controllers/PiggyBank/IndexController.php b/app/Http/Controllers/PiggyBank/IndexController.php index c931c108b4..4a7d4f49af 100644 --- a/app/Http/Controllers/PiggyBank/IndexController.php +++ b/app/Http/Controllers/PiggyBank/IndexController.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\PiggyBank; use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\PiggyBank; use FireflyIII\Repositories\ObjectGroup\OrganisesObjectGroups; @@ -35,6 +36,7 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\View\View; +use JsonException; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -57,7 +59,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); @@ -72,11 +74,11 @@ class IndexController extends Controller * * TODO very complicated function. * - * @param Request $request + * @param Request $request * * @return Factory|View - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ public function index(Request $request) { @@ -104,16 +106,16 @@ class IndexController extends Controller /** @var PiggyBank $piggy */ foreach ($collection as $piggy) { $array = $transformer->transform($piggy); - $groupOrder = (int) $array['object_group_order']; + $groupOrder = (int)$array['object_group_order']; // make group array if necessary: $piggyBanks[$groupOrder] = $piggyBanks[$groupOrder] ?? [ - 'object_group_id' => $array['object_group_id'] ?? 0, - 'object_group_title' => $array['object_group_title'] ?? trans('firefly.default_group_title_name'), - 'piggy_banks' => [], - ]; + 'object_group_id' => $array['object_group_id'] ?? 0, + 'object_group_title' => $array['object_group_title'] ?? trans('firefly.default_group_title_name'), + 'piggy_banks' => [], + ]; $account = $accountTransformer->transform($piggy->account); - $accountId = (int) $account['id']; + $accountId = (int)$account['id']; $array['attachments'] = $this->piggyRepos->getAttachments($piggy); if (!array_key_exists($accountId, $accounts)) { // create new: @@ -143,7 +145,7 @@ class IndexController extends Controller } /** - * @param array $piggyBanks + * @param array $piggyBanks * * @return array */ @@ -155,23 +157,23 @@ class IndexController extends Controller foreach ($group['piggy_banks'] as $piggy) { $currencyId = $piggy['currency_id']; $sums[$groupId][$currencyId] = $sums[$groupId][$currencyId] ?? [ - 'target' => '0', - 'saved' => '0', - 'left_to_save' => '0', - 'save_per_month' => '0', - 'currency_id' => $currencyId, - 'currency_code' => $piggy['currency_code'], - 'currency_symbol' => $piggy['currency_symbol'], - 'currency_decimal_places' => $piggy['currency_decimal_places'], - ]; + 'target' => '0', + 'saved' => '0', + 'left_to_save' => '0', + 'save_per_month' => '0', + 'currency_id' => $currencyId, + 'currency_code' => $piggy['currency_code'], + 'currency_symbol' => $piggy['currency_symbol'], + 'currency_decimal_places' => $piggy['currency_decimal_places'], + ]; // target_amount // current_amount // left_to_save // save_per_month - $sums[$groupId][$currencyId]['target'] = bcadd($sums[$groupId][$currencyId]['target'], (string) $piggy['target_amount']); - $sums[$groupId][$currencyId]['saved'] = bcadd($sums[$groupId][$currencyId]['saved'], (string) $piggy['current_amount']); - $sums[$groupId][$currencyId]['left_to_save'] = bcadd($sums[$groupId][$currencyId]['left_to_save'], (string) $piggy['left_to_save']); - $sums[$groupId][$currencyId]['save_per_month'] = bcadd($sums[$groupId][$currencyId]['save_per_month'], (string) $piggy['save_per_month']); + $sums[$groupId][$currencyId]['target'] = bcadd($sums[$groupId][$currencyId]['target'], (string)$piggy['target_amount']); + $sums[$groupId][$currencyId]['saved'] = bcadd($sums[$groupId][$currencyId]['saved'], (string)$piggy['current_amount']); + $sums[$groupId][$currencyId]['left_to_save'] = bcadd($sums[$groupId][$currencyId]['left_to_save'], (string)$piggy['left_to_save']); + $sums[$groupId][$currencyId]['save_per_month'] = bcadd($sums[$groupId][$currencyId]['save_per_month'], (string)$piggy['save_per_month']); } } foreach ($piggyBanks as $groupOrder => $group) { @@ -185,15 +187,15 @@ class IndexController extends Controller /** * Set the order of a piggy bank. * - * @param Request $request - * @param PiggyBank $piggyBank + * @param Request $request + * @param PiggyBank $piggyBank * * @return JsonResponse */ public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse { - $objectGroupTitle = (string) $request->get('objectGroupTitle'); - $newOrder = (int) $request->get('order'); + $objectGroupTitle = (string)$request->get('objectGroupTitle'); + $newOrder = (int)$request->get('order'); $this->piggyRepos->setOrder($piggyBank, $newOrder); if ('' !== $objectGroupTitle) { $this->piggyRepos->setObjectGroup($piggyBank, $objectGroupTitle); diff --git a/app/Http/Controllers/PiggyBank/ShowController.php b/app/Http/Controllers/PiggyBank/ShowController.php index a73b59f409..93905891c9 100644 --- a/app/Http/Controllers/PiggyBank/ShowController.php +++ b/app/Http/Controllers/PiggyBank/ShowController.php @@ -51,7 +51,7 @@ class ShowController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.piggyBanks')); + app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-bullseye'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); @@ -64,7 +64,7 @@ class ShowController extends Controller /** * Show a single piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Factory|View */ diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index b5a442c988..93fdcc9a67 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -1,4 +1,5 @@ middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-paint-brush'); - app('view')->share('title', (string) trans('firefly.recurrences')); - app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence')); + app('view')->share('title', (string)trans('firefly.recurrences')); + app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence')); $this->recurring = app(RecurringRepositoryInterface::class); $this->budgetRepos = app(BudgetRepositoryInterface::class); @@ -79,7 +79,7 @@ class CreateController extends Controller /** * Create a new recurring transaction. * - * @param Request $request + * @param Request $request * * @return Factory|View */ @@ -98,22 +98,22 @@ class CreateController extends Controller } $request->session()->forget('recurring.create.fromStore'); $repetitionEnds = [ - 'forever' => (string) trans('firefly.repeat_forever'), - 'until_date' => (string) trans('firefly.repeat_until_date'), - 'times' => (string) trans('firefly.repeat_times'), + 'forever' => (string)trans('firefly.repeat_forever'), + 'until_date' => (string)trans('firefly.repeat_until_date'), + 'times' => (string)trans('firefly.repeat_times'), ]; $weekendResponses = [ - RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'), - RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'), - RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'), - RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'), + RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), + RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), + RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), + RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), ]; $hasOldInput = null !== $request->old('_token'); // flash some data $preFilled = [ 'first_date' => $tomorrow->format('Y-m-d'), 'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal', - 'active' => $hasOldInput ? (bool) $request->old('active') : true, - 'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : true, + 'active' => $hasOldInput ? (bool)$request->old('active') : true, + 'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : true, ]; $request->session()->flash('preFilled', $preFilled); @@ -124,8 +124,8 @@ class CreateController extends Controller } /** - * @param Request $request - * @param TransactionJournal $journal + * @param Request $request + * @param TransactionJournal $journal * * @return Factory|\Illuminate\Contracts\View\View */ @@ -144,15 +144,15 @@ class CreateController extends Controller } $request->session()->forget('recurring.create.fromStore'); $repetitionEnds = [ - 'forever' => (string) trans('firefly.repeat_forever'), - 'until_date' => (string) trans('firefly.repeat_until_date'), - 'times' => (string) trans('firefly.repeat_times'), + 'forever' => (string)trans('firefly.repeat_forever'), + 'until_date' => (string)trans('firefly.repeat_until_date'), + 'times' => (string)trans('firefly.repeat_times'), ]; $weekendResponses = [ - RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'), - RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'), - RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'), - RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'), + RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), + RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), + RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), + RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), ]; @@ -185,8 +185,8 @@ class CreateController extends Controller 'category' => $request->old('category'), 'budget_id' => $request->old('budget_id'), 'bill_id' => $request->old('bill_id'), - 'active' => (bool) $request->old('active'), - 'apply_rules' => (bool) $request->old('apply_rules'), + 'active' => (bool)$request->old('active'), + 'apply_rules' => (bool)$request->old('apply_rules'), ]; } if (false === $hasOldInput) { @@ -221,7 +221,7 @@ class CreateController extends Controller /** * Store a recurring transaction. * - * @param RecurrenceFormRequest $request + * @param RecurrenceFormRequest $request * * @return RedirectResponse|Redirector * @throws FireflyException @@ -237,7 +237,7 @@ class CreateController extends Controller return redirect(route('recurring.create'))->withInput(); } - $request->session()->flash('success', (string) trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); + $request->session()->flash('success', (string)trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); app('preferences')->mark(); // store attachment(s): @@ -247,7 +247,7 @@ class CreateController extends Controller $this->attachments->saveAttachmentsForModel($recurrence, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { @@ -255,7 +255,7 @@ class CreateController extends Controller } $redirect = redirect($this->getPreviousUrl('recurring.create.url')); - if (1 === (int) $request->get('create_another')) { + if (1 === (int)$request->get('create_another')) { // set value so create routine will not overwrite URL: $request->session()->put('recurring.create.fromStore', true); diff --git a/app/Http/Controllers/Recurring/DeleteController.php b/app/Http/Controllers/Recurring/DeleteController.php index 8de42d9b6f..c45bdb1bdb 100644 --- a/app/Http/Controllers/Recurring/DeleteController.php +++ b/app/Http/Controllers/Recurring/DeleteController.php @@ -53,7 +53,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-paint-brush'); - app('view')->share('title', (string) trans('firefly.recurrences')); + app('view')->share('title', (string)trans('firefly.recurrences')); $this->recurring = app(RecurringRepositoryInterface::class); @@ -65,13 +65,13 @@ class DeleteController extends Controller /** * Delete a recurring transaction form. * - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @return Factory|View */ public function delete(Recurrence $recurrence) { - $subTitle = (string) trans('firefly.delete_recurring', ['title' => $recurrence->title]); + $subTitle = (string)trans('firefly.delete_recurring', ['title' => $recurrence->title]); // put previous url in session $this->rememberPreviousUrl('recurrences.delete.url'); @@ -83,16 +83,16 @@ class DeleteController extends Controller /** * Destroy the recurring transaction. * - * @param RecurringRepositoryInterface $repository - * @param Request $request - * @param Recurrence $recurrence + * @param RecurringRepositoryInterface $repository + * @param Request $request + * @param Recurrence $recurrence * * @return RedirectResponse|Redirector */ public function destroy(RecurringRepositoryInterface $repository, Request $request, Recurrence $recurrence) { $repository->destroy($recurrence); - $request->session()->flash('success', (string) trans('firefly.' . 'recurrence_deleted', ['title' => $recurrence->title])); + $request->session()->flash('success', (string)trans('firefly.'.'recurrence_deleted', ['title' => $recurrence->title])); app('preferences')->mark(); return redirect($this->getPreviousUrl('recurrences.delete.url')); diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index e9bd8982f5..a0a908ac62 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -64,8 +64,8 @@ class EditController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-paint-brush'); - app('view')->share('title', (string) trans('firefly.recurrences')); - app('view')->share('subTitle', (string) trans('firefly.recurrences')); + app('view')->share('title', (string)trans('firefly.recurrences')); + app('view')->share('subTitle', (string)trans('firefly.recurrences')); $this->recurring = app(RecurringRepositoryInterface::class); $this->budgetRepos = app(BudgetRepositoryInterface::class); @@ -80,8 +80,8 @@ class EditController extends Controller /** * Edit a recurring transaction. * - * @param Request $request - * @param Recurrence $recurrence + * @param Request $request + * @param Recurrence $recurrence * * @return Factory|View * @throws FireflyException @@ -107,7 +107,7 @@ class EditController extends Controller $repetition = $recurrence->recurrenceRepetitions()->first(); $currentRepType = $repetition->repetition_type; if ('' !== $repetition->repetition_moment) { - $currentRepType .= ',' . $repetition->repetition_moment; + $currentRepType .= ','.$repetition->repetition_moment; } // put previous url in session if not redirect from store (not "return_to_edit"). @@ -118,9 +118,9 @@ class EditController extends Controller $repetitionEnd = 'forever'; $repetitionEnds = [ - 'forever' => (string) trans('firefly.repeat_forever'), - 'until_date' => (string) trans('firefly.repeat_until_date'), - 'times' => (string) trans('firefly.repeat_times'), + 'forever' => (string)trans('firefly.repeat_forever'), + 'until_date' => (string)trans('firefly.repeat_until_date'), + 'times' => (string)trans('firefly.repeat_times'), ]; if (null !== $recurrence->repeat_until) { $repetitionEnd = 'until_date'; @@ -130,22 +130,22 @@ class EditController extends Controller } $weekendResponses = [ - RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'), - RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'), - RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'), - RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'), + RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), + RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), + RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), + RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), ]; $hasOldInput = null !== $request->old('_token'); $preFilled = [ 'transaction_type' => strtolower($recurrence->transactionType->type), - 'active' => $hasOldInput ? (bool) $request->old('active') : $recurrence->active, - 'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : $recurrence->apply_rules, + 'active' => $hasOldInput ? (bool)$request->old('active') : $recurrence->active, + 'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules, 'deposit_source_id' => $array['transactions'][0]['source_id'], 'withdrawal_destination_id' => $array['transactions'][0]['destination_id'], ]; - $array['first_date'] = substr((string) $array['first_date'], 0, 10); - $array['repeat_until'] = substr((string) $array['repeat_until'], 0, 10); + $array['first_date'] = substr((string)$array['first_date'], 0, 10); + $array['repeat_until'] = substr((string)$array['repeat_until'], 0, 10); $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags'] ?? []); return view( @@ -167,8 +167,8 @@ class EditController extends Controller /** * Update the recurring transaction. * - * @param RecurrenceFormRequest $request - * @param Recurrence $recurrence + * @param RecurrenceFormRequest $request + * @param Recurrence $recurrence * * @return RedirectResponse|Redirector * @throws FireflyException @@ -178,7 +178,7 @@ class EditController extends Controller $data = $request->getAll(); $this->recurring->update($recurrence, $data); - $request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title])); + $request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title])); // store new attachment(s): $files = $request->hasFile('attachments') ? $request->file('attachments') : null; @@ -186,7 +186,7 @@ class EditController extends Controller $this->attachments->saveAttachmentsForModel($recurrence, $files); } if (null !== $files && auth()->user()->hasRole('demo')) { - session()->flash('info', (string) trans('firefly.no_att_demo_user')); + session()->flash('info', (string)trans('firefly.no_att_demo_user')); } if (count($this->attachments->getMessages()->get('attachments')) > 0) { @@ -194,7 +194,7 @@ class EditController extends Controller } app('preferences')->mark(); $redirect = redirect($this->getPreviousUrl('recurrences.edit.url')); - if (1 === (int) $request->get('return_to_edit')) { + if (1 === (int)$request->get('return_to_edit')) { // set value so edit routine will not overwrite URL: $request->session()->put('recurrences.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php index 9f6260ac2c..3e0d426941 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -1,4 +1,5 @@ middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-paint-brush'); - app('view')->share('title', (string) trans('firefly.recurrences')); + app('view')->share('title', (string)trans('firefly.recurrences')); $this->recurringRepos = app(RecurringRepositoryInterface::class); @@ -71,17 +74,17 @@ class IndexController extends Controller * TODO the notes of a recurrence are pretty pointless at this moment. * Show all recurring transactions. * - * @param Request $request + * @param Request $request * * @return Factory|View * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function index(Request $request) { - $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); - $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; + $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); + $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $collection = $this->recurringRepos->get(); $today = today(config('app.timezone')); $year = today(config('app.timezone')); diff --git a/app/Http/Controllers/Recurring/TriggerController.php b/app/Http/Controllers/Recurring/TriggerController.php index 6e2909a7e4..3ed8570ea4 100644 --- a/app/Http/Controllers/Recurring/TriggerController.php +++ b/app/Http/Controllers/Recurring/TriggerController.php @@ -1,4 +1,5 @@ $sourceAccount, - 'currency_id' => $journal['currency_id'], - 'currency_code' => $journal['currency_code'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - 'spent' => '0', - ]; + 'source_account_id' => $sourceAccount, + 'currency_id' => $journal['currency_id'], + 'currency_code' => $journal['currency_code'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + 'spent' => '0', + ]; $spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']); // also fix sum: $report['sums'][$budgetId][$currencyId] = $report['sums'][$budgetId][$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $journal['currency_id'], - 'currency_code' => $journal['currency_code'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $journal['currency_id'], + 'currency_code' => $journal['currency_code'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']); $report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']); diff --git a/app/Http/Controllers/Report/BillController.php b/app/Http/Controllers/Report/BillController.php index 934aa4b7ab..0cc81018c6 100644 --- a/app/Http/Controllers/Report/BillController.php +++ b/app/Http/Controllers/Report/BillController.php @@ -29,7 +29,6 @@ use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; -use JsonException; use Log; use Throwable; @@ -39,9 +38,9 @@ use Throwable; class BillController extends Controller { /** - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return mixed|string */ diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index 22b4a49170..c56139c216 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -1,4 +1,5 @@ id; $report[$accountId] = $report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'sum' => '0', + ]; foreach ($currency['budgets'] as $budget) { foreach ($budget['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $report[$sourceAccountId]['currencies'][$currencyId] = $report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'sum' => '0', + ]; $report[$sourceAccountId]['currencies'][$currencyId]['sum'] = bcadd( $report[$sourceAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] @@ -157,10 +158,10 @@ class BudgetController extends Controller } /** - * @param Collection $accounts - * @param Collection $budgets - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $budgets + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -174,21 +175,21 @@ class BudgetController extends Controller $destinationId = $journal['destination_account_id']; $key = sprintf('%d-%d', $destinationId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'destination_account_name' => $journal['destination_account_name'], - 'destination_account_id' => $journal['destination_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'destination_account_name' => $journal['destination_account_name'], + 'destination_account_id' => $journal['destination_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; // intentional float } } } @@ -209,10 +210,10 @@ class BudgetController extends Controller } /** - * @param Collection $accounts - * @param Collection $budgets - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $budgets + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -225,20 +226,20 @@ class BudgetController extends Controller foreach ($budgets as $budget) { $budgetId = $budget->id; $report[$budgetId] = $report[$budgetId] ?? [ - 'name' => $budget->name, - 'id' => $budget->id, - 'currencies' => [], - ]; + 'name' => $budget->name, + 'id' => $budget->id, + 'currencies' => [], + ]; } foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'sum' => '0', + ]; /** @var array $budget */ foreach ($currency['budgets'] as $budget) { $budgetId = $budget['id']; @@ -246,14 +247,14 @@ class BudgetController extends Controller foreach ($budget['transaction_journals'] as $journal) { // add currency info to report array: $report[$budgetId]['currencies'][$currencyId] = $report[$budgetId]['currencies'][$currencyId] ?? [ - 'sum' => '0', - 'sum_pct' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], + 'sum' => '0', + 'sum_pct' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + ]; $report[$budgetId]['currencies'][$currencyId]['sum'] = bcadd($report[$budgetId]['currencies'][$currencyId]['sum'], $journal['amount']); $sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']); } @@ -267,7 +268,7 @@ class BudgetController extends Controller $total = $sums[$currencyId]['sum'] ?? '0'; $pct = '0'; if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) { - $pct = round((float) bcmul(bcdiv($sum, $total), '100')); // intentional float + $pct = round((float)bcmul(bcdiv($sum, $total), '100')); // intentional float } $report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct; } @@ -279,9 +280,9 @@ class BudgetController extends Controller /** * Show partial overview of budgets. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -304,9 +305,9 @@ class BudgetController extends Controller /** * Show budget overview for a period. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return mixed|string * @throws JsonException @@ -336,20 +337,20 @@ class BudgetController extends Controller $key = sprintf('%d-%d', $budget['id'], $currency['currency_id']); $dateKey = $journal['date']->format($keyFormat); $report[$key] = $report[$key] ?? [ - 'id' => $budget['id'], - 'name' => sprintf('%s (%s)', $budget['name'], $currency['currency_name']), - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'entries' => [], - ]; + 'id' => $budget['id'], + 'name' => sprintf('%s (%s)', $budget['name'], $currency['currency_name']), + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'entries' => [], + ]; $report[$key]['entries'][$dateKey] = $report[$key] ['entries'][$dateKey] ?? '0'; $report[$key]['entries'][$dateKey] = bcadd($journal['amount'], $report[$key] ['entries'][$dateKey]); $report[$key]['sum'] = bcadd($report[$key] ['sum'], $journal['amount']); - $report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) count($periods)); + $report[$key]['avg'] = bcdiv($report[$key]['sum'], (string)count($periods)); } } } @@ -367,10 +368,10 @@ class BudgetController extends Controller } /** - * @param Collection $accounts - * @param Collection $budgets - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $budgets + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -384,7 +385,7 @@ class BudgetController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], // intentional float + 'amount_float' => (float)$journal['amount'], // intentional float 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index d67ef1e879..7a8c66f23f 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -1,4 +1,5 @@ id; $report[$accountId] = $report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. @@ -100,12 +101,12 @@ class CategoryController extends Controller foreach ($category['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $report[$sourceAccountId]['currencies'][$currencyId] = $report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'categories' => [], - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'categories' => [], + ]; $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']] = $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']] @@ -167,10 +168,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -184,37 +185,37 @@ class CategoryController extends Controller foreach ($accounts as $account) { $accountId = $account->id; $report[$accountId] = $report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent_sum' => '0', - 'earned_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent_sum' => '0', + 'earned_sum' => '0', + 'total_sum' => '0', + ]; foreach ($currency['categories'] as $category) { foreach ($category['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $report[$sourceAccountId]['currencies'][$currencyId] = $report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; $report[$sourceAccountId]['currencies'][$currencyId]['spent'] = bcadd( $report[$sourceAccountId]['currencies'][$currencyId]['spent'], $journal['amount'] @@ -233,26 +234,26 @@ class CategoryController extends Controller foreach ($earned as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent_sum' => '0', - 'earned_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent_sum' => '0', + 'earned_sum' => '0', + 'total_sum' => '0', + ]; foreach ($currency['categories'] as $category) { foreach ($category['transaction_journals'] as $journal) { $destinationAccountId = $journal['destination_account_id']; $report[$destinationAccountId]['currencies'][$currencyId] = $report[$destinationAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; $report[$destinationAccountId]['currencies'][$currencyId]['earned'] = bcadd( $report[$destinationAccountId]['currencies'][$currencyId]['earned'], $journal['amount'] @@ -271,10 +272,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -288,21 +289,21 @@ class CategoryController extends Controller $destinationId = $journal['destination_account_id']; $key = sprintf('%d-%d', $destinationId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'destination_account_name' => $journal['destination_account_name'], - 'destination_account_id' => $journal['destination_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'destination_account_name' => $journal['destination_account_name'], + 'destination_account_id' => $journal['destination_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; // intentional float + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; // intentional float } } } @@ -323,10 +324,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -340,21 +341,21 @@ class CategoryController extends Controller $sourceId = $journal['source_account_id']; $key = sprintf('%d-%d', $sourceId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'source_account_name' => $journal['source_account_name'], - 'source_account_id' => $journal['source_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'source_account_name' => $journal['source_account_name'], + 'source_account_id' => $journal['source_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; } } } @@ -375,10 +376,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -392,22 +393,22 @@ class CategoryController extends Controller foreach ($categories as $category) { $categoryId = $category->id; $report[$categoryId] = $report[$categoryId] ?? [ - 'name' => $category->name, - 'id' => $category->id, - 'currencies' => [], - ]; + 'name' => $category->name, + 'id' => $category->id, + 'currencies' => [], + ]; } foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'earned_sum' => '0', - 'spent_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'earned_sum' => '0', + 'spent_sum' => '0', + 'total_sum' => '0', + ]; /** @var array $category */ foreach ($currency['categories'] as $category) { $categoryId = $category['id']; @@ -415,14 +416,14 @@ class CategoryController extends Controller foreach ($category['transaction_journals'] as $journal) { // add currency info to report array: $report[$categoryId]['currencies'][$currencyId] = $report[$categoryId]['currencies'][$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $report[$categoryId]['currencies'][$currencyId]['spent'] = bcadd( $report[$categoryId]['currencies'][$currencyId]['spent'], $journal['amount'] @@ -441,14 +442,14 @@ class CategoryController extends Controller foreach ($earned as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'earned_sum' => '0', - 'spent_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'earned_sum' => '0', + 'spent_sum' => '0', + 'total_sum' => '0', + ]; /** @var array $category */ foreach ($currency['categories'] as $category) { $categoryId = $category['id']; @@ -456,14 +457,14 @@ class CategoryController extends Controller foreach ($category['transaction_journals'] as $journal) { // add currency info to report array: $report[$categoryId]['currencies'][$currencyId] = $report[$categoryId]['currencies'][$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $report[$categoryId]['currencies'][$currencyId]['earned'] = bcadd( $report[$categoryId]['currencies'][$currencyId]['earned'], $journal['amount'] @@ -485,9 +486,9 @@ class CategoryController extends Controller /** * Show overview of expenses in category. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return mixed|string * @throws JsonException @@ -523,17 +524,17 @@ class CategoryController extends Controller foreach ($currencyRow['categories'] as $categoryId => $categoryRow) { $key = sprintf('%d-%d', $currencyId, $categoryId); $data[$key] = $data[$key] ?? [ - 'id' => $categoryRow['id'], - 'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']), - 'currency_id' => $currencyRow['currency_id'], - 'currency_symbol' => $currencyRow['currency_symbol'], - 'currency_name' => $currencyRow['currency_name'], - 'currency_code' => $currencyRow['currency_code'], - 'currency_decimal_places' => $currencyRow['currency_decimal_places'], - 'sum' => '0', - 'entries' => [], + 'id' => $categoryRow['id'], + 'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']), + 'currency_id' => $currencyRow['currency_id'], + 'currency_symbol' => $currencyRow['currency_symbol'], + 'currency_name' => $currencyRow['currency_name'], + 'currency_code' => $currencyRow['currency_code'], + 'currency_decimal_places' => $currencyRow['currency_decimal_places'], + 'sum' => '0', + 'entries' => [], - ]; + ]; foreach ($categoryRow['transaction_journals'] as $journal) { $date = $journal['date']->format($format); $data[$key]['entries'][$date] = $data[$key]['entries'][$date] ?? '0'; @@ -565,10 +566,10 @@ class CategoryController extends Controller /** * Show overview of income in category. * - * @param Collection $accounts + * @param Collection $accounts * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string * @throws JsonException @@ -604,17 +605,17 @@ class CategoryController extends Controller foreach ($currencyRow['categories'] as $categoryId => $categoryRow) { $key = sprintf('%d-%d', $currencyId, $categoryId); $data[$key] = $data[$key] ?? [ - 'id' => $categoryRow['id'], - 'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']), - 'currency_id' => $currencyRow['currency_id'], - 'currency_symbol' => $currencyRow['currency_symbol'], - 'currency_name' => $currencyRow['currency_name'], - 'currency_code' => $currencyRow['currency_code'], - 'currency_decimal_places' => $currencyRow['currency_decimal_places'], - 'sum' => '0', - 'entries' => [], + 'id' => $categoryRow['id'], + 'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']), + 'currency_id' => $currencyRow['currency_id'], + 'currency_symbol' => $currencyRow['currency_symbol'], + 'currency_name' => $currencyRow['currency_name'], + 'currency_code' => $currencyRow['currency_code'], + 'currency_decimal_places' => $currencyRow['currency_decimal_places'], + 'sum' => '0', + 'entries' => [], - ]; + ]; foreach ($categoryRow['transaction_journals'] as $journal) { $date = $journal['date']->format($format); $data[$key]['entries'][$date] = $data[$key]['entries'][$date] ?? '0'; @@ -645,9 +646,9 @@ class CategoryController extends Controller /** * Show overview of category transactions on the default report. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -673,7 +674,7 @@ class CategoryController extends Controller try { - $result = (string) view('reports.partials.categories', compact('report'))->render(); + $result = (string)view('reports.partials.categories', compact('report'))->render(); $cache->store($result); } catch (Throwable $e) { Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage())); @@ -685,10 +686,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -702,7 +703,7 @@ class CategoryController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float)$journal['amount'], 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), @@ -735,10 +736,10 @@ class CategoryController extends Controller } /** - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -752,7 +753,7 @@ class CategoryController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float)$journal['amount'], 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), diff --git a/app/Http/Controllers/Report/DoubleController.php b/app/Http/Controllers/Report/DoubleController.php index 27f72a6b03..50605fb754 100644 --- a/app/Http/Controllers/Report/DoubleController.php +++ b/app/Http/Controllers/Report/DoubleController.php @@ -1,4 +1,5 @@ 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'source_account_name' => $journal['source_account_name'], - 'source_account_id' => $journal['source_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'source_account_name' => $journal['source_account_name'], + 'source_account_id' => $journal['source_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; } } // sort by amount_float @@ -122,10 +123,10 @@ class DoubleController extends Controller } /** - * @param Collection $accounts - * @param Collection $doubles - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $doubles + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -140,21 +141,21 @@ class DoubleController extends Controller $destinationId = $journal['destination_account_id']; $key = sprintf('%d-%d', $destinationId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'destination_account_name' => $journal['destination_account_name'], - 'destination_account_id' => $journal['destination_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'destination_account_name' => $journal['destination_account_name'], + 'destination_account_id' => $journal['destination_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; } } // sort by amount_float @@ -174,10 +175,10 @@ class DoubleController extends Controller } /** - * @param Collection $accounts - * @param Collection $double - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $double + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -197,15 +198,15 @@ class DoubleController extends Controller $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; /** @var array $journal */ foreach ($currency['transaction_journals'] as $journal) { @@ -215,19 +216,19 @@ class DoubleController extends Controller $genericName = $this->getCounterpartName($withCounterpart, $destId, $destName, $destIban); $objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']); $report[$objectName] = $report[$objectName] ?? [ - 'dest_name' => '', - 'dest_iban' => '', - 'source_name' => '', - 'source_iban' => '', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'dest_name' => '', + 'dest_iban' => '', + 'source_name' => '', + 'source_iban' => '', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; // set name $report[$objectName]['dest_name'] = $destName; $report[$objectName]['dest_iban'] = $destIban; @@ -245,15 +246,15 @@ class DoubleController extends Controller $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; /** @var array $journal */ foreach ($currency['transaction_journals'] as $journal) { @@ -263,19 +264,19 @@ class DoubleController extends Controller $genericName = $this->getCounterpartName($withCounterpart, $sourceId, $sourceName, $sourceIban); $objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']); $report[$objectName] = $report[$objectName] ?? [ - 'dest_name' => '', - 'dest_iban' => '', - 'source_name' => '', - 'source_iban' => '', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'dest_name' => '', + 'dest_iban' => '', + 'source_name' => '', + 'source_iban' => '', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; // set name $report[$objectName]['source_name'] = $sourceName; @@ -295,10 +296,10 @@ class DoubleController extends Controller /** * TODO this method is duplicated. * - * @param Collection $accounts - * @param int $id - * @param string $name - * @param string|null $iban + * @param Collection $accounts + * @param int $id + * @param string $name + * @param string|null $iban * * @return string */ @@ -318,10 +319,10 @@ class DoubleController extends Controller } /** - * @param Collection $accounts - * @param Collection $double - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $double + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -341,31 +342,31 @@ class DoubleController extends Controller $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; /** @var array $journal */ foreach ($currency['transaction_journals'] as $journal) { $objectName = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']); $report[$objectName] = $report[$objectName] ?? [ - 'account_id' => $journal['source_account_id'], - 'account_name' => $objectName, - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'account_id' => $journal['source_account_id'], + 'account_name' => $objectName, + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; // set name // add amounts: $report[$objectName]['spent'] = bcadd($report[$objectName]['spent'], $journal['amount']); @@ -380,31 +381,31 @@ class DoubleController extends Controller $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; /** @var array $journal */ foreach ($currency['transaction_journals'] as $journal) { $objectName = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']); $report[$objectName] = $report[$objectName] ?? [ - 'account_id' => $journal['destination_account_id'], - 'account_name' => $objectName, - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'account_id' => $journal['destination_account_id'], + 'account_name' => $objectName, + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; // add amounts: $report[$objectName]['earned'] = bcadd($report[$objectName]['earned'], $journal['amount']); @@ -418,10 +419,10 @@ class DoubleController extends Controller } /** - * @param Collection $accounts - * @param Collection $doubles - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $doubles + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -436,7 +437,7 @@ class DoubleController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float)$journal['amount'], 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), @@ -468,10 +469,10 @@ class DoubleController extends Controller } /** - * @param Collection $accounts - * @param Collection $doubles - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $doubles + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -486,7 +487,7 @@ class DoubleController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float)$journal['amount'], 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), diff --git a/app/Http/Controllers/Report/OperationsController.php b/app/Http/Controllers/Report/OperationsController.php index 722e4820dc..6569fddad0 100644 --- a/app/Http/Controllers/Report/OperationsController.php +++ b/app/Http/Controllers/Report/OperationsController.php @@ -1,4 +1,5 @@ $currencyId, - 'currency_name' => $currencyInfo['currency_name'], - 'currency_code' => $currencyInfo['currency_code'], - 'currency_symbol' => $currencyInfo['currency_symbol'], - 'currency_decimal_places' => $currencyInfo['currency_decimal_places'], - 'in' => $incomes['sums'][$currencyId]['sum'] ?? '0', - 'out' => $expenses['sums'][$currencyId]['sum'] ?? '0', - 'sum' => '0', - ]; + 'currency_id' => $currencyId, + 'currency_name' => $currencyInfo['currency_name'], + 'currency_code' => $currencyInfo['currency_code'], + 'currency_symbol' => $currencyInfo['currency_symbol'], + 'currency_decimal_places' => $currencyInfo['currency_decimal_places'], + 'in' => $incomes['sums'][$currencyId]['sum'] ?? '0', + 'out' => $expenses['sums'][$currencyId]['sum'] ?? '0', + 'sum' => '0', + ]; $sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['in'], $sums[$currencyId]['out']); } diff --git a/app/Http/Controllers/Report/TagController.php b/app/Http/Controllers/Report/TagController.php index 5cb8b7f3fe..557cb75f84 100644 --- a/app/Http/Controllers/Report/TagController.php +++ b/app/Http/Controllers/Report/TagController.php @@ -61,10 +61,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -77,11 +77,11 @@ class TagController extends Controller foreach ($accounts as $account) { $accountId = $account->id; $report[$accountId] = $report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. @@ -93,12 +93,12 @@ class TagController extends Controller foreach ($tag['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $report[$sourceAccountId]['currencies'][$currencyId] = $report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'tags' => [], - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'tags' => [], + ]; $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']] = $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']] @@ -160,10 +160,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -177,37 +177,37 @@ class TagController extends Controller foreach ($accounts as $account) { $accountId = $account->id; $report[$accountId] = $report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent_sum' => '0', - 'earned_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent_sum' => '0', + 'earned_sum' => '0', + 'total_sum' => '0', + ]; foreach ($currency['tags'] as $tag) { foreach ($tag['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $report[$sourceAccountId]['currencies'][$currencyId] = $report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; $report[$sourceAccountId]['currencies'][$currencyId]['spent'] = bcadd( $report[$sourceAccountId]['currencies'][$currencyId]['spent'], $journal['amount'] @@ -226,26 +226,26 @@ class TagController extends Controller foreach ($earned as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent_sum' => '0', - 'earned_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent_sum' => '0', + 'earned_sum' => '0', + 'total_sum' => '0', + ]; foreach ($currency['tags'] as $tag) { foreach ($tag['transaction_journals'] as $journal) { $destinationAccountId = $journal['destination_account_id']; $report[$destinationAccountId]['currencies'][$currencyId] = $report[$destinationAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; $report[$destinationAccountId]['currencies'][$currencyId]['earned'] = bcadd( $report[$destinationAccountId]['currencies'][$currencyId]['earned'], $journal['amount'] @@ -264,10 +264,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -281,21 +281,21 @@ class TagController extends Controller $destinationId = $journal['destination_account_id']; $key = sprintf('%d-%d', $destinationId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'destination_account_name' => $journal['destination_account_name'], - 'destination_account_id' => $journal['destination_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'destination_account_name' => $journal['destination_account_name'], + 'destination_account_id' => $journal['destination_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; } } } @@ -316,10 +316,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -333,21 +333,21 @@ class TagController extends Controller $sourceId = $journal['source_account_id']; $key = sprintf('%d-%d', $sourceId, $currency['currency_id']); $result[$key] = $result[$key] ?? [ - 'transactions' => 0, - 'sum' => '0', - 'avg' => '0', - 'avg_float' => 0, - 'source_account_name' => $journal['source_account_name'], - 'source_account_id' => $journal['source_account_id'], - 'currency_id' => $currency['currency_id'], - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'transactions' => 0, + 'sum' => '0', + 'avg' => '0', + 'avg_float' => 0, + 'source_account_name' => $journal['source_account_name'], + 'source_account_id' => $journal['source_account_id'], + 'currency_id' => $currency['currency_id'], + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $result[$key]['transactions']++; $result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']); - $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string) $result[$key]['transactions']); - $result[$key]['avg_float'] = (float) $result[$key]['avg']; + $result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']); + $result[$key]['avg_float'] = (float)$result[$key]['avg']; } } } @@ -368,10 +368,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return Factory|View */ @@ -385,22 +385,22 @@ class TagController extends Controller foreach ($tags as $tag) { $tagId = $tag->id; $report[$tagId] = $report[$tagId] ?? [ - 'name' => $tag->tag, - 'id' => $tag->id, - 'currencies' => [], - ]; + 'name' => $tag->tag, + 'id' => $tag->id, + 'currencies' => [], + ]; } foreach ($spent as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'earned_sum' => '0', - 'spent_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'earned_sum' => '0', + 'spent_sum' => '0', + 'total_sum' => '0', + ]; /** @var array $tag */ foreach ($currency['tags'] as $tag) { $tagId = $tag['id']; @@ -408,14 +408,14 @@ class TagController extends Controller foreach ($tag['transaction_journals'] as $journal) { // add currency info to report array: $report[$tagId]['currencies'][$currencyId] = $report[$tagId]['currencies'][$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $report[$tagId]['currencies'][$currencyId]['spent'] = bcadd( $report[$tagId]['currencies'][$currencyId]['spent'], $journal['amount'] @@ -434,14 +434,14 @@ class TagController extends Controller foreach ($earned as $currency) { $currencyId = $currency['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - 'earned_sum' => '0', - 'spent_sum' => '0', - 'total_sum' => '0', - ]; + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + 'earned_sum' => '0', + 'spent_sum' => '0', + 'total_sum' => '0', + ]; /** @var array $tag */ foreach ($currency['tags'] as $tag) { $tagId = $tag['id']; @@ -449,14 +449,14 @@ class TagController extends Controller foreach ($tag['transaction_journals'] as $journal) { // add currency info to report array: $report[$tagId]['currencies'][$currencyId] = $report[$tagId]['currencies'][$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currency['currency_id'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_name' => $currency['currency_name'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currency['currency_id'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_name' => $currency['currency_name'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; $report[$tagId]['currencies'][$currencyId]['earned'] = bcadd( $report[$tagId]['currencies'][$currencyId]['earned'], $journal['amount'] @@ -476,10 +476,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -493,7 +493,7 @@ class TagController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], + 'amount_float' => (float)$journal['amount'], 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), @@ -526,10 +526,10 @@ class TagController extends Controller } /** - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -543,7 +543,7 @@ class TagController extends Controller $result[] = [ 'description' => $journal['description'], 'transaction_group_id' => $journal['transaction_group_id'], - 'amount_float' => (float) $journal['amount'], // intentional float. + 'amount_float' => (float)$journal['amount'], // intentional float. 'amount' => $journal['amount'], 'date' => $journal['date']->isoFormat($this->monthAndDayFormat), 'date_sort' => $journal['date']->format('Y-m-d'), diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php index b9cf7191bd..db1bbe7e0d 100644 --- a/app/Http/Controllers/Rule/CreateController.php +++ b/app/Http/Controllers/Rule/CreateController.php @@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Rule; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleFormRequest; use FireflyIII\Models\Bill; -use FireflyIII\Models\Rule; use FireflyIII\Models\RuleGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; @@ -61,7 +60,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->ruleRepos = app(RuleRepositoryInterface::class); @@ -74,8 +73,8 @@ class CreateController extends Controller /** * Create a new rule. It will be stored under the given $ruleGroup. * - * @param Request $request - * @param RuleGroup|null $ruleGroup + * @param Request $request + * @param RuleGroup|null $ruleGroup * * @return Factory|View */ @@ -89,7 +88,7 @@ class CreateController extends Controller $oldActions = []; // build triggers from query, if present. - $query = (string) $request->get('from_query'); + $query = (string)$request->get('from_query'); if ('' !== $query) { $search = app(SearchInterface::class); $search->parseQuery($query); @@ -113,9 +112,9 @@ class CreateController extends Controller $subTitleIcon = 'fa-clone'; // title depends on whether or not there is a rule group: - $subTitle = (string) trans('firefly.make_new_rule_no_group'); + $subTitle = (string)trans('firefly.make_new_rule_no_group'); if (null !== $ruleGroup) { - $subTitle = (string) trans('firefly.make_new_rule', ['title' => $ruleGroup->title]); + $subTitle = (string)trans('firefly.make_new_rule', ['title' => $ruleGroup->title]); } // flash old data @@ -136,20 +135,20 @@ class CreateController extends Controller /** * Create a new rule. It will be stored under the given $ruleGroup. * - * @param Request $request - * @param Bill $bill + * @param Request $request + * @param Bill $bill * * @return Factory|View */ public function createFromBill(Request $request, Bill $bill) { - $request->session()->flash('info', (string) trans('firefly.instructions_rule_from_bill', ['name' => e($bill->name)])); + $request->session()->flash('info', (string)trans('firefly.instructions_rule_from_bill', ['name' => e($bill->name)])); $this->createDefaultRuleGroup(); $preFilled = [ 'strict' => true, - 'title' => (string) trans('firefly.new_rule_for_bill_title', ['name' => $bill->name]), - 'description' => (string) trans('firefly.new_rule_for_bill_description', ['name' => $bill->name]), + 'title' => (string)trans('firefly.new_rule_for_bill_title', ['name' => $bill->name]), + 'description' => (string)trans('firefly.new_rule_for_bill_description', ['name' => $bill->name]), ]; // make triggers and actions from the bill itself. @@ -169,7 +168,7 @@ class CreateController extends Controller $subTitleIcon = 'fa-clone'; // title depends on whether or not there is a rule group: - $subTitle = (string) trans('firefly.make_new_rule_no_group'); + $subTitle = (string)trans('firefly.make_new_rule_no_group'); // flash old data $request->session()->flash('preFilled', $preFilled); @@ -187,17 +186,17 @@ class CreateController extends Controller } /** - * @param Request $request - * @param TransactionJournal $journal + * @param Request $request + * @param TransactionJournal $journal * * @return Factory|\Illuminate\Contracts\View\View */ public function createFromJournal(Request $request, TransactionJournal $journal) { - $request->session()->flash('info', (string) trans('firefly.instructions_rule_from_journal', ['name' => e($journal->description)])); + $request->session()->flash('info', (string)trans('firefly.instructions_rule_from_journal', ['name' => e($journal->description)])); $subTitleIcon = 'fa-clone'; - $subTitle = (string) trans('firefly.make_new_rule_no_group'); + $subTitle = (string)trans('firefly.make_new_rule_no_group'); // get triggers and actions for journal. $oldTriggers = $this->getTriggersForJournal($journal); @@ -208,8 +207,8 @@ class CreateController extends Controller // collect pre-filled information: $preFilled = [ 'strict' => true, - 'title' => (string) trans('firefly.new_rule_for_journal_title', ['description' => $journal->description]), - 'description' => (string) trans('firefly.new_rule_for_journal_description', ['description' => $journal->description]), + 'title' => (string)trans('firefly.new_rule_for_journal_title', ['description' => $journal->description]), + 'description' => (string)trans('firefly.new_rule_for_journal_description', ['description' => $journal->description]), ]; // restore actions and triggers from old input: @@ -237,12 +236,12 @@ class CreateController extends Controller } /** - * @param Request $request + * @param Request $request * @return JsonResponse */ public function duplicate(Request $request): JsonResponse { - $ruleId = (int) $request->get('id'); + $ruleId = (int)$request->get('id'); $rule = $this->ruleRepos->find($ruleId); if (null !== $rule) { $this->ruleRepos->duplicate($rule); @@ -254,7 +253,7 @@ class CreateController extends Controller /** * Store the new rule. * - * @param RuleFormRequest $request + * @param RuleFormRequest $request * * @return RedirectResponse|Redirector * @@ -264,22 +263,22 @@ class CreateController extends Controller $data = $request->getRuleData(); $rule = $this->ruleRepos->store($data); - session()->flash('success', (string) trans('firefly.stored_new_rule', ['title' => $rule->title])); + session()->flash('success', (string)trans('firefly.stored_new_rule', ['title' => $rule->title])); app('preferences')->mark(); // redirect to show bill. - if ('true' === $request->get('return_to_bill') && (int) $request->get('bill_id') > 0) { - return redirect(route('bills.show', [(int) $request->get('bill_id')])); + if ('true' === $request->get('return_to_bill') && (int)$request->get('bill_id') > 0) { + return redirect(route('bills.show', [(int)$request->get('bill_id')])); } // redirect to new bill creation. - if ((int) $request->get('bill_id') > 0) { + if ((int)$request->get('bill_id') > 0) { return redirect($this->getPreviousUrl('bills.create.url')); } $redirect = redirect($this->getPreviousUrl('rules.create.url')); - if (1 === (int) $request->get('create_another')) { + if (1 === (int)$request->get('create_another')) { session()->put('rules.create.fromStore', true); $redirect = redirect(route('rules.create', [$data['rule_group_id']]))->withInput(); } diff --git a/app/Http/Controllers/Rule/DeleteController.php b/app/Http/Controllers/Rule/DeleteController.php index 2a74e7555f..36c4cba793 100644 --- a/app/Http/Controllers/Rule/DeleteController.php +++ b/app/Http/Controllers/Rule/DeleteController.php @@ -49,7 +49,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->ruleRepos = app(RuleRepositoryInterface::class); @@ -62,13 +62,13 @@ class DeleteController extends Controller /** * Delete a given rule. * - * @param Rule $rule + * @param Rule $rule * * @return Factory|View */ public function delete(Rule $rule) { - $subTitle = (string) trans('firefly.delete_rule', ['title' => $rule->title]); + $subTitle = (string)trans('firefly.delete_rule', ['title' => $rule->title]); // put previous url in session $this->rememberPreviousUrl('rules.delete.url'); @@ -79,7 +79,7 @@ class DeleteController extends Controller /** * Actually destroy the given rule. * - * @param Rule $rule + * @param Rule $rule * * @return RedirectResponse */ @@ -88,7 +88,7 @@ class DeleteController extends Controller $title = $rule->title; $this->ruleRepos->destroy($rule); - session()->flash('success', (string) trans('firefly.deleted_rule', ['title' => $title])); + session()->flash('success', (string)trans('firefly.deleted_rule', ['title' => $title])); app('preferences')->mark(); return redirect($this->getPreviousUrl('rules.delete.url')); diff --git a/app/Http/Controllers/Rule/EditController.php b/app/Http/Controllers/Rule/EditController.php index 29639db9ae..1412c86db1 100644 --- a/app/Http/Controllers/Rule/EditController.php +++ b/app/Http/Controllers/Rule/EditController.php @@ -61,7 +61,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->ruleRepos = app(RuleRepositoryInterface::class); @@ -74,8 +74,8 @@ class EditController extends Controller /** * Edit a rule. * - * @param Request $request - * @param Rule $rule + * @param Request $request + * @param Rule $rule * * @return Factory|View */ @@ -87,7 +87,7 @@ class EditController extends Controller $oldTriggers = []; // build triggers from query, if present. - $query = (string) $request->get('from_query'); + $query = (string)$request->get('from_query'); if ('' !== $query) { $search = app(SearchInterface::class); $search->parseQuery($query); @@ -117,15 +117,15 @@ class EditController extends Controller $hasOldInput = null !== $request->old('_token'); $preFilled = [ - 'active' => $hasOldInput ? (bool) $request->old('active') : $rule->active, - 'stop_processing' => $hasOldInput ? (bool) $request->old('stop_processing') : $rule->stop_processing, - 'strict' => $hasOldInput ? (bool) $request->old('strict') : $rule->strict, + 'active' => $hasOldInput ? (bool)$request->old('active') : $rule->active, + 'stop_processing' => $hasOldInput ? (bool)$request->old('stop_processing') : $rule->stop_processing, + 'strict' => $hasOldInput ? (bool)$request->old('strict') : $rule->strict, ]; // get rule trigger for update / store-journal: $primaryTrigger = $this->ruleRepos->getPrimaryTrigger($rule); - $subTitle = (string) trans('firefly.edit_rule', ['title' => $rule->title]); + $subTitle = (string)trans('firefly.edit_rule', ['title' => $rule->title]); // put previous url in session if not redirect from store (not "return_to_edit"). if (true !== session('rules.edit.fromUpdate')) { @@ -139,7 +139,7 @@ class EditController extends Controller } /** - * @param array $submittedOperators + * @param array $submittedOperators * * @return array */ @@ -151,7 +151,7 @@ class EditController extends Controller $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); @@ -183,8 +183,8 @@ class EditController extends Controller /** * Update the rule. * - * @param RuleFormRequest $request - * @param Rule $rule + * @param RuleFormRequest $request + * @param Rule $rule * * @return RedirectResponse|Redirector */ @@ -194,10 +194,10 @@ class EditController extends Controller $this->ruleRepos->update($rule, $data); - session()->flash('success', (string) trans('firefly.updated_rule', ['title' => $rule->title])); + session()->flash('success', (string)trans('firefly.updated_rule', ['title' => $rule->title])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUrl('rules.edit.url')); - if (1 === (int) $request->get('return_to_edit')) { + if (1 === (int)$request->get('return_to_edit')) { session()->put('rules.edit.fromUpdate', true); $redirect = redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]); diff --git a/app/Http/Controllers/Rule/IndexController.php b/app/Http/Controllers/Rule/IndexController.php index 7323dec1c5..47dd5178db 100644 --- a/app/Http/Controllers/Rule/IndexController.php +++ b/app/Http/Controllers/Rule/IndexController.php @@ -1,4 +1,5 @@ middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->ruleGroupRepos = app(RuleGroupRepositoryInterface::class); $this->ruleRepos = app(RuleRepositoryInterface::class); @@ -79,22 +80,22 @@ class IndexController extends Controller } /** - * @param Request $request - * @param Rule $rule - * @param RuleGroup $ruleGroup + * @param Request $request + * @param Rule $rule + * @param RuleGroup $ruleGroup * * @return JsonResponse */ public function moveRule(Request $request, Rule $rule, RuleGroup $ruleGroup): JsonResponse { - $order = (int) $request->get('order'); - $this->ruleRepos->moveRule($rule, $ruleGroup, (int) $order); + $order = (int)$request->get('order'); + $this->ruleRepos->moveRule($rule, $ruleGroup, (int)$order); return response()->json([]); } /** - * @param Rule $rule + * @param Rule $rule * * @return RedirectResponse */ diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index d2346e2801..ad57565d7e 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -59,7 +59,7 @@ class SelectController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); return $next($request); @@ -70,8 +70,8 @@ class SelectController extends Controller /** * Execute the given rule on a set of existing transactions. * - * @param SelectTransactionsRequest $request - * @param Rule $rule + * @param SelectTransactionsRequest $request + * @param Rule $rule * * @return RedirectResponse */ @@ -98,7 +98,7 @@ class SelectController extends Controller $newRuleEngine->fire(); $resultCount = $newRuleEngine->getResults(); - session()->flash('success', (string) trans_choice('firefly.applied_rule_selection', $resultCount, ['title' => $rule->title])); + session()->flash('success', (string)trans_choice('firefly.applied_rule_selection', $resultCount, ['title' => $rule->title])); return redirect()->route('rules.index'); } @@ -106,7 +106,7 @@ class SelectController extends Controller /** * View to select transactions by a rule. * - * @param Rule $rule + * @param Rule $rule * * @return Factory|View */ @@ -120,7 +120,7 @@ class SelectController extends Controller // does the user have shared accounts? $first = session('first', Carbon::now()->subYear())->format('Y-m-d'); $today = Carbon::now()->format('Y-m-d'); - $subTitle = (string) trans('firefly.apply_rule_selection', ['title' => $rule->title]); + $subTitle = (string)trans('firefly.apply_rule_selection', ['title' => $rule->title]); return view('rules.rule.select-transactions', compact('first', 'today', 'rule', 'subTitle')); } @@ -129,7 +129,7 @@ class SelectController extends Controller * This method allows the user to test a certain set of rule triggers. The rule triggers are passed along * using the URL parameters (GET), and are usually put there using a Javascript thing. * - * @param TestRuleFormRequest $request + * @param TestRuleFormRequest $request * * @return JsonResponse * @@ -146,7 +146,7 @@ class SelectController extends Controller // warn if nothing. if (0 === count($textTriggers)) { - return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); + return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); } foreach ($textTriggers as $textTrigger) { @@ -170,7 +170,7 @@ class SelectController extends Controller // Warn the user if only a subset of transactions is returned $warning = ''; if (0 === count($collection)) { - $warning = (string) trans('firefly.warning_no_matching_transactions'); + $warning = (string)trans('firefly.warning_no_matching_transactions'); } // Return json response @@ -191,7 +191,7 @@ class SelectController extends Controller * This method allows the user to test a certain set of rule triggers. The rule triggers are grabbed from * the rule itself. * - * @param Rule $rule + * @param Rule $rule * * @return JsonResponse * @@ -201,7 +201,7 @@ class SelectController extends Controller $triggers = $rule->ruleTriggers; if (0 === count($triggers)) { - return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); + return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); } // create new rule engine: $newRuleEngine = app(RuleEngineInterface::class); @@ -213,7 +213,7 @@ class SelectController extends Controller $warning = ''; if (0 === count($collection)) { - $warning = (string) trans('firefly.warning_no_matching_transactions'); + $warning = (string)trans('firefly.warning_no_matching_transactions'); } // Return json response diff --git a/app/Http/Controllers/RuleGroup/CreateController.php b/app/Http/Controllers/RuleGroup/CreateController.php index 55c91fdd1f..04df9b1a5f 100644 --- a/app/Http/Controllers/RuleGroup/CreateController.php +++ b/app/Http/Controllers/RuleGroup/CreateController.php @@ -50,7 +50,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->repository = app(RuleGroupRepositoryInterface::class); @@ -68,7 +68,7 @@ class CreateController extends Controller public function create() { $subTitleIcon = 'fa-clone'; - $subTitle = (string) trans('firefly.make_new_rule_group'); + $subTitle = (string)trans('firefly.make_new_rule_group'); // put previous url in session if not redirect from store (not "create another"). if (true !== session('rule-groups.create.fromStore')) { @@ -82,7 +82,7 @@ class CreateController extends Controller /** * Store the rule group. * - * @param RuleGroupFormRequest $request + * @param RuleGroupFormRequest $request * * @return RedirectResponse|Redirector */ @@ -91,11 +91,11 @@ class CreateController extends Controller $data = $request->getRuleGroupData(); $ruleGroup = $this->repository->store($data); - session()->flash('success', (string) trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title])); + session()->flash('success', (string)trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUrl('rule-groups.create.url')); - if (1 === (int) $request->get('create_another')) { + if (1 === (int)$request->get('create_another')) { session()->put('rule-groups.create.fromStore', true); $redirect = redirect(route('rule-groups.create'))->withInput(); diff --git a/app/Http/Controllers/RuleGroup/DeleteController.php b/app/Http/Controllers/RuleGroup/DeleteController.php index fdc92c527c..eaddb527a3 100644 --- a/app/Http/Controllers/RuleGroup/DeleteController.php +++ b/app/Http/Controllers/RuleGroup/DeleteController.php @@ -51,7 +51,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->repository = app(RuleGroupRepositoryInterface::class); @@ -64,13 +64,13 @@ class DeleteController extends Controller /** * Delete a rule group. * - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return Factory|View */ public function delete(RuleGroup $ruleGroup) { - $subTitle = (string) trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]); + $subTitle = (string)trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]); // put previous url in session $this->rememberPreviousUrl('rule-groups.delete.url'); @@ -81,8 +81,8 @@ class DeleteController extends Controller /** * Actually destroy the rule group. * - * @param Request $request - * @param RuleGroup $ruleGroup + * @param Request $request + * @param RuleGroup $ruleGroup * * @return RedirectResponse|Redirector */ @@ -91,10 +91,10 @@ class DeleteController extends Controller $title = $ruleGroup->title; /** @var RuleGroup $moveTo */ - $moveTo = $this->repository->find((int) $request->get('move_rules_before_delete')); + $moveTo = $this->repository->find((int)$request->get('move_rules_before_delete')); $this->repository->destroy($ruleGroup, $moveTo); - session()->flash('success', (string) trans('firefly.deleted_rule_group', ['title' => $title])); + session()->flash('success', (string)trans('firefly.deleted_rule_group', ['title' => $title])); app('preferences')->mark(); return redirect($this->getPreviousUrl('rule-groups.delete.url')); diff --git a/app/Http/Controllers/RuleGroup/EditController.php b/app/Http/Controllers/RuleGroup/EditController.php index 1449fa1a5f..b18e66c888 100644 --- a/app/Http/Controllers/RuleGroup/EditController.php +++ b/app/Http/Controllers/RuleGroup/EditController.php @@ -52,7 +52,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->repository = app(RuleGroupRepositoryInterface::class); @@ -65,18 +65,18 @@ class EditController extends Controller /** * Edit a rule group. * - * @param Request $request - * @param RuleGroup $ruleGroup + * @param Request $request + * @param RuleGroup $ruleGroup * * @return Factory|View */ public function edit(Request $request, RuleGroup $ruleGroup) { - $subTitle = (string) trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]); + $subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]); $hasOldInput = null !== $request->old('_token'); $preFilled = [ - 'active' => $hasOldInput ? (bool) $request->old('active') : $ruleGroup->active, + 'active' => $hasOldInput ? (bool)$request->old('active') : $ruleGroup->active, ]; // put previous url in session if not redirect from store (not "return_to_edit"). if (true !== session('rule-groups.edit.fromUpdate')) { @@ -91,26 +91,26 @@ class EditController extends Controller /** * Move a rule group in either direction. * - * @param Request $request + * @param Request $request * * @return JsonResponse */ public function moveGroup(Request $request): JsonResponse { - $groupId = (int) $request->get('id'); + $groupId = (int)$request->get('id'); $ruleGroup = $this->repository->find($groupId); if (null !== $ruleGroup) { $direction = $request->get('direction'); if ('down' === $direction) { $maxOrder = $this->repository->maxOrder(); - $order = (int) $ruleGroup->order; + $order = (int)$ruleGroup->order; if ($order < $maxOrder) { $newOrder = $order + 1; $this->repository->setOrder($ruleGroup, $newOrder); } } if ('up' === $direction) { - $order = (int) $ruleGroup->order; + $order = (int)$ruleGroup->order; if ($order > 1) { $newOrder = $order - 1; $this->repository->setOrder($ruleGroup, $newOrder); @@ -123,8 +123,8 @@ class EditController extends Controller /** * Update the rule group. * - * @param RuleGroupFormRequest $request - * @param RuleGroup $ruleGroup + * @param RuleGroupFormRequest $request + * @param RuleGroup $ruleGroup * * @return $this|RedirectResponse|Redirector */ @@ -133,15 +133,15 @@ class EditController extends Controller $data = [ 'title' => $request->convertString('title'), 'description' => $request->stringWithNewlines('description'), - 'active' => 1 === (int) $request->input('active'), + 'active' => 1 === (int)$request->input('active'), ]; $this->repository->update($ruleGroup, $data); - session()->flash('success', (string) trans('firefly.updated_rule_group', ['title' => $ruleGroup->title])); + session()->flash('success', (string)trans('firefly.updated_rule_group', ['title' => $ruleGroup->title])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUrl('rule-groups.edit.url')); - if (1 === (int) $request->get('return_to_edit')) { + if (1 === (int)$request->get('return_to_edit')) { session()->put('rule-groups.edit.fromUpdate', true); $redirect = redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]); diff --git a/app/Http/Controllers/RuleGroup/ExecutionController.php b/app/Http/Controllers/RuleGroup/ExecutionController.php index 39d0bc89b8..14a75e5ea1 100644 --- a/app/Http/Controllers/RuleGroup/ExecutionController.php +++ b/app/Http/Controllers/RuleGroup/ExecutionController.php @@ -53,7 +53,7 @@ class ExecutionController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.rules')); + app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); $this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class); @@ -66,8 +66,8 @@ class ExecutionController extends Controller /** * Execute the given rulegroup on a set of existing transactions. * - * @param SelectTransactionsRequest $request - * @param RuleGroup $ruleGroup + * @param SelectTransactionsRequest $request + * @param RuleGroup $ruleGroup * * @return RedirectResponse * @throws Exception @@ -95,7 +95,7 @@ class ExecutionController extends Controller $newRuleEngine->fire(); // Tell the user that the job is queued - session()->flash('success', (string) trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title])); + session()->flash('success', (string)trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title])); return redirect()->route('rules.index'); } @@ -103,7 +103,7 @@ class ExecutionController extends Controller /** * Select transactions to apply the group on. * - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return Factory|View */ @@ -111,7 +111,7 @@ class ExecutionController extends Controller { $first = session('first')->format('Y-m-d'); $today = Carbon::now()->format('Y-m-d'); - $subTitle = (string) trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]); + $subTitle = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]); return view('rules.rule-group.select-transactions', compact('first', 'today', 'ruleGroup', 'subTitle')); } diff --git a/app/Http/Controllers/System/HealthcheckController.php b/app/Http/Controllers/System/HealthcheckController.php index 7455aa5cc4..fef70b5b05 100644 --- a/app/Http/Controllers/System/HealthcheckController.php +++ b/app/Http/Controllers/System/HealthcheckController.php @@ -1,4 +1,5 @@ set('ff3_version', (string) config('firefly.version')); + app('fireflyconfig')->set('ff3_version', (string)config('firefly.version')); // set new DB version. - app('fireflyconfig')->set('db_version', (int) config('firefly.db_version')); + app('fireflyconfig')->set('db_version', (int)config('firefly.db_version')); return view('install.index'); } /** - * @param Request $request + * @param Request $request * * @return JsonResponse */ public function runCommand(Request $request): JsonResponse { - $requestIndex = (int) $request->get('index'); + $requestIndex = (int)$request->get('index'); $response = [ 'hasNextCommand' => false, 'done' => true, @@ -156,7 +156,7 @@ class InstallController extends Controller $index = 0; /** * @var string $command - * @var array $args + * @var array $args */ foreach ($this->upgradeCommands as $command => $args) { Log::debug(sprintf('Current command is "%s", index is %d', $command, $index)); @@ -182,8 +182,8 @@ class InstallController extends Controller } /** - * @param string $command - * @param array $args + * @param string $command + * @param array $args * * @return bool */ diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php index 2f20179698..ea63afab36 100644 --- a/app/Http/Controllers/Transaction/BulkController.php +++ b/app/Http/Controllers/Transaction/BulkController.php @@ -57,7 +57,7 @@ class BulkController extends Controller $this->middleware( function ($request, $next) { $this->repository = app(JournalRepositoryInterface::class); - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); return $next($request); @@ -70,13 +70,13 @@ class BulkController extends Controller * * TODO user wont be able to tell if the journal is part of a split. * - * @param array $journals + * @param array $journals * * @return Factory|View */ public function edit(array $journals) { - $subTitle = (string) trans('firefly.mass_bulk_journals'); + $subTitle = (string)trans('firefly.mass_bulk_journals'); $this->rememberPreviousUrl('transactions.bulk-edit.url'); @@ -93,7 +93,7 @@ class BulkController extends Controller /** * Update all journals. * - * @param BulkEditJournalRequest $request + * @param BulkEditJournalRequest $request * * @return Application|RedirectResponse|Redirector */ @@ -101,14 +101,14 @@ class BulkController extends Controller { $journalIds = $request->get('journals'); $journalIds = is_array($journalIds) ? $journalIds : []; - $ignoreCategory = 1 === (int) $request->get('ignore_category'); - $ignoreBudget = 1 === (int) $request->get('ignore_budget'); + $ignoreCategory = 1 === (int)$request->get('ignore_category'); + $ignoreBudget = 1 === (int)$request->get('ignore_budget'); $tagsAction = $request->get('tags_action'); $collection = new Collection(); $count = 0; foreach ($journalIds as $journalId) { - $journalId = (int) $journalId; + $journalId = (int)$journalId; $journal = $this->repository->find($journalId); if (null !== $journal) { $resultA = $this->updateJournalBudget($journal, $ignoreBudget, $request->integer('budget_id')); @@ -128,16 +128,16 @@ class BulkController extends Controller } app('preferences')->mark(); - $request->session()->flash('success', (string) trans_choice('firefly.mass_edited_transactions_success', $count)); + $request->session()->flash('success', (string)trans_choice('firefly.mass_edited_transactions_success', $count)); // redirect to previous URL: return redirect($this->getPreviousUrl('transactions.bulk-edit.url')); } /** - * @param TransactionJournal $journal - * @param bool $ignoreUpdate - * @param int $budgetId + * @param TransactionJournal $journal + * @param bool $ignoreUpdate + * @param int $budgetId * * @return bool */ @@ -153,9 +153,9 @@ class BulkController extends Controller } /** - * @param TransactionJournal $journal - * @param string $action - * @param array $tags + * @param TransactionJournal $journal + * @param string $action + * @param array $tags * * @return bool */ @@ -175,9 +175,9 @@ class BulkController extends Controller } /** - * @param TransactionJournal $journal - * @param bool $ignoreUpdate - * @param string $category + * @param TransactionJournal $journal + * @param bool $ignoreUpdate + * @param string $category * * @return bool */ diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index 78ee0fda5b..b64474d184 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -1,4 +1,5 @@ repository = app(JournalRepositoryInterface::class); $this->accountRepository = app(AccountRepositoryInterface::class); - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); return $next($request); @@ -81,8 +82,8 @@ class ConvertController extends Controller /** * Show overview of a to be converted transaction. * - * @param TransactionType $destinationType - * @param TransactionGroup $group + * @param TransactionType $destinationType + * @param TransactionGroup $group * * @return RedirectResponse|Redirector|Factory|View * @throws Exception @@ -103,7 +104,7 @@ class ConvertController extends Controller $groupTitle = $group->title ?? $first->description; $groupArray = $transformer->transformObject($group); - $subTitle = (string) trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]); + $subTitle = (string)trans('firefly.convert_to_'.$destinationType->type, ['description' => $groupTitle]); $subTitleIcon = 'fa-exchange'; // get a list of asset accounts and liabilities and stuff, in various combinations: @@ -119,7 +120,7 @@ class ConvertController extends Controller if ($sourceType->type === $destinationType->type) { // cannot convert to its own type. Log::debug('This is already a transaction of the expected type..'); - session()->flash('info', (string) trans('firefly.convert_is_already_type_' . $destinationType->type)); + session()->flash('info', (string)trans('firefly.convert_is_already_type_'.$destinationType->type)); return redirect(route('transactions.show', [$group->id])); } @@ -156,7 +157,7 @@ class ConvertController extends Controller // group accounts: /** @var Account $account */ foreach ($accountList as $account) { - $role = (string) $this->accountRepository->getMetaValue($account, 'account_role'); + $role = (string)$this->accountRepository->getMetaValue($account, 'account_role'); $name = $account->name; if ('' === $role) { $role = 'no_account_type'; @@ -164,7 +165,7 @@ class ConvertController extends Controller // maybe it's a liability thing: if (in_array($account->accountType->type, $liabilityTypes, true)) { - $role = 'l_' . $account->accountType->type; + $role = 'l_'.$account->accountType->type; } if (AccountType::CASH === $account->accountType->type) { $role = 'cash_account'; @@ -174,7 +175,7 @@ class ConvertController extends Controller $role = 'revenue_account'; } - $key = (string) trans('firefly.opt_group_' . $role); + $key = (string)trans('firefly.opt_group_'.$role); $grouped[$key][$account->id] = $name; } @@ -195,7 +196,7 @@ class ConvertController extends Controller // group accounts: /** @var Account $account */ foreach ($accountList as $account) { - $role = (string) $this->accountRepository->getMetaValue($account, 'account_role'); + $role = (string)$this->accountRepository->getMetaValue($account, 'account_role'); $name = $account->name; if ('' === $role) { $role = 'no_account_type'; @@ -203,7 +204,7 @@ class ConvertController extends Controller // maybe it's a liability thing: if (in_array($account->accountType->type, $liabilityTypes, true)) { - $role = 'l_' . $account->accountType->type; + $role = 'l_'.$account->accountType->type; } if (AccountType::CASH === $account->accountType->type) { $role = 'cash_account'; @@ -213,7 +214,7 @@ class ConvertController extends Controller $role = 'expense_account'; } - $key = (string) trans('firefly.opt_group_' . $role); + $key = (string)trans('firefly.opt_group_'.$role); $grouped[$key][$account->id] = $name; } @@ -235,9 +236,9 @@ class ConvertController extends Controller foreach ($accountList as $account) { $balance = app('steam')->balance($account, today()); $currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency; - $role = 'l_' . $account->accountType->type; - $key = (string) trans('firefly.opt_group_' . $role); - $grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')'; + $role = 'l_'.$account->accountType->type; + $key = (string)trans('firefly.opt_group_'.$role); + $grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')'; } return $grouped; @@ -258,13 +259,13 @@ class ConvertController extends Controller foreach ($accountList as $account) { $balance = app('steam')->balance($account, today()); $currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency; - $role = (string) $this->accountRepository->getMetaValue($account, 'account_role'); + $role = (string)$this->accountRepository->getMetaValue($account, 'account_role'); if ('' === $role) { $role = 'no_account_type'; } - $key = (string) trans('firefly.opt_group_' . $role); - $grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')'; + $key = (string)trans('firefly.opt_group_'.$role); + $grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')'; } return $grouped; @@ -273,9 +274,9 @@ class ConvertController extends Controller /** * Do the conversion. * - * @param Request $request - * @param TransactionType $destinationType - * @param TransactionGroup $group + * @param Request $request + * @param TransactionType $destinationType + * @param TransactionGroup $group * * @return RedirectResponse|Redirector * @@ -301,16 +302,16 @@ class ConvertController extends Controller // correct transfers: $group->refresh(); - session()->flash('success', (string) trans('firefly.converted_to_' . $destinationType->type)); + session()->flash('success', (string)trans('firefly.converted_to_'.$destinationType->type)); event(new UpdatedTransactionGroup($group, true, true)); return redirect(route('transactions.show', [$group->id])); } /** - * @param TransactionJournal $journal - * @param TransactionType $transactionType - * @param array $data + * @param TransactionJournal $journal + * @param TransactionType $transactionType + * @param array $data * * @return TransactionJournal * @throws FireflyException @@ -328,10 +329,10 @@ class ConvertController extends Controller $destinationName = $data['destination_name'][$journal->id] ?? null; // double check its not an empty string. - $sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId; - $sourceName = '' === $sourceName ? null : (string) $sourceName; - $destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId; - $destinationName = '' === $destinationName ? null : (string) $destinationName; + $sourceId = '' === $sourceId || null === $sourceId ? null : (int)$sourceId; + $sourceName = '' === $sourceName ? null : (string)$sourceName; + $destinationId = '' === $destinationId || null === $destinationId ? null : (int)$destinationId; + $destinationName = '' === $destinationName ? null : (string)$destinationName; $validSource = $validator->validateSource(['id' => $sourceId, 'name' => $sourceName,]); $validDestination = $validator->validateDestination(['id' => $destinationId, 'name' => $destinationName,]); diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php index 53cc071651..cdca03ae74 100644 --- a/app/Http/Controllers/Transaction/CreateController.php +++ b/app/Http/Controllers/Transaction/CreateController.php @@ -33,6 +33,9 @@ use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use JsonException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class CreateController @@ -52,7 +55,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); $this->repository = app(TransactionGroupRepositoryInterface::class); @@ -62,13 +65,13 @@ class CreateController extends Controller } /** - * @param Request $request + * @param Request $request * * @return JsonResponse */ public function cloneGroup(Request $request): JsonResponse { - $groupId = (int) $request->get('id'); + $groupId = (int)$request->get('id'); if (0 !== $groupId) { $group = $this->repository->find($groupId); if (null !== $group) { @@ -96,26 +99,26 @@ class CreateController extends Controller /** * Create a new transaction group. * - * @param string|null $objectType + * @param string|null $objectType * * @return Factory|View * @throws FireflyException - * @throws \JsonException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws JsonException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function create(?string $objectType) { app('preferences')->mark(); - $sourceId = (int) request()->get('source'); - $destinationId = (int) request()->get('destination'); + $sourceId = (int)request()->get('source'); + $destinationId = (int)request()->get('destination'); /** @var AccountRepositoryInterface $accountRepository */ $accountRepository = app(AccountRepositoryInterface::class); $cash = $accountRepository->getCashAccount(); $preFilled = session()->has('preFilled') ? session('preFilled') : []; - $subTitle = (string) trans(sprintf('breadcrumbs.create_%s', strtolower((string) $objectType))); + $subTitle = (string)trans(sprintf('breadcrumbs.create_%s', strtolower((string)$objectType))); $subTitleIcon = 'fa-plus'; $optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data; $allowedOpposingTypes = config('firefly.allowed_opposing_types'); diff --git a/app/Http/Controllers/Transaction/DeleteController.php b/app/Http/Controllers/Transaction/DeleteController.php index 196ca0fca6..39b6290b64 100644 --- a/app/Http/Controllers/Transaction/DeleteController.php +++ b/app/Http/Controllers/Transaction/DeleteController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Transaction; -use FireflyIII\Events\DestroyedTransactionGroup; use FireflyIII\Events\UpdatedAccount; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; @@ -57,7 +56,7 @@ class DeleteController extends Controller // translations: $this->middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); $this->repository = app(TransactionGroupRepositoryInterface::class); @@ -70,7 +69,7 @@ class DeleteController extends Controller /** * Shows the form that allows a user to delete a transaction journal. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return Factory|View|Redirector|RedirectResponse */ @@ -87,7 +86,7 @@ class DeleteController extends Controller throw new NotFoundHttpException(); } $objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type); - $subTitle = (string) trans('firefly.delete_' . $objectType, ['description' => $group->title ?? $journal->description]); + $subTitle = (string)trans('firefly.delete_'.$objectType, ['description' => $group->title ?? $journal->description]); $previous = app('steam')->getSafePreviousUrl(route('index')); // put previous url in session Log::debug('Will try to remember previous URL'); @@ -99,7 +98,7 @@ class DeleteController extends Controller /** * Actually destroys the journal. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return RedirectResponse */ @@ -114,7 +113,7 @@ class DeleteController extends Controller throw new NotFoundHttpException(); } $objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type); - session()->flash('success', (string) trans('firefly.deleted_' . strtolower($objectType), ['description' => $group->title ?? $journal->description])); + session()->flash('success', (string)trans('firefly.deleted_'.strtolower($objectType), ['description' => $group->title ?? $journal->description])); // grab asset account(s) from group: $accounts = []; diff --git a/app/Http/Controllers/Transaction/EditController.php b/app/Http/Controllers/Transaction/EditController.php index 6593c4f6fc..f34121a3ab 100644 --- a/app/Http/Controllers/Transaction/EditController.php +++ b/app/Http/Controllers/Transaction/EditController.php @@ -48,7 +48,7 @@ class EditController extends Controller // some useful repositories: $this->middleware( static function ($request, $next) { - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); return $next($request); @@ -57,7 +57,7 @@ class EditController extends Controller } /** - * @param TransactionGroup $transactionGroup + * @param TransactionGroup $transactionGroup * * @return Factory|View|RedirectResponse|Redirector */ diff --git a/app/Http/Controllers/Transaction/IndexController.php b/app/Http/Controllers/Transaction/IndexController.php index dbd6dd594b..e7c01542fc 100644 --- a/app/Http/Controllers/Transaction/IndexController.php +++ b/app/Http/Controllers/Transaction/IndexController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Transaction; use Carbon\Carbon; -use Exception; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; @@ -32,6 +32,8 @@ use FireflyIII\Support\Http\Controllers\PeriodOverview; use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\View\View; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class IndexController @@ -55,7 +57,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-exchange'); - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); $this->repository = app(JournalRepositoryInterface::class); @@ -67,15 +69,15 @@ class IndexController extends Controller /** * Index for a range of transactions. * - * @param Request $request - * @param string $objectType - * @param Carbon|null $start - * @param Carbon|null $end + * @param Request $request + * @param string $objectType + * @param Carbon|null $start + * @param Carbon|null $end * * @return Factory|View - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws FireflyException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function index(Request $request, string $objectType, Carbon $start = null, Carbon $end = null) { @@ -83,10 +85,10 @@ class IndexController extends Controller $objectType = 'transfer'; } - $subTitleIcon = config('firefly.transactionIconsByType.' . $objectType); - $types = config('firefly.transactionTypesByType.' . $objectType); - $page = (int) $request->get('page'); - $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; + $subTitleIcon = config('firefly.transactionIconsByType.'.$objectType); + $types = config('firefly.transactionTypesByType.'.$objectType); + $page = (int)$request->get('page'); + $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; if (null === $start) { $start = session('start'); $end = session('end'); @@ -101,7 +103,7 @@ class IndexController extends Controller $path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]); $startStr = $start->isoFormat($this->monthAndDayFormat); $endStr = $end->isoFormat($this->monthAndDayFormat); - $subTitle = (string) trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]); + $subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]); $firstJournal = $this->repository->firstNull(); $startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date; @@ -128,26 +130,26 @@ class IndexController extends Controller /** * Index for ALL transactions. * - * @param Request $request - * @param string $objectType + * @param Request $request + * @param string $objectType * * @return Factory|View - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws FireflyException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function indexAll(Request $request, string $objectType) { - $subTitleIcon = config('firefly.transactionIconsByType.' . $objectType); - $types = config('firefly.transactionTypesByType.' . $objectType); - $page = (int) $request->get('page'); - $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; + $subTitleIcon = config('firefly.transactionIconsByType.'.$objectType); + $types = config('firefly.transactionTypesByType.'.$objectType); + $page = (int)$request->get('page'); + $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $path = route('transactions.index.all', [$objectType]); $first = $this->repository->firstNull(); $start = null === $first ? new Carbon() : $first->date; $last = $this->repository->getLast(); $end = $last ? $last->date : today(config('app.timezone')); - $subTitle = (string) trans('firefly.all_' . $objectType); + $subTitle = (string)trans('firefly.all_'.$objectType); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php index 48627302d4..3534bb7b95 100644 --- a/app/Http/Controllers/Transaction/LinkController.php +++ b/app/Http/Controllers/Transaction/LinkController.php @@ -1,4 +1,5 @@ middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); $this->journalRepository = app(JournalRepositoryInterface::class); @@ -68,14 +69,14 @@ class LinkController extends Controller /** * Delete a link. * - * @param TransactionJournalLink $link + * @param TransactionJournalLink $link * * @return Factory|View */ public function delete(TransactionJournalLink $link) { $subTitleIcon = 'fa-link'; - $subTitle = (string) trans('breadcrumbs.delete_journal_link'); + $subTitle = (string)trans('breadcrumbs.delete_journal_link'); $this->rememberPreviousUrl('journal_links.delete.url'); return view('transactions.links.delete', compact('link', 'subTitle', 'subTitleIcon')); @@ -84,7 +85,7 @@ class LinkController extends Controller /** * Actually destroy it. * - * @param TransactionJournalLink $link + * @param TransactionJournalLink $link * * @return RedirectResponse|Redirector */ @@ -92,14 +93,14 @@ class LinkController extends Controller { $this->repository->destroyLink($link); - session()->flash('success', (string) trans('firefly.deleted_link')); + session()->flash('success', (string)trans('firefly.deleted_link')); app('preferences')->mark(); - return redirect((string) session('journal_links.delete.url')); + return redirect((string)session('journal_links.delete.url')); } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Factory|View */ @@ -113,8 +114,8 @@ class LinkController extends Controller /** * Store a new link. * - * @param JournalLinkRequest $request - * @param TransactionJournal $journal + * @param JournalLinkRequest $request + * @param TransactionJournal $journal * * @return RedirectResponse|Redirector */ @@ -125,7 +126,7 @@ class LinkController extends Controller Log::debug('We are here (store)'); $other = $this->journalRepository->find($linkInfo['transaction_journal_id']); if (null === $other) { - session()->flash('error', (string) trans('firefly.invalid_link_selection')); + session()->flash('error', (string)trans('firefly.invalid_link_selection')); return redirect(route('transactions.show', [$journal->transaction_group_id])); } @@ -133,19 +134,19 @@ class LinkController extends Controller $alreadyLinked = $this->repository->findLink($journal, $other); if ($other->id === $journal->id) { - session()->flash('error', (string) trans('firefly.journals_link_to_self')); + session()->flash('error', (string)trans('firefly.journals_link_to_self')); return redirect(route('transactions.show', [$journal->transaction_group_id])); } if ($alreadyLinked) { - session()->flash('error', (string) trans('firefly.journals_error_linked')); + session()->flash('error', (string)trans('firefly.journals_error_linked')); return redirect(route('transactions.show', [$journal->transaction_group_id])); } Log::debug(sprintf('Journal is %d, opposing is %d', $journal->id, $other->id)); $this->repository->storeLink($linkInfo, $other, $journal); - session()->flash('success', (string) trans('firefly.journals_linked')); + session()->flash('success', (string)trans('firefly.journals_linked')); return redirect(route('transactions.show', [$journal->transaction_group_id])); } @@ -153,12 +154,12 @@ class LinkController extends Controller /** * Switch link from A <> B to B <> A. * - * @param Request $request + * @param Request $request * @return RedirectResponse|Redirector */ public function switchLink(Request $request) { - $linkId = (int) $request->get('id'); + $linkId = (int)$request->get('id'); $this->repository->switchLinkById($linkId); return redirect(app('steam')->getSafePreviousUrl()); diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index efee9b13e0..91457cbdb2 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -1,4 +1,5 @@ middleware( function ($request, $next) { - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); $this->repository = app(JournalRepositoryInterface::class); @@ -73,13 +74,13 @@ class MassController extends Controller /** * Mass delete transactions. * - * @param array $journals + * @param array $journals * * @return IlluminateView */ public function delete(array $journals): IlluminateView { - $subTitle = (string) trans('firefly.mass_delete_journals'); + $subTitle = (string)trans('firefly.mass_delete_journals'); // put previous url in session $this->rememberPreviousUrl('transactions.mass-delete.url'); @@ -90,7 +91,7 @@ class MassController extends Controller /** * Do the mass delete. * - * @param MassDeleteJournalRequest $request + * @param MassDeleteJournalRequest $request * * @return Application|Redirector|RedirectResponse * @@ -103,15 +104,15 @@ class MassController extends Controller /** @var string $journalId */ foreach ($ids as $journalId) { /** @var TransactionJournal $journal */ - $journal = $this->repository->find((int) $journalId); - if (null !== $journal && (int) $journalId === $journal->id) { + $journal = $this->repository->find((int)$journalId); + if (null !== $journal && (int)$journalId === $journal->id) { $this->repository->destroyJournal($journal); ++$count; } } } app('preferences')->mark(); - session()->flash('success', (string) trans_choice('firefly.mass_deleted_transactions_success', $count)); + session()->flash('success', (string)trans_choice('firefly.mass_deleted_transactions_success', $count)); // redirect to previous URL: return redirect($this->getPreviousUrl('transactions.mass-delete.url')); @@ -120,13 +121,13 @@ class MassController extends Controller /** * Mass edit of journals. * - * @param array $journals + * @param array $journals * * @return IlluminateView */ public function edit(array $journals): IlluminateView { - $subTitle = (string) trans('firefly.mass_edit_journals'); + $subTitle = (string)trans('firefly.mass_edit_journals'); /** @var AccountRepositoryInterface $accountRepository */ $accountRepository = app(AccountRepositoryInterface::class); @@ -158,7 +159,7 @@ class MassController extends Controller /** * Mass update of journals. * - * @param MassEditJournalRequest $request + * @param MassEditJournalRequest $request * * @return RedirectResponse|Redirector * @throws FireflyException @@ -173,7 +174,7 @@ class MassController extends Controller $count = 0; /** @var string $journalId */ foreach ($journalIds as $journalId) { - $integer = (int) $journalId; + $integer = (int)$journalId; try { $this->updateJournal($integer, $request); $count++; @@ -183,15 +184,15 @@ class MassController extends Controller } app('preferences')->mark(); - session()->flash('success', (string) trans_choice('firefly.mass_edited_transactions_success', $count)); + session()->flash('success', (string)trans_choice('firefly.mass_edited_transactions_success', $count)); // redirect to previous URL: return redirect($this->getPreviousUrl('transactions.mass-edit.url')); } /** - * @param int $journalId - * @param MassEditJournalRequest $request + * @param int $journalId + * @param MassEditJournalRequest $request * * @throws FireflyException */ @@ -227,9 +228,9 @@ class MassController extends Controller } /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $key + * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $key * * @return Carbon|null * @codeCoverageIgnore @@ -255,9 +256,9 @@ class MassController extends Controller } /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $string + * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $string * * @return string|null * @codeCoverageIgnore @@ -272,13 +273,13 @@ class MassController extends Controller return null; } - return (string) $value[$journalId]; + return (string)$value[$journalId]; } /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $string + * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $string * * @return int|null * @codeCoverageIgnore @@ -293,6 +294,6 @@ class MassController extends Controller return null; } - return (int) $value[$journalId]; + return (int)$value[$journalId]; } } diff --git a/app/Http/Controllers/Transaction/ShowController.php b/app/Http/Controllers/Transaction/ShowController.php index 08bb352938..c294ff0c7e 100644 --- a/app/Http/Controllers/Transaction/ShowController.php +++ b/app/Http/Controllers/Transaction/ShowController.php @@ -41,8 +41,8 @@ use Symfony\Component\HttpFoundation\ParameterBag; */ class ShowController extends Controller { - private TransactionGroupRepositoryInterface $repository; private ALERepositoryInterface $ALERepository; + private TransactionGroupRepositoryInterface $repository; /** * ShowController constructor. @@ -57,7 +57,7 @@ class ShowController extends Controller $this->repository = app(TransactionGroupRepositoryInterface::class); $this->ALERepository = app(ALERepositoryInterface::class); - app('view')->share('title', (string) trans('firefly.transactions')); + app('view')->share('title', (string)trans('firefly.transactions')); app('view')->share('mainTitleIcon', 'fa-exchange'); return $next($request); @@ -66,7 +66,7 @@ class ShowController extends Controller } /** - * @param TransactionGroup $transactionGroup + * @param TransactionGroup $transactionGroup * * @return JsonResponse */ @@ -76,8 +76,8 @@ class ShowController extends Controller } /** - * @param Request $request - * @param TransactionGroup $transactionGroup + * @param Request $request + * @param TransactionGroup $transactionGroup * * @return Factory|View * @throws FireflyException @@ -92,7 +92,7 @@ class ShowController extends Controller throw new FireflyException('This transaction is broken :(.'); } - $type = (string) trans(sprintf('firefly.%s', $first->transactionType->type)); + $type = (string)trans(sprintf('firefly.%s', $first->transactionType->type)); $title = 1 === $splits ? $first->description : $transactionGroup->title; $subTitle = sprintf('%s: "%s"', $type, $title); @@ -140,7 +140,7 @@ class ShowController extends Controller } /** - * @param array $group + * @param array $group * * @return array */ @@ -175,7 +175,7 @@ class ShowController extends Controller } /** - * @param array $group + * @param array $group * * @return array */ @@ -188,12 +188,14 @@ class ShowController extends Controller 'type' => $transaction['source_type'], 'id' => $transaction['source_id'], 'name' => $transaction['source_name'], - 'iban' => $transaction['source_iban']]; + 'iban' => $transaction['source_iban'], + ]; $accounts['destination'][] = [ 'type' => $transaction['destination_type'], 'id' => $transaction['destination_id'], 'name' => $transaction['destination_name'], - 'iban' => $transaction['destination_iban']]; + 'iban' => $transaction['destination_iban'], + ]; } $accounts['source'] = array_unique($accounts['source'], SORT_REGULAR); diff --git a/app/Http/Controllers/Webhooks/CreateController.php b/app/Http/Controllers/Webhooks/CreateController.php index daa58426f3..4bf123ef0b 100644 --- a/app/Http/Controllers/Webhooks/CreateController.php +++ b/app/Http/Controllers/Webhooks/CreateController.php @@ -45,8 +45,8 @@ class CreateController extends Controller function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-bolt'); app('view')->share('subTitleIcon', 'fa-plus'); - app('view')->share('title', (string) trans('firefly.webhooks')); - app('view')->share('subTitle', (string) trans('firefly.create_new_webhook')); + app('view')->share('title', (string)trans('firefly.webhooks')); + app('view')->share('subTitle', (string)trans('firefly.create_new_webhook')); return $next($request); } diff --git a/app/Http/Controllers/Webhooks/DeleteController.php b/app/Http/Controllers/Webhooks/DeleteController.php index c3c57bfdcb..f97bee9492 100644 --- a/app/Http/Controllers/Webhooks/DeleteController.php +++ b/app/Http/Controllers/Webhooks/DeleteController.php @@ -25,7 +25,6 @@ namespace FireflyIII\Http\Controllers\Webhooks; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Webhook; -use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; @@ -50,8 +49,8 @@ class DeleteController extends Controller function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-bolt'); app('view')->share('subTitleIcon', 'fa-trash'); - app('view')->share('title', (string) trans('firefly.webhooks')); - app('view')->share('subTitle', (string) trans('firefly.delete_webhook')); + app('view')->share('title', (string)trans('firefly.webhooks')); + app('view')->share('subTitle', (string)trans('firefly.delete_webhook')); return $next($request); } @@ -61,13 +60,13 @@ class DeleteController extends Controller /** * Delete account screen. * - * @param Webhook $webhook + * @param Webhook $webhook * * @return Factory|RedirectResponse|Redirector|View */ public function index(Webhook $webhook) { - $subTitle = (string) trans('firefly.delete_webhook', ['title' => $webhook->name]); + $subTitle = (string)trans('firefly.delete_webhook', ['title' => $webhook->name]); $this->rememberPreviousUrl('webhooks.delete.url'); return view('webhooks.delete', compact('webhook', 'subTitle')); diff --git a/app/Http/Controllers/Webhooks/EditController.php b/app/Http/Controllers/Webhooks/EditController.php index f3cf0f80f2..6f630855ca 100644 --- a/app/Http/Controllers/Webhooks/EditController.php +++ b/app/Http/Controllers/Webhooks/EditController.php @@ -24,12 +24,9 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Webhooks; use FireflyIII\Http\Controllers\Controller; -use FireflyIII\Models\Account; use FireflyIII\Models\Webhook; -use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -52,7 +49,7 @@ class EditController extends Controller function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-bolt'); app('view')->share('subTitleIcon', 'fa-pencil'); - app('view')->share('title', (string) trans('firefly.webhooks')); + app('view')->share('title', (string)trans('firefly.webhooks')); return $next($request); } @@ -62,13 +59,13 @@ class EditController extends Controller /** * Delete account screen. * - * @param Webhook $webhook + * @param Webhook $webhook * * @return Factory|RedirectResponse|Redirector|View */ public function index(Webhook $webhook) { - $subTitle = (string) trans('firefly.edit_webhook', ['title' => $webhook->title]); + $subTitle = (string)trans('firefly.edit_webhook', ['title' => $webhook->title]); $this->rememberPreviousUrl('webhooks.delete.url'); return view('webhooks.edit', compact('webhook', 'subTitle')); diff --git a/app/Http/Controllers/Webhooks/IndexController.php b/app/Http/Controllers/Webhooks/IndexController.php index 801201ba7f..30c1c414b5 100644 --- a/app/Http/Controllers/Webhooks/IndexController.php +++ b/app/Http/Controllers/Webhooks/IndexController.php @@ -46,16 +46,17 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-bolt'); - app('view')->share('title', (string) trans('firefly.webhooks')); + app('view')->share('title', (string)trans('firefly.webhooks')); return $next($request); } ); } + /** * Show debug info. * - * @param Request $request + * @param Request $request * * @return Factory|View * @throws FireflyException diff --git a/app/Http/Controllers/Webhooks/ShowController.php b/app/Http/Controllers/Webhooks/ShowController.php index 344132dc69..236461d339 100644 --- a/app/Http/Controllers/Webhooks/ShowController.php +++ b/app/Http/Controllers/Webhooks/ShowController.php @@ -24,12 +24,9 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Webhooks; use FireflyIII\Http\Controllers\Controller; -use FireflyIII\Models\Account; use FireflyIII\Models\Webhook; -use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -52,7 +49,7 @@ class ShowController extends Controller function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-bolt'); app('view')->share('subTitleIcon', 'fa-bolt'); - app('view')->share('title', (string) trans('firefly.webhooks')); + app('view')->share('title', (string)trans('firefly.webhooks')); return $next($request); } @@ -62,13 +59,13 @@ class ShowController extends Controller /** * Delete account screen. * - * @param Webhook $webhook + * @param Webhook $webhook * * @return Factory|RedirectResponse|Redirector|View */ public function index(Webhook $webhook) { - $subTitle = (string) trans('firefly.show_webhook', ['title' => $webhook->title]); + $subTitle = (string)trans('firefly.show_webhook', ['title' => $webhook->title]); return view('webhooks.show', compact('webhook', 'subTitle')); } diff --git a/app/Http/Middleware/AcceptHeaders.php b/app/Http/Middleware/AcceptHeaders.php index 75c6eeb45e..ffbd0f77ba 100644 --- a/app/Http/Middleware/AcceptHeaders.php +++ b/app/Http/Middleware/AcceptHeaders.php @@ -27,7 +27,6 @@ namespace FireflyIII\Http\Middleware; use FireflyIII\Exceptions\BadHttpHeaderException; use Illuminate\Http\Request; use Illuminate\Http\Response; -use Log; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; /** @@ -38,8 +37,8 @@ class AcceptHeaders /** * Handle the incoming requests. * - * @param Request $request - * @param callable $next + * @param Request $request + * @param callable $next * @return Response * @throws BadHttpHeaderException */ @@ -50,7 +49,7 @@ class AcceptHeaders if ('GET' === $method && !$request->accepts(['application/json', 'application/vdn.api+json'])) { throw new BadHttpHeaderException('Your request must accept either application/json or application/vdn.api+json.'); } - $allowed = ['application/x-www-form-urlencoded','application/json']; + $allowed = ['application/x-www-form-urlencoded', 'application/json']; $submitted = (string)$request->header('Content-Type'); if (('POST' === $method || 'PUT' === $method) && !in_array($submitted, $allowed, true)) { $error = new BadHttpHeaderException(sprintf('Content-Type cannot be "%s"', $submitted)); diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 236ac192c8..1507af86b6 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -47,7 +47,7 @@ class Authenticate /** * Create a new middleware instance. * - * @param Auth $auth + * @param Auth $auth * * @return void */ @@ -59,9 +59,9 @@ class Authenticate /** * Handle an incoming request. * - * @param Request $request - * @param Closure $next - * @param string[] ...$guards + * @param Request $request + * @param Closure $next + * @param string[] ...$guards * * @return mixed * @@ -78,8 +78,8 @@ class Authenticate /** * Determine if the user is logged in to any of the given guards. * - * @param mixed $request - * @param array $guards + * @param mixed $request + * @param array $guards * * @return mixed * @throws FireflyException @@ -94,10 +94,10 @@ class Authenticate // do an extra check on user object. /** @var User $user */ $user = $this->auth->authenticate(); - if (1 === (int) $user->blocked) { - $message = (string) trans('firefly.block_account_logout'); + if (1 === (int)$user->blocked) { + $message = (string)trans('firefly.block_account_logout'); if ('email_changed' === $user->blocked_code) { - $message = (string) trans('firefly.email_changed_logout'); + $message = (string)trans('firefly.email_changed_logout'); } app('session')->flash('logoutMessage', $message); $this->auth->logout(); diff --git a/app/Http/Middleware/Binder.php b/app/Http/Middleware/Binder.php index fb5255a15d..7f8287486c 100644 --- a/app/Http/Middleware/Binder.php +++ b/app/Http/Middleware/Binder.php @@ -1,4 +1,5 @@ getFresh('db_version', 1)->data; + $configVersion = (int)config('firefly.db_version'); + $dbVersion = (int)app('fireflyconfig')->getFresh('db_version', 1)->data; if ($configVersion > $dbVersion) { app('log')->warning( sprintf( @@ -174,8 +174,8 @@ class Installer private function oldVersion(): bool { // version compare thing. - $configVersion = (string) config('firefly.version'); - $dbVersion = (string) app('fireflyconfig')->getFresh('ff3_version', '1.0')->data; + $configVersion = (string)config('firefly.version'); + $dbVersion = (string)app('fireflyconfig')->getFresh('ff3_version', '1.0')->data; if (1 === version_compare($configVersion, $dbVersion)) { app('log')->warning( sprintf( diff --git a/app/Http/Middleware/InterestingMessage.php b/app/Http/Middleware/InterestingMessage.php index 88759d928f..f3e264bda7 100644 --- a/app/Http/Middleware/InterestingMessage.php +++ b/app/Http/Middleware/InterestingMessage.php @@ -40,8 +40,8 @@ class InterestingMessage /** * Flashes the user an interesting message if the URL parameters warrant it. * - * @param Request $request - * @param Closure $next + * @param Request $request + * @param Closure $next * * @return mixed * @@ -82,7 +82,7 @@ class InterestingMessage } /** - * @param Request $request + * @param Request $request * * @return bool */ @@ -96,7 +96,7 @@ class InterestingMessage } /** - * @param Request $request + * @param Request $request */ private function handleGroupMessage(Request $request): void { @@ -106,7 +106,7 @@ class InterestingMessage // send message about newly created transaction group. /** @var TransactionGroup $group */ - $group = auth()->user()->transactionGroups()->with(['transactionJournals', 'transactionJournals.transactionType'])->find((int) $transactionGroupId); + $group = auth()->user()->transactionGroups()->with(['transactionJournals', 'transactionJournals.transactionType'])->find((int)$transactionGroupId); if (null === $group) { return; @@ -122,22 +122,22 @@ class InterestingMessage $title = $count > 1 ? $group->title : $journal->description; if ('created' === $message) { session()->flash('success_url', route('transactions.show', [$transactionGroupId])); - session()->flash('success', (string) trans('firefly.stored_journal', ['description' => $title])); + session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $title])); } if ('updated' === $message) { $type = strtolower($journal->transactionType->type); session()->flash('success_url', route('transactions.show', [$transactionGroupId])); - session()->flash('success', (string) trans(sprintf('firefly.updated_%s', $type), ['description' => $title])); + session()->flash('success', (string)trans(sprintf('firefly.updated_%s', $type), ['description' => $title])); } if ('no_change' === $message) { $type = strtolower($journal->transactionType->type); session()->flash('warning_url', route('transactions.show', [$transactionGroupId])); - session()->flash('warning', (string) trans(sprintf('firefly.no_changes_%s', $type), ['description' => $title])); + session()->flash('warning', (string)trans(sprintf('firefly.no_changes_%s', $type), ['description' => $title])); } } /** - * @param Request $request + * @param Request $request * * @return bool */ @@ -151,7 +151,7 @@ class InterestingMessage } /** - * @param Request $request + * @param Request $request */ private function handleAccountMessage(Request $request): void { @@ -166,18 +166,18 @@ class InterestingMessage return; } if ('deleted' === $message) { - session()->flash('success', (string) trans('firefly.account_deleted', ['name' => $account->name])); + session()->flash('success', (string)trans('firefly.account_deleted', ['name' => $account->name])); } if ('created' === $message) { - session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name])); + session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name])); } if ('updated' === $message) { - session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name])); + session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name])); } } /** - * @param Request $request + * @param Request $request * * @return bool */ @@ -189,22 +189,9 @@ class InterestingMessage return null !== $billId && null !== $message; } - /** - * @param Request $request - * - * @return bool - */ - private function webhookMessage(Request $request): bool - { - // get parameters from request. - $billId = $request->get('webhook_id'); - $message = $request->get('message'); - - return null !== $billId && null !== $message; - } /** - * @param Request $request + * @param Request $request */ private function handleBillMessage(Request $request): void { @@ -219,21 +206,35 @@ class InterestingMessage return; } if ('deleted' === $message) { - session()->flash('success', (string) trans('firefly.deleted_bill', ['name' => $bill->name])); + session()->flash('success', (string)trans('firefly.deleted_bill', ['name' => $bill->name])); } if ('created' === $message) { - session()->flash('success', (string) trans('firefly.stored_new_bill', ['name' => $bill->name])); + session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name])); } } /** - * @param Request $request + * @param Request $request + * + * @return bool + */ + private function webhookMessage(Request $request): bool + { + // get parameters from request. + $billId = $request->get('webhook_id'); + $message = $request->get('message'); + + return null !== $billId && null !== $message; + } + + /** + * @param Request $request */ private function handleWebhookMessage(Request $request): void { // get parameters from request. - $webhookId = $request->get('webhook_id'); - $message = $request->get('message'); + $webhookId = $request->get('webhook_id'); + $message = $request->get('message'); /** @var Webhook $webhook */ $webhook = auth()->user()->webhooks()->withTrashed()->find($webhookId); @@ -242,13 +243,13 @@ class InterestingMessage return; } if ('deleted' === $message) { - session()->flash('success', (string) trans('firefly.deleted_webhook', ['title' => $webhook->title])); + session()->flash('success', (string)trans('firefly.deleted_webhook', ['title' => $webhook->title])); } if ('updated' === $message) { - session()->flash('success', (string) trans('firefly.updated_webhook', ['title' => $webhook->title])); + session()->flash('success', (string)trans('firefly.updated_webhook', ['title' => $webhook->title])); } if ('created' === $message) { - session()->flash('success', (string) trans('firefly.stored_new_webhook', ['title' => $webhook->title])); + session()->flash('success', (string)trans('firefly.stored_new_webhook', ['title' => $webhook->title])); } } } diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php index 8386c3fe93..32d8b04c98 100644 --- a/app/Http/Middleware/IsAdmin.php +++ b/app/Http/Middleware/IsAdmin.php @@ -1,4 +1,5 @@ hasRole($user, 'demo')) { Log::info('User is a demo user.'); - $request->session()->flash('info', (string) trans('firefly.not_available_demo_user')); + $request->session()->flash('info', (string)trans('firefly.not_available_demo_user')); $current = $request->url(); $previous = $request->session()->previousUrl(); if ($current !== $previous) { diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 8d1313f7a8..3db1a776a9 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -1,4 +1,5 @@ getDefaultCurrency(); // also format for moment JS: - $madMomentJS = (string) trans('config.month_and_day_moment_js', [], $locale); + $madMomentJS = (string)trans('config.month_and_day_moment_js', [], $locale); app('view')->share('madMomentJS', $madMomentJS); app('view')->share('monthAndDayFormat', $monthAndDayFormat); diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 9b17c7f49a..d48dbcb893 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -1,4 +1,5 @@ route(); $customUrl = ''; - $authGuard = (string) config('firefly.authentication_guard'); - $logoutUrl = (string) config('firefly.custom_logout_url'); + $authGuard = (string)config('firefly.authentication_guard'); + $logoutUrl = (string)config('firefly.custom_logout_url'); if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) { $customUrl = $logoutUrl; } @@ -115,8 +115,8 @@ class SecureHeaders */ private function getTrackingScriptSource(): string { - if ('' !== (string) config('firefly.tracker_site_id') && '' !== (string) config('firefly.tracker_url')) { - return (string) config('firefly.tracker_url'); + if ('' !== (string)config('firefly.tracker_site_id') && '' !== (string)config('firefly.tracker_url')) { + return (string)config('firefly.tracker_url'); } return ''; diff --git a/app/Http/Middleware/StartFireflySession.php b/app/Http/Middleware/StartFireflySession.php index 20d1d7d4e6..2ae301774c 100644 --- a/app/Http/Middleware/StartFireflySession.php +++ b/app/Http/Middleware/StartFireflySession.php @@ -1,4 +1,5 @@ proxies = (string) config('firefly.trusted_proxies'); + $this->proxies = (string)config('firefly.trusted_proxies'); } } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 195b27daaa..8f53afdccd 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -1,4 +1,5 @@ 'numeric|nullable|max:1000000000', 'currency_id' => 'exists:transaction_currencies,id', 'account_number' => 'between:1,255|uniqueAccountNumberForUser|nullable', - 'account_role' => 'in:' . $accountRoles, + 'account_role' => 'in:'.$accountRoles, 'active' => 'boolean', - 'cc_type' => 'in:' . $ccPaymentTypes, + 'cc_type' => 'in:'.$ccPaymentTypes, 'amount_currency_id_opening_balance' => 'exists:transaction_currencies,id', 'amount_currency_id_virtual_balance' => 'exists:transaction_currencies,id', - 'what' => 'in:' . $types, + 'what' => 'in:'.$types, 'interest_period' => 'in:daily,monthly,yearly', ]; $rules = Location::requestRules($rules); @@ -122,7 +123,7 @@ class AccountFormRequest extends FormRequest if (null !== $account) { // add rules: $rules['id'] = 'belongsToUser:accounts'; - $rules['name'] = 'required|min:1|uniqueAccountForUser:' . $account->id; + $rules['name'] = 'required|min:1|uniqueAccountForUser:'.$account->id; $rules['iban'] = ['iban', 'nullable', new UniqueIban($account, $account->accountType->type)]; } diff --git a/app/Http/Requests/AttachmentFormRequest.php b/app/Http/Requests/AttachmentFormRequest.php index 11dfbcf69f..c02d58d1ca 100644 --- a/app/Http/Requests/AttachmentFormRequest.php +++ b/app/Http/Requests/AttachmentFormRequest.php @@ -1,4 +1,5 @@ route()->parameter('budget'); if (null !== $budget) { - $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . $budget->id; + $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,'.$budget->id; } return [ @@ -85,7 +86,7 @@ class BudgetFormUpdateRequest extends FormRequest /** * Configure the validator instance with special rules for after the basic validation rules. * - * @param Validator $validator + * @param Validator $validator * * @return void */ diff --git a/app/Http/Requests/BudgetIncomeRequest.php b/app/Http/Requests/BudgetIncomeRequest.php index aa99bf336a..bc500c7e8b 100644 --- a/app/Http/Requests/BudgetIncomeRequest.php +++ b/app/Http/Requests/BudgetIncomeRequest.php @@ -1,4 +1,5 @@ route()->parameter('category'); if (null !== $category) { - $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . $category->id; + $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,'.$category->id; } // fixed diff --git a/app/Http/Requests/ConfigurationRequest.php b/app/Http/Requests/ConfigurationRequest.php index 41dc970169..14b7267ad0 100644 --- a/app/Http/Requests/ConfigurationRequest.php +++ b/app/Http/Requests/ConfigurationRequest.php @@ -1,4 +1,5 @@ get('link_type'); $parts = explode('_', $linkType); - $return['link_type_id'] = (int) $parts[0]; + $return['link_type_id'] = (int)$parts[0]; $return['transaction_journal_id'] = $this->convertInteger('opposing'); $return['notes'] = $this->convertString('notes'); $return['direction'] = $parts[1]; diff --git a/app/Http/Requests/LinkTypeFormRequest.php b/app/Http/Requests/LinkTypeFormRequest.php index 3df1effbe3..d8864ba15e 100644 --- a/app/Http/Requests/LinkTypeFormRequest.php +++ b/app/Http/Requests/LinkTypeFormRequest.php @@ -1,4 +1,5 @@ 'required|between:1,255|uniqueObjectForUser:recurrences,title', - 'first_date' => 'required|date|after:' . $today->format('Y-m-d'), + 'first_date' => 'required|date|after:'.$today->format('Y-m-d'), 'repetition_type' => ['required', new ValidRecurrenceRepetitionValue(), new ValidRecurrenceRepetitionType(), 'between:1,20'], 'skip' => 'required|numeric|integer|gte:0|lte:31', @@ -235,7 +235,7 @@ class RecurrenceFormRequest extends FormRequest // if ends at date X, set another rule. if ('until_date' === $this->convertString('repetition_end')) { - $rules['repeat_until'] = 'required|date|after:' . $tomorrow->format('Y-m-d'); + $rules['repeat_until'] = 'required|date|after:'.$tomorrow->format('Y-m-d'); } // switch on type to expand rules for source and destination accounts: @@ -263,7 +263,7 @@ class RecurrenceFormRequest extends FormRequest $recurrence = $this->route()->parameter('recurrence'); if ($recurrence instanceof Recurrence) { $rules['id'] = 'required|numeric|exists:recurrences,id'; - $rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,' . $recurrence->id; + $rules['title'] = 'required|between:1,255|uniqueObjectForUser:recurrences,title,'.$recurrence->id; $rules['first_date'] = 'required|date'; } @@ -273,7 +273,7 @@ class RecurrenceFormRequest extends FormRequest /** * Configure the validator instance with special rules for after the basic validation rules. * - * @param Validator $validator + * @param Validator $validator * * @return void */ @@ -290,7 +290,7 @@ class RecurrenceFormRequest extends FormRequest /** * Validates the given account information. Switches on given transaction type. * - * @param Validator $validator + * @param Validator $validator * * @throws FireflyException */ @@ -314,16 +314,16 @@ class RecurrenceFormRequest extends FormRequest default: throw new FireflyException(sprintf('Cannot handle transaction type "%s"', $this->convertString('transaction_type'))); case 'withdrawal': - $sourceId = (int) $data['source_id']; - $destinationId = (int) $data['withdrawal_destination_id']; + $sourceId = (int)$data['source_id']; + $destinationId = (int)$data['withdrawal_destination_id']; break; case 'deposit': - $sourceId = (int) $data['deposit_source_id']; - $destinationId = (int) $data['destination_id']; + $sourceId = (int)$data['deposit_source_id']; + $destinationId = (int)$data['destination_id']; break; case 'transfer': - $sourceId = (int) $data['source_id']; - $destinationId = (int) $data['destination_id']; + $sourceId = (int)$data['source_id']; + $destinationId = (int)$data['destination_id']; break; } // validate source account. @@ -331,7 +331,7 @@ class RecurrenceFormRequest extends FormRequest // do something with result: if (false === $validSource) { - $message = (string) trans('validation.generic_invalid_source'); + $message = (string)trans('validation.generic_invalid_source'); $validator->errors()->add('source_id', $message); $validator->errors()->add('deposit_source_id', $message); @@ -342,7 +342,7 @@ class RecurrenceFormRequest extends FormRequest $validDestination = $accountValidator->validateDestination(['id' => $destinationId,]); // do something with result: if (false === $validDestination) { - $message = (string) trans('validation.generic_invalid_destination'); + $message = (string)trans('validation.generic_invalid_destination'); $validator->errors()->add('destination_id', $message); $validator->errors()->add('withdrawal_destination_id', $message); } diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.php index 3b5274f3cd..2fbea87a78 100644 --- a/app/Http/Requests/ReportFormRequest.php +++ b/app/Http/Requests/ReportFormRequest.php @@ -1,4 +1,5 @@ find((int) $accountId); + $account = $repository->find((int)$accountId); if (null !== $account) { $collection->push($account); } @@ -78,7 +79,7 @@ class ReportFormRequest extends FormRequest $collection = new Collection(); if (is_array($set)) { foreach ($set as $budgetId) { - $budget = $repository->find((int) $budgetId); + $budget = $repository->find((int)$budgetId); if (null !== $budget) { $collection->push($budget); } @@ -101,7 +102,7 @@ class ReportFormRequest extends FormRequest $collection = new Collection(); if (is_array($set)) { foreach ($set as $categoryId) { - $category = $repository->find((int) $categoryId); + $category = $repository->find((int)$categoryId); if (null !== $category) { $collection->push($category); } @@ -124,7 +125,7 @@ class ReportFormRequest extends FormRequest $collection = new Collection(); if (is_array($set)) { foreach ($set as $accountId) { - $account = $repository->find((int) $accountId); + $account = $repository->find((int)$accountId); if (null !== $account) { $collection->push($account); } @@ -145,7 +146,7 @@ class ReportFormRequest extends FormRequest { $date = today(config('app.timezone')); $range = $this->get('daterange'); - $parts = explode(' - ', (string) $range); + $parts = explode(' - ', (string)$range); if (2 === count($parts)) { $string = $parts[1]; // validate as date @@ -179,7 +180,7 @@ class ReportFormRequest extends FormRequest { $date = today(config('app.timezone')); $range = $this->get('daterange'); - $parts = explode(' - ', (string) $range); + $parts = explode(' - ', (string)$range); if (2 === count($parts)) { $string = $parts[0]; // validate as date @@ -223,7 +224,7 @@ class ReportFormRequest extends FormRequest $collection->push($tag); continue; } - $tag = $repository->find((int) $tagTag); + $tag = $repository->find((int)$tagTag); if (null !== $tag) { $collection->push($tag); } diff --git a/app/Http/Requests/RuleGroupFormRequest.php b/app/Http/Requests/RuleGroupFormRequest.php index 89b37bf34f..3b23ecc0f7 100644 --- a/app/Http/Requests/RuleGroupFormRequest.php +++ b/app/Http/Requests/RuleGroupFormRequest.php @@ -1,4 +1,5 @@ route()->parameter('ruleGroup'); if (null !== $ruleGroup) { - $titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id; + $titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,'.$ruleGroup->id; } return [ diff --git a/app/Http/Requests/SelectTransactionsRequest.php b/app/Http/Requests/SelectTransactionsRequest.php index e52c1d3cfd..c7a84cd23a 100644 --- a/app/Http/Requests/SelectTransactionsRequest.php +++ b/app/Http/Requests/SelectTransactionsRequest.php @@ -1,4 +1,5 @@ addDay()->format('Y-m-d'); return [ - 'start' => 'required|date|after:' . $first, - 'end' => 'required|date|before:' . $today, + 'start' => 'required|date|after:'.$first, + 'end' => 'required|date|before:'.$today, 'accounts' => 'required', 'accounts.*' => 'required|exists:accounts,id|belongsToUser:accounts', ]; diff --git a/app/Http/Requests/TagFormRequest.php b/app/Http/Requests/TagFormRequest.php index f63754c9a9..25adcd9450 100644 --- a/app/Http/Requests/TagFormRequest.php +++ b/app/Http/Requests/TagFormRequest.php @@ -1,4 +1,5 @@ id; + $tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,'.$tag->id; } $rules = [ diff --git a/app/Http/Requests/TestRuleFormRequest.php b/app/Http/Requests/TestRuleFormRequest.php index e80042afc9..3c6d7bdf37 100644 --- a/app/Http/Requests/TestRuleFormRequest.php +++ b/app/Http/Requests/TestRuleFormRequest.php @@ -1,4 +1,5 @@ getTriggers(); return [ - 'rule-trigger.*' => 'required|min:1|in:' . implode(',', $validTriggers), + 'rule-trigger.*' => 'required|min:1|in:'.implode(',', $validTriggers), 'rule-trigger-value.*' => 'required|min:1|ruleTriggerValue', ]; } diff --git a/app/Http/Requests/TokenFormRequest.php b/app/Http/Requests/TokenFormRequest.php index e7c45ad2cc..8245fafa37 100644 --- a/app/Http/Requests/TokenFormRequest.php +++ b/app/Http/Requests/TokenFormRequest.php @@ -1,4 +1,5 @@ findBudgetLimit($autoBudget->budget, $start, $end); - if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_RESET === (int) $autoBudget->auto_budget_type) { + if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_RESET === (int)$autoBudget->auto_budget_type) { // that's easy: create one. // do nothing else. $this->createBudgetLimit($autoBudget, $start, $end); @@ -142,7 +142,7 @@ class CreateAutoBudgetLimits implements ShouldQueue return; } - if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_ROLLOVER === (int) $autoBudget->auto_budget_type) { + if (null === $budgetLimit && AutoBudget::AUTO_BUDGET_ROLLOVER === (int)$autoBudget->auto_budget_type) { // budget limit exists already, $this->createRollover($autoBudget); Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id)); @@ -153,7 +153,7 @@ class CreateAutoBudgetLimits implements ShouldQueue } /** - * @param AutoBudget $autoBudget + * @param AutoBudget $autoBudget * * @return bool * @throws FireflyException @@ -190,9 +190,9 @@ class CreateAutoBudgetLimits implements ShouldQueue } /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end + * @param Budget $budget + * @param Carbon $start + * @param Carbon $end * * @return BudgetLimit|null */ @@ -214,10 +214,10 @@ class CreateAutoBudgetLimits implements ShouldQueue } /** - * @param AutoBudget $autoBudget - * @param Carbon $start - * @param Carbon $end - * @param string|null $amount + * @param AutoBudget $autoBudget + * @param Carbon $start + * @param Carbon $end + * @param string|null $amount */ private function createBudgetLimit(AutoBudget $autoBudget, Carbon $start, Carbon $end, ?string $amount = null) { @@ -239,7 +239,7 @@ class CreateAutoBudgetLimits implements ShouldQueue } /** - * @param AutoBudget $autoBudget + * @param AutoBudget $autoBudget * * @throws FireflyException */ @@ -280,7 +280,7 @@ class CreateAutoBudgetLimits implements ShouldQueue $repository = app(OperationsRepositoryInterface::class); $repository->setUser($autoBudget->budget->user); $spent = $repository->sumExpenses($previousStart, $previousEnd, null, new Collection([$autoBudget->budget]), $autoBudget->transactionCurrency); - $currencyId = (int) $autoBudget->transaction_currency_id; + $currencyId = (int)$autoBudget->transaction_currency_id; $spentAmount = $spent[$currencyId]['sum'] ?? '0'; Log::debug(sprintf('Spent in previous budget period (%s-%s) is %s', $previousStart->format('Y-m-d'), $previousEnd->format('Y-m-d'), $spentAmount)); @@ -304,7 +304,7 @@ class CreateAutoBudgetLimits implements ShouldQueue } /** - * @param Carbon $date + * @param Carbon $date */ public function setDate(Carbon $date): void { diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php index 04563b115a..8d7baff791 100644 --- a/app/Jobs/CreateRecurringTransactions.php +++ b/app/Jobs/CreateRecurringTransactions.php @@ -61,10 +61,10 @@ class CreateRecurringTransactions implements ShouldQueue private Carbon $date; private bool $force; private TransactionGroupRepositoryInterface $groupRepository; - private JournalRepositoryInterface $journalRepository; - private RecurringRepositoryInterface $repository; - private Collection $recurrences; private Collection $groups; + private JournalRepositoryInterface $journalRepository; + private Collection $recurrences; + private RecurringRepositoryInterface $repository; /** * Create a new job instance. @@ -97,6 +97,14 @@ class CreateRecurringTransactions implements ShouldQueue Log::debug(sprintf('Created new CreateRecurringTransactions("%s")', $this->date->format('Y-m-d'))); } + /** + * @return Collection + */ + public function getGroups(): Collection + { + return $this->groups; + } + /** * Execute the job. */ @@ -520,12 +528,4 @@ class CreateRecurringTransactions implements ShouldQueue { $this->recurrences = $recurrences; } - - /** - * @return Collection - */ - public function getGroups(): Collection - { - return $this->groups; - } } diff --git a/app/Jobs/DownloadExchangeRates.php b/app/Jobs/DownloadExchangeRates.php index 98e8f74260..3e47c4e045 100644 --- a/app/Jobs/DownloadExchangeRates.php +++ b/app/Jobs/DownloadExchangeRates.php @@ -47,9 +47,9 @@ class DownloadExchangeRates implements ShouldQueue use Queueable; use SerializesModels; + private array $active; private Carbon $date; private CurrencyRepositoryInterface $repository; - private array $active; private Collection $users; /** @@ -57,7 +57,7 @@ class DownloadExchangeRates implements ShouldQueue * * @codeCoverageIgnore * - * @param Carbon|null $date + * @param Carbon|null $date */ public function __construct(?Carbon $date) { @@ -92,23 +92,13 @@ class DownloadExchangeRates implements ShouldQueue } /** - * @param Carbon $date - */ - public function setDate(Carbon $date): void - { - $newDate = clone $date; - $newDate->startOfDay(); - $this->date = $newDate; - } - - /** - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency * @return void */ private function downloadRates(TransactionCurrency $currency): void { Log::debug(sprintf('Now downloading new exchange rates for currency %s.', $currency->code)); - $base = sprintf('%s/%s/%s', (string) config('cer.url'), $this->date->year, $this->date->isoWeek); + $base = sprintf('%s/%s/%s', (string)config('cer.url'), $this->date->year, $this->date->isoWeek); $client = new Client(); $url = sprintf('%s/%s.json', $base, $currency->code); $res = $client->get($url); @@ -117,7 +107,7 @@ class DownloadExchangeRates implements ShouldQueue app('log')->warning(sprintf('Trying to grab "%s" resulted in status code %d.', $url, $statusCode)); return; } - $body = (string) $res->getBody(); + $body = (string)$res->getBody(); $json = json_decode($body, true); if (false === $json || null === $json) { app('log')->warning(sprintf('Trying to grab "%s" resulted in bad JSON.', $url)); @@ -128,8 +118,8 @@ class DownloadExchangeRates implements ShouldQueue } /** - * @param TransactionCurrency $currency - * @param array $rates + * @param TransactionCurrency $currency + * @param array $rates * @return void */ private function saveRates(TransactionCurrency $currency, Carbon $date, array $rates): void @@ -146,7 +136,7 @@ class DownloadExchangeRates implements ShouldQueue } /** - * @param string $code + * @param string $code * @return TransactionCurrency|null */ private function getCurrency(string $code): ?TransactionCurrency @@ -185,4 +175,14 @@ class DownloadExchangeRates implements ShouldQueue } } } + + /** + * @param Carbon $date + */ + public function setDate(Carbon $date): void + { + $newDate = clone $date; + $newDate->startOfDay(); + $this->date = $newDate; + } } diff --git a/app/Jobs/Job.php b/app/Jobs/Job.php index 7562dbfa3c..05b4952226 100644 --- a/app/Jobs/Job.php +++ b/app/Jobs/Job.php @@ -1,4 +1,5 @@ exception; $args['loggedIn'] = $this->userData['id'] > 0; $args['user'] = $this->userData; @@ -83,12 +84,12 @@ class MailError extends Job implements ShouldQueue $args, function (Message $message) use ($email) { if ('mail@example.com' !== $email) { - $message->to($email, $email)->subject((string) trans('email.error_subject')); + $message->to($email, $email)->subject((string)trans('email.error_subject')); } } ); } catch (Exception $e) { - Log::error('Exception when mailing: ' . $e->getMessage()); + Log::error('Exception when mailing: '.$e->getMessage()); } } } diff --git a/app/Jobs/SendWebhookMessage.php b/app/Jobs/SendWebhookMessage.php index d628f1882f..05efaeb8a2 100644 --- a/app/Jobs/SendWebhookMessage.php +++ b/app/Jobs/SendWebhookMessage.php @@ -48,7 +48,7 @@ class SendWebhookMessage implements ShouldQueue /** * Create a new job instance. * - * @param WebhookMessage $message + * @param WebhookMessage $message */ public function __construct(WebhookMessage $message) { diff --git a/app/Jobs/WarnAboutBills.php b/app/Jobs/WarnAboutBills.php index 353cdebc05..647e3d0372 100644 --- a/app/Jobs/WarnAboutBills.php +++ b/app/Jobs/WarnAboutBills.php @@ -52,7 +52,7 @@ class WarnAboutBills implements ShouldQueue * * @codeCoverageIgnore * - * @param Carbon|null $date + * @param Carbon|null $date */ public function __construct(?Carbon $date) { @@ -97,7 +97,7 @@ class WarnAboutBills implements ShouldQueue } /** - * @param Bill $bill + * @param Bill $bill * @return bool */ private function hasDateFields(Bill $bill): bool @@ -114,8 +114,8 @@ class WarnAboutBills implements ShouldQueue } /** - * @param Bill $bill - * @param string $field + * @param Bill $bill + * @param string $field * @return bool */ private function needsWarning(Bill $bill, string $field): bool @@ -133,8 +133,8 @@ class WarnAboutBills implements ShouldQueue } /** - * @param Bill $bill - * @param string $field + * @param Bill $bill + * @param string $field * @return int */ private function getDiff(Bill $bill, string $field): int @@ -145,8 +145,8 @@ class WarnAboutBills implements ShouldQueue } /** - * @param Bill $bill - * @param string $field + * @param Bill $bill + * @param string $field * @return void */ private function sendWarning(Bill $bill, string $field): void @@ -157,7 +157,7 @@ class WarnAboutBills implements ShouldQueue } /** - * @param Carbon $date + * @param Carbon $date */ public function setDate(Carbon $date): void { @@ -167,7 +167,7 @@ class WarnAboutBills implements ShouldQueue } /** - * @param bool $force + * @param bool $force */ public function setForce(bool $force): void { diff --git a/app/Mail/AccessTokenCreatedMail.php b/app/Mail/AccessTokenCreatedMail.php index bf7b4a4e10..40dbbe2c27 100644 --- a/app/Mail/AccessTokenCreatedMail.php +++ b/app/Mail/AccessTokenCreatedMail.php @@ -53,6 +53,6 @@ class AccessTokenCreatedMail extends Mailable { return $this ->markdown('emails.token-created') - ->subject((string) trans('email.access_token_created_subject')); + ->subject((string)trans('email.access_token_created_subject')); } } diff --git a/app/Mail/AdminTestMail.php b/app/Mail/AdminTestMail.php index 400861d502..bcef6cda6e 100644 --- a/app/Mail/AdminTestMail.php +++ b/app/Mail/AdminTestMail.php @@ -1,4 +1,5 @@ markdown('emails.admin-test') - ->subject((string) trans('email.admin_test_subject')); + ->subject((string)trans('email.admin_test_subject')); } } diff --git a/app/Mail/BillWarningMail.php b/app/Mail/BillWarningMail.php index 64623e5560..308d86c706 100644 --- a/app/Mail/BillWarningMail.php +++ b/app/Mail/BillWarningMail.php @@ -41,9 +41,9 @@ class BillWarningMail extends Mailable /** * ConfirmEmailChangeMail constructor. * - * @param Bill $bill - * @param string $field - * @param int $diff + * @param Bill $bill + * @param string $field + * @param int $diff */ public function __construct(Bill $bill, string $field, int $diff) { @@ -59,9 +59,9 @@ class BillWarningMail extends Mailable */ public function build(): self { - $subject = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $subject = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); if (0 === $this->diff) { - $subject = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $subject = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); } return $this diff --git a/app/Mail/ConfirmEmailChangeMail.php b/app/Mail/ConfirmEmailChangeMail.php index 6bf15b5f1f..7ad5fe34ac 100644 --- a/app/Mail/ConfirmEmailChangeMail.php +++ b/app/Mail/ConfirmEmailChangeMail.php @@ -1,4 +1,5 @@ view('emails.confirm-email-change-html') //->text('emails.confirm-email-change-text') ->markdown('emails.confirm-email-change') - ->subject((string) trans('email.email_change_subject')); + ->subject((string)trans('email.email_change_subject')); } } diff --git a/app/Mail/InvitationMail.php b/app/Mail/InvitationMail.php index cd1995029b..65490d9b0f 100644 --- a/app/Mail/InvitationMail.php +++ b/app/Mail/InvitationMail.php @@ -33,22 +33,22 @@ class InvitationMail extends Mailable use Queueable; use SerializesModels; - public string $invitee; public string $admin; - public string $url; public string $host; + public string $invitee; + public string $url; /** * OAuthTokenCreatedMail constructor. * - * @param string $ipAddress + * @param string $ipAddress */ public function __construct(string $invitee, string $admin, string $url) { $this->invitee = $invitee; - $this->admin = $admin; - $this->url = $url; - $this->host = parse_url($url, PHP_URL_HOST); + $this->admin = $admin; + $this->url = $url; + $this->host = parse_url($url, PHP_URL_HOST); } /** @@ -60,6 +60,6 @@ class InvitationMail extends Mailable { return $this ->markdown('emails.invitation') - ->subject((string) trans('email.invite_user_subject')); + ->subject((string)trans('email.invite_user_subject')); } } diff --git a/app/Mail/NewIPAddressWarningMail.php b/app/Mail/NewIPAddressWarningMail.php index 02297032e0..80393791c0 100644 --- a/app/Mail/NewIPAddressWarningMail.php +++ b/app/Mail/NewIPAddressWarningMail.php @@ -44,7 +44,7 @@ class NewIPAddressWarningMail extends Mailable /** * OAuthTokenCreatedMail constructor. * - * @param string $ipAddress + * @param string $ipAddress */ public function __construct(string $ipAddress) { @@ -58,7 +58,7 @@ class NewIPAddressWarningMail extends Mailable */ public function build(): self { - $this->time = now(config('app.timezone'))->isoFormat((string) trans('config.date_time_js')); + $this->time = now(config('app.timezone'))->isoFormat((string)trans('config.date_time_js')); $this->host = ''; try { $hostName = gethostbyaddr($this->ipAddress); @@ -71,6 +71,6 @@ class NewIPAddressWarningMail extends Mailable return $this ->markdown('emails.new-ip') - ->subject((string) trans('email.login_from_new_ip')); + ->subject((string)trans('email.login_from_new_ip')); } } diff --git a/app/Mail/OAuthTokenCreatedMail.php b/app/Mail/OAuthTokenCreatedMail.php index 9a6bdef155..69bc8cf471 100644 --- a/app/Mail/OAuthTokenCreatedMail.php +++ b/app/Mail/OAuthTokenCreatedMail.php @@ -43,7 +43,7 @@ class OAuthTokenCreatedMail extends Mailable /** * OAuthTokenCreatedMail constructor. * - * @param Client $client + * @param Client $client */ public function __construct(Client $client) { @@ -59,6 +59,6 @@ class OAuthTokenCreatedMail extends Mailable { return $this ->markdown('emails.oauth-client-created') - ->subject((string) trans('email.oauth_created_subject')); + ->subject((string)trans('email.oauth_created_subject')); } } diff --git a/app/Mail/RegisteredUser.php b/app/Mail/RegisteredUser.php index 81a73704e4..b68e2449b7 100644 --- a/app/Mail/RegisteredUser.php +++ b/app/Mail/RegisteredUser.php @@ -44,7 +44,7 @@ class RegisteredUser extends Mailable /** * Create a new message instance. * - * @param string $address + * @param string $address */ public function __construct(string $address) { @@ -60,6 +60,6 @@ class RegisteredUser extends Mailable { return $this ->markdown('emails.registered') - ->subject((string) trans('email.registered_subject')); + ->subject((string)trans('email.registered_subject')); } } diff --git a/app/Mail/ReportNewJournalsMail.php b/app/Mail/ReportNewJournalsMail.php index c69ee517be..2b0154ce8d 100644 --- a/app/Mail/ReportNewJournalsMail.php +++ b/app/Mail/ReportNewJournalsMail.php @@ -1,4 +1,5 @@ markdown('emails.report-new-journals') - ->subject((string) trans_choice('email.new_journals_subject', $this->groups->count())); + ->subject((string)trans_choice('email.new_journals_subject', $this->groups->count())); } private function transform(): void diff --git a/app/Mail/RequestedNewPassword.php b/app/Mail/RequestedNewPassword.php index d7dc317fa7..865280d00d 100644 --- a/app/Mail/RequestedNewPassword.php +++ b/app/Mail/RequestedNewPassword.php @@ -43,7 +43,7 @@ class RequestedNewPassword extends Mailable /** * RequestedNewPassword constructor. * - * @param string $url + * @param string $url */ public function __construct(string $url) { @@ -59,6 +59,6 @@ class RequestedNewPassword extends Mailable { return $this ->markdown('emails.password') - ->subject((string) trans('email.reset_pw_subject')); + ->subject((string)trans('email.reset_pw_subject')); } } diff --git a/app/Mail/UndoEmailChangeMail.php b/app/Mail/UndoEmailChangeMail.php index f499314d2b..df4a5df620 100644 --- a/app/Mail/UndoEmailChangeMail.php +++ b/app/Mail/UndoEmailChangeMail.php @@ -1,4 +1,5 @@ markdown('emails.undo-email-change') - ->subject((string) trans('email.email_change_subject')); + ->subject((string)trans('email.email_change_subject')); } } diff --git a/app/Models/Account.php b/app/Models/Account.php index 14588b6f4e..8375ef8737 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1,4 +1,5 @@ check()) { - $accountId = (int) $value; + $accountId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Account $account */ @@ -150,6 +151,15 @@ class Account extends Model throw new NotFoundHttpException(); } + /** + * @return BelongsTo + * @codeCoverageIgnore + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @return BelongsTo * @codeCoverageIgnore @@ -245,8 +255,8 @@ class Account extends Model /** * @codeCoverageIgnore * - * @param EloquentBuilder $query - * @param array $types + * @param EloquentBuilder $query + * @param array $types */ public function scopeAccountTypeIn(EloquentBuilder $query, array $types): void { @@ -260,13 +270,13 @@ class Account extends Model /** * @codeCoverageIgnore * - * @param mixed $value + * @param mixed $value * * @codeCoverageIgnore */ public function setVirtualBalanceAttribute($value): void { - $value = (string) $value; + $value = (string)$value; if ('' === $value) { $value = null; } @@ -281,13 +291,4 @@ class Account extends Model { return $this->hasMany(Transaction::class); } - - /** - * @return BelongsTo - * @codeCoverageIgnore - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 4f41f9aaf9..1047fa1a72 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -1,4 +1,5 @@ check()) { - $attachmentId = (int) $value; + $attachmentId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Attachment $attachment */ @@ -123,6 +124,15 @@ class Attachment extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * Get all of the owning attachable models. * @@ -143,7 +153,7 @@ class Attachment extends Model */ public function fileName(): string { - return sprintf('at-%s.data', (string) $this->id); + return sprintf('at-%s.data', (string)$this->id); } /** @@ -154,13 +164,4 @@ class Attachment extends Model { return $this->morphMany(Note::class, 'noteable'); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/AuditLogEntry.php b/app/Models/AuditLogEntry.php index 2df014d179..86f2a94283 100644 --- a/app/Models/AuditLogEntry.php +++ b/app/Models/AuditLogEntry.php @@ -24,22 +24,47 @@ declare(strict_types=1); namespace FireflyIII\Models; +use Eloquent; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Carbon; /** * Class AuditLogEntry * - * @property-read Model|\Eloquent $auditable - * @property-read Model|\Eloquent $changer - * @method static \Illuminate\Database\Eloquent\Builder|AuditLogEntry newModelQuery() - * @method static \Illuminate\Database\Eloquent\Builder|AuditLogEntry newQuery() + * @property-read Model|Eloquent $auditable + * @property-read Model|Eloquent $changer + * @method static Builder|AuditLogEntry newModelQuery() + * @method static Builder|AuditLogEntry newQuery() * @method static \Illuminate\Database\Query\Builder|AuditLogEntry onlyTrashed() - * @method static \Illuminate\Database\Eloquent\Builder|AuditLogEntry query() + * @method static Builder|AuditLogEntry query() * @method static \Illuminate\Database\Query\Builder|AuditLogEntry withTrashed() * @method static \Illuminate\Database\Query\Builder|AuditLogEntry withoutTrashed() - * @mixin \Eloquent + * @mixin Eloquent + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $auditable_id + * @property string $auditable_type + * @property int $changer_id + * @property string $changer_type + * @property string $action + * @property array|null $before + * @property array|null $after + * @method static Builder|AuditLogEntry whereAction($value) + * @method static Builder|AuditLogEntry whereAfter($value) + * @method static Builder|AuditLogEntry whereAuditableId($value) + * @method static Builder|AuditLogEntry whereAuditableType($value) + * @method static Builder|AuditLogEntry whereBefore($value) + * @method static Builder|AuditLogEntry whereChangerId($value) + * @method static Builder|AuditLogEntry whereChangerType($value) + * @method static Builder|AuditLogEntry whereCreatedAt($value) + * @method static Builder|AuditLogEntry whereDeletedAt($value) + * @method static Builder|AuditLogEntry whereId($value) + * @method static Builder|AuditLogEntry whereUpdatedAt($value) */ class AuditLogEntry extends Model { diff --git a/app/Models/AutoBudget.php b/app/Models/AutoBudget.php index 9132c39a4b..aef874b847 100644 --- a/app/Models/AutoBudget.php +++ b/app/Models/AutoBudget.php @@ -34,16 +34,16 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\AutoBudget * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $budget_id - * @property int $transaction_currency_id - * @property int $auto_budget_type - * @property string $amount - * @property string $period - * @property-read Budget $budget + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $budget_id + * @property int $transaction_currency_id + * @property int $auto_budget_type + * @property string $amount + * @property string $period + * @property-read Budget $budget * @property-read TransactionCurrency $transactionCurrency * @method static \Illuminate\Database\Eloquent\Builder|AutoBudget newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|AutoBudget newQuery() @@ -65,7 +65,8 @@ use Illuminate\Support\Carbon; class AutoBudget extends Model { use SoftDeletes; - public const AUTO_BUDGET_RESET = 1; + + public const AUTO_BUDGET_RESET = 1; public const AUTO_BUDGET_ROLLOVER = 2; /** diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php index 8286c87e6d..79fd9a1607 100644 --- a/app/Models/AvailableBudget.php +++ b/app/Models/AvailableBudget.php @@ -1,4 +1,5 @@ check()) { - $availableBudgetId = (int) $value; + $availableBudgetId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var AvailableBudget $availableBudget */ @@ -112,17 +113,17 @@ class AvailableBudget extends Model * @codeCoverageIgnore * @return BelongsTo */ - public function transactionCurrency(): BelongsTo + public function user(): BelongsTo { - return $this->belongsTo(TransactionCurrency::class); + return $this->belongsTo(User::class); } /** * @codeCoverageIgnore * @return BelongsTo */ - public function user(): BelongsTo + public function transactionCurrency(): BelongsTo { - return $this->belongsTo(User::class); + return $this->belongsTo(TransactionCurrency::class); } } diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 73dc7a0377..2e7673fcae 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -1,4 +1,5 @@ check()) { - $billId = (int) $value; + $billId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Bill $bill */ @@ -152,6 +166,15 @@ class Bill extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -181,21 +204,21 @@ class Bill extends Model /** * @codeCoverageIgnore * - * @param mixed $value + * @param mixed $value */ public function setAmountMaxAttribute($value): void { - $this->attributes['amount_max'] = (string) $value; + $this->attributes['amount_max'] = (string)$value; } /** - * @param mixed $value + * @param mixed $value * * @codeCoverageIgnore */ public function setAmountMinAttribute($value): void { - $this->attributes['amount_min'] = (string) $value; + $this->attributes['amount_min'] = (string)$value; } /** @@ -216,15 +239,6 @@ class Bill extends Model return $this->hasMany(TransactionJournal::class); } - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } - /** * Get the max amount * @@ -233,7 +247,7 @@ class Bill extends Model protected function amountMax(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } @@ -245,7 +259,7 @@ class Bill extends Model protected function amountMin(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/Budget.php b/app/Models/Budget.php index fc5f6a7c11..6b260adb25 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -1,4 +1,5 @@ check()) { - $budgetId = (int) $value; + $budgetId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Budget $budget */ @@ -125,6 +126,15 @@ class Budget extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -178,13 +188,4 @@ class Budget extends Model { return $this->belongsToMany(Transaction::class, 'budget_transaction', 'budget_id'); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index e2671ae380..fdb0c43cac 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -1,4 +1,5 @@ check()) { - $budgetLimitId = (int) $value; + $budgetLimitId = (int)$value; $budgetLimit = self::where('budget_limits.id', $budgetLimitId) ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') ->where('budgets.user_id', auth()->user()->id) @@ -129,7 +130,7 @@ class BudgetLimit extends Model protected function amount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/Category.php b/app/Models/Category.php index e2ddee7726..24a9e2038f 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -38,23 +38,23 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\Category * - * @property int $id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property \Illuminate\Support\Carbon|null $deleted_at - * @property int $user_id - * @property string $name - * @property Carbon $lastActivity - * @property bool $encrypted - * @property-read Collection|Attachment[] $attachments - * @property-read int|null $attachments_count - * @property-read Collection|Note[] $notes - * @property-read int|null $notes_count + * @property int $id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + * @property \Illuminate\Support\Carbon|null $deleted_at + * @property int $user_id + * @property string $name + * @property Carbon $lastActivity + * @property bool $encrypted + * @property-read Collection|Attachment[] $attachments + * @property-read int|null $attachments_count + * @property-read Collection|Note[] $notes + * @property-read int|null $notes_count * @property-read Collection|TransactionJournal[] $transactionJournals - * @property-read int|null $transaction_journals_count - * @property-read Collection|Transaction[] $transactions - * @property-read int|null $transactions_count - * @property-read User $user + * @property-read int|null $transaction_journals_count + * @property-read Collection|Transaction[] $transactions + * @property-read int|null $transactions_count + * @property-read User $user * @method static \Illuminate\Database\Eloquent\Builder|Category newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Category newQuery() * @method static Builder|Category onlyTrashed() @@ -69,7 +69,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static Builder|Category withTrashed() * @method static Builder|Category withoutTrashed() * @mixin Eloquent - * @property int|null $user_group_id + * @property int|null $user_group_id * @method static \Illuminate\Database\Eloquent\Builder|Category whereUserGroupId($value) */ class Category extends Model @@ -96,7 +96,7 @@ class Category extends Model /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * - * @param string $value + * @param string $value * * @return Category * @throws NotFoundHttpException @@ -104,7 +104,7 @@ class Category extends Model public static function routeBinder(string $value): Category { if (auth()->check()) { - $categoryId = (int) $value; + $categoryId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Category $category */ @@ -116,6 +116,15 @@ class Category extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -151,13 +160,4 @@ class Category extends Model { return $this->belongsToMany(Transaction::class, 'category_transaction', 'category_id'); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index ee887f0227..ec88f81842 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -1,4 +1,5 @@ 'datetime', 'redeemed' => 'boolean', ]; + protected $fillable = ['user_id', 'email', 'invite_code', 'expires', 'redeemed']; /** * @codeCoverageIgnore diff --git a/app/Models/LinkType.php b/app/Models/LinkType.php index 65bd060832..e05e7d8263 100644 --- a/app/Models/LinkType.php +++ b/app/Models/LinkType.php @@ -1,4 +1,5 @@ check()) { - $linkTypeId = (int) $value; + $linkTypeId = (int)$value; $linkType = self::find($linkTypeId); if (null !== $linkType) { return $linkType; diff --git a/app/Models/Location.php b/app/Models/Location.php index 720fcf02bb..47520351cf 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -35,18 +35,18 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\Location * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $locatable_id - * @property string $locatable_type - * @property float|null $latitude - * @property float|null $longitude - * @property int|null $zoom_level + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $locatable_id + * @property string $locatable_type + * @property float|null $latitude + * @property float|null $longitude + * @property int|null $zoom_level * @property-read Collection|Account[] $accounts - * @property-read int|null $accounts_count - * @property-read Model|Eloquent $locatable + * @property-read int|null $accounts_count + * @property-read Model|Eloquent $locatable * @method static Builder|Location newModelQuery() * @method static Builder|Location newQuery() * @method static Builder|Location query() @@ -83,7 +83,7 @@ class Location extends Model /** * Add rules for locations. * - * @param array $rules + * @param array $rules * * @return array */ diff --git a/app/Models/Note.php b/app/Models/Note.php index 59e03f4501..92c83528ec 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -1,4 +1,5 @@ check()) { - $objectGroupId = (int) $value; + $objectGroupId = (int)$value; /** @var ObjectGroup $objectGroup */ $objectGroup = self::where('object_groups.id', $objectGroupId) ->where('object_groups.user_id', auth()->user()->id)->first(); @@ -101,6 +101,15 @@ class ObjectGroup extends Model throw new NotFoundHttpException(); } + /** + * @return BelongsTo + * @codeCoverageIgnore + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @return MorphToMany */ @@ -124,13 +133,4 @@ class ObjectGroup extends Model { return $this->morphedByMany(PiggyBank::class, 'object_groupable'); } - - /** - * @return BelongsTo - * @codeCoverageIgnore - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 5e4c7e6eaa..b497fd1791 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -1,4 +1,5 @@ check()) { - $piggyBankId = (int) $value; + $piggyBankId = (int)$value; $piggyBank = self::where('piggy_banks.id', $piggyBankId) ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') ->where('accounts.user_id', auth()->user()->id)->first(['piggy_banks.*']); @@ -183,11 +184,11 @@ class PiggyBank extends Model /** * @codeCoverageIgnore * - * @param mixed $value + * @param mixed $value */ public function setTargetamountAttribute($value): void { - $this->attributes['targetamount'] = (string) $value; + $this->attributes['targetamount'] = (string)$value; } /** @@ -198,7 +199,7 @@ class PiggyBank extends Model protected function targetamount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 4562d27dab..592810edcf 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -1,4 +1,5 @@ attributes['amount'] = (string) $value; + $this->attributes['amount'] = (string)$value; } /** @@ -107,7 +108,7 @@ class PiggyBankEvent extends Model protected function amount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index 55f5ebf5e9..f7394bbf90 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -1,4 +1,5 @@ attributes['currentamount'] = (string) $value; + $this->attributes['currentamount'] = (string)$value; } /** @@ -136,7 +137,7 @@ class PiggyBankRepetition extends Model protected function currentamount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/Preference.php b/app/Models/Preference.php index 7b1440cee1..daf12690a7 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -1,4 +1,5 @@ preferences()->where('name', $value)->first(); if (null === $preference) { - $preference = $user->preferences()->where('id', (int) $value)->first(); + $preference = $user->preferences()->where('id', (int)$value)->first(); } if (null !== $preference) { return $preference; diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 0df6d7bbd3..b1415f8333 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -38,33 +38,33 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\Recurrence * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $user_id - * @property int $transaction_type_id - * @property string $title - * @property string $description - * @property Carbon $first_date - * @property Carbon|null $repeat_until - * @property Carbon|null $latest_date - * @property int $repetitions - * @property bool $apply_rules - * @property bool $active - * @property-read Collection|Attachment[] $attachments - * @property-read int|null $attachments_count - * @property-read Collection|Note[] $notes - * @property-read int|null $notes_count - * @property-read Collection|RecurrenceMeta[] $recurrenceMeta - * @property-read int|null $recurrence_meta_count - * @property-read Collection|RecurrenceRepetition[] $recurrenceRepetitions - * @property-read int|null $recurrence_repetitions_count + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $user_id + * @property int $transaction_type_id + * @property string $title + * @property string $description + * @property Carbon $first_date + * @property Carbon|null $repeat_until + * @property Carbon|null $latest_date + * @property int $repetitions + * @property bool $apply_rules + * @property bool $active + * @property-read Collection|Attachment[] $attachments + * @property-read int|null $attachments_count + * @property-read Collection|Note[] $notes + * @property-read int|null $notes_count + * @property-read Collection|RecurrenceMeta[] $recurrenceMeta + * @property-read int|null $recurrence_meta_count + * @property-read Collection|RecurrenceRepetition[] $recurrenceRepetitions + * @property-read int|null $recurrence_repetitions_count * @property-read Collection|RecurrenceTransaction[] $recurrenceTransactions - * @property-read int|null $recurrence_transactions_count - * @property-read TransactionCurrency $transactionCurrency - * @property-read TransactionType $transactionType - * @property-read User $user + * @property-read int|null $recurrence_transactions_count + * @property-read TransactionCurrency $transactionCurrency + * @property-read TransactionType $transactionType + * @property-read User $user * @method static \Illuminate\Database\Eloquent\Builder|Recurrence newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Recurrence newQuery() * @method static Builder|Recurrence onlyTrashed() @@ -86,7 +86,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static Builder|Recurrence withTrashed() * @method static Builder|Recurrence withoutTrashed() * @mixin Eloquent - * @property int|null $user_group_id + * @property int|null $user_group_id * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUserGroupId($value) */ class Recurrence extends Model @@ -122,7 +122,7 @@ class Recurrence extends Model /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * - * @param string $value + * @param string $value * * @return Recurrence * @throws NotFoundHttpException @@ -130,7 +130,7 @@ class Recurrence extends Model public static function routeBinder(string $value): Recurrence { if (auth()->check()) { - $recurrenceId = (int) $value; + $recurrenceId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Recurrence $recurrence */ @@ -142,6 +142,15 @@ class Recurrence extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -204,13 +213,4 @@ class Recurrence extends Model { return $this->belongsTo(TransactionType::class); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/RecurrenceMeta.php b/app/Models/RecurrenceMeta.php index 1037b6ccb3..516ff62ed5 100644 --- a/app/Models/RecurrenceMeta.php +++ b/app/Models/RecurrenceMeta.php @@ -33,13 +33,13 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\RecurrenceMeta * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $recurrence_id - * @property string $name - * @property mixed $value + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $recurrence_id + * @property string $name + * @property mixed $value * @property-read Recurrence $recurrence * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceMeta newQuery() diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index 3061ad67f6..156dbaf01a 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -33,15 +33,15 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\RecurrenceRepetition * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $recurrence_id - * @property string $repetition_type - * @property string $repetition_moment - * @property int $repetition_skip - * @property int $weekend + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $recurrence_id + * @property string $repetition_type + * @property string $repetition_moment + * @property int $repetition_skip + * @property int $weekend * @property-read Recurrence $recurrence * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceRepetition newQuery() @@ -63,6 +63,7 @@ use Illuminate\Support\Carbon; class RecurrenceRepetition extends Model { use SoftDeletes; + public const WEEKEND_DO_NOTHING = 1; public const WEEKEND_SKIP_CREATION = 2; public const WEEKEND_TO_FRIDAY = 3; diff --git a/app/Models/RecurrenceTransaction.php b/app/Models/RecurrenceTransaction.php index 9617e13a2b..3bf47ab78c 100644 --- a/app/Models/RecurrenceTransaction.php +++ b/app/Models/RecurrenceTransaction.php @@ -35,25 +35,25 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\RecurrenceTransaction * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $recurrence_id - * @property int $transaction_currency_id - * @property int|null $foreign_currency_id - * @property int $source_id - * @property int $destination_id - * @property string $amount - * @property string|null $foreign_amount - * @property string $description - * @property-read Account $destinationAccount - * @property-read TransactionCurrency|null $foreignCurrency - * @property-read Recurrence $recurrence + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $recurrence_id + * @property int $transaction_currency_id + * @property int|null $foreign_currency_id + * @property int $source_id + * @property int $destination_id + * @property string $amount + * @property string|null $foreign_amount + * @property string $description + * @property-read Account $destinationAccount + * @property-read TransactionCurrency|null $foreignCurrency + * @property-read Recurrence $recurrence * @property-read Collection|RecurrenceTransactionMeta[] $recurrenceTransactionMeta - * @property-read int|null $recurrence_transaction_meta_count - * @property-read Account $sourceAccount - * @property-read TransactionCurrency $transactionCurrency + * @property-read int|null $recurrence_transaction_meta_count + * @property-read Account $sourceAccount + * @property-read TransactionCurrency $transactionCurrency * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransaction newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransaction newQuery() * @method static Builder|RecurrenceTransaction onlyTrashed() @@ -73,9 +73,9 @@ use Illuminate\Support\Carbon; * @method static Builder|RecurrenceTransaction withTrashed() * @method static Builder|RecurrenceTransaction withoutTrashed() * @mixin Eloquent - * @property int|null $transaction_type_id + * @property int|null $transaction_type_id * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransaction whereTransactionTypeId($value) - * @property-read TransactionType|null $transactionType + * @property-read TransactionType|null $transactionType */ class RecurrenceTransaction extends Model { @@ -97,8 +97,16 @@ class RecurrenceTransaction extends Model ]; /** @var array Fields that can be filled */ protected $fillable - = ['recurrence_id', 'transaction_currency_id', 'foreign_currency_id', 'source_id', 'destination_id', 'amount', 'foreign_amount', - 'description']; + = [ + 'recurrence_id', + 'transaction_currency_id', + 'foreign_currency_id', + 'source_id', + 'destination_id', + 'amount', + 'foreign_amount', + 'description', + ]; /** @var string The table to store the data in */ protected $table = 'recurrences_transactions'; diff --git a/app/Models/RecurrenceTransactionMeta.php b/app/Models/RecurrenceTransactionMeta.php index 0ca31628e5..a5e1bd9fc0 100644 --- a/app/Models/RecurrenceTransactionMeta.php +++ b/app/Models/RecurrenceTransactionMeta.php @@ -33,13 +33,13 @@ use Illuminate\Support\Carbon; /** * FireflyIII\Models\RecurrenceTransactionMeta * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property Carbon|null $deleted_at - * @property int $rt_id - * @property string $name - * @property mixed $value + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property Carbon|null $deleted_at + * @property int $rt_id + * @property string $name + * @property mixed $value * @property-read RecurrenceTransaction $recurrenceTransaction * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|RecurrenceTransactionMeta newQuery() diff --git a/app/Models/Role.php b/app/Models/Role.php index 1462fb2e30..75befaabe5 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -1,4 +1,5 @@ check()) { - $ruleId = (int) $value; + $ruleId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Rule $rule */ @@ -123,6 +124,15 @@ class Rule extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return HasMany @@ -151,7 +161,7 @@ class Rule extends Model } /** - * @param mixed $value + * @param mixed $value * * @codeCoverageIgnore */ @@ -159,13 +169,4 @@ class Rule extends Model { $this->attributes['description'] = e($value); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php index 922c4445c1..a80ccb1523 100644 --- a/app/Models/RuleAction.php +++ b/app/Models/RuleAction.php @@ -1,4 +1,5 @@ check()) { - $ruleGroupId = (int) $value; + $ruleGroupId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var RuleGroup $ruleGroup */ @@ -114,15 +115,6 @@ class RuleGroup extends Model throw new NotFoundHttpException(); } - /** - * @codeCoverageIgnore - * @return HasMany - */ - public function rules(): HasMany - { - return $this->hasMany(Rule::class); - } - /** * @codeCoverageIgnore * @return BelongsTo @@ -131,4 +123,13 @@ class RuleGroup extends Model { return $this->belongsTo(User::class); } + + /** + * @codeCoverageIgnore + * @return HasMany + */ + public function rules(): HasMany + { + return $this->hasMany(Rule::class); + } } diff --git a/app/Models/RuleTrigger.php b/app/Models/RuleTrigger.php index 234e1feefa..2e0fb6543a 100644 --- a/app/Models/RuleTrigger.php +++ b/app/Models/RuleTrigger.php @@ -1,4 +1,5 @@ check()) { - $tagId = (int) $value; + $tagId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Tag $tag */ @@ -125,6 +126,15 @@ class Tag extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -151,13 +161,4 @@ class Tag extends Model { return $this->belongsToMany(TransactionJournal::class); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index b65007574c..03e90a0203 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -1,4 +1,5 @@ attributes['amount'] = (string) $value; + $this->attributes['amount'] = (string)$value; } /** @@ -267,7 +277,7 @@ class Transaction extends Model protected function amount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } @@ -279,7 +289,7 @@ class Transaction extends Model protected function foreignAmount(): Attribute { return Attribute::make( - get: fn ($value) => (string) $value, + get: fn ($value) => (string)$value, ); } } diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index 6d00964384..1196f7a8e3 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -1,4 +1,5 @@ check()) { - $currencyId = (int) $value; + $currencyId = (int)$value; $currency = self::find($currencyId); if (null !== $currency) { return $currency; diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php index a22763c667..627f5c756d 100644 --- a/app/Models/TransactionGroup.php +++ b/app/Models/TransactionGroup.php @@ -1,4 +1,5 @@ check()) { - $groupId = (int) $value; + $groupId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var TransactionGroup $group */ @@ -109,15 +110,6 @@ class TransactionGroup extends Model throw new NotFoundHttpException(); } - /** - * @codeCoverageIgnore - * @return HasMany - */ - public function transactionJournals(): HasMany - { - return $this->hasMany(TransactionJournal::class); - } - /** * @codeCoverageIgnore * @return BelongsTo @@ -126,4 +118,13 @@ class TransactionGroup extends Model { return $this->belongsTo(User::class); } + + /** + * @codeCoverageIgnore + * @return HasMany + */ + public function transactionJournals(): HasMany + { + return $this->hasMany(TransactionJournal::class); + } } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index a1541e13e3..03fe540362 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -1,4 +1,5 @@ check()) { - $journalId = (int) $value; + $journalId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var TransactionJournal $journal */ @@ -174,6 +184,15 @@ class TransactionJournal extends Model throw new NotFoundHttpException(); } + /** + * @codeCoverageIgnore + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @codeCoverageIgnore * @return MorphMany @@ -262,8 +281,8 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore * - * @param EloquentBuilder $query - * @param Carbon $date + * @param EloquentBuilder $query + * @param Carbon $date * * @return EloquentBuilder */ @@ -275,8 +294,8 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore * - * @param EloquentBuilder $query - * @param Carbon $date + * @param EloquentBuilder $query + * @param Carbon $date * * @return EloquentBuilder */ @@ -288,8 +307,8 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore * - * @param EloquentBuilder $query - * @param array $types + * @param EloquentBuilder $query + * @param array $types */ public function scopeTransactionTypes(EloquentBuilder $query, array $types): void { @@ -306,8 +325,8 @@ class TransactionJournal extends Model * * @codeCoverageIgnore * - * @param Builder $query - * @param string $table + * @param Builder $query + * @param string $table * * @return bool */ @@ -388,13 +407,4 @@ class TransactionJournal extends Model { return $this->hasMany(Transaction::class); } - - /** - * @codeCoverageIgnore - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } } diff --git a/app/Models/TransactionJournalLink.php b/app/Models/TransactionJournalLink.php index 34e819a2d8..937acf1713 100644 --- a/app/Models/TransactionJournalLink.php +++ b/app/Models/TransactionJournalLink.php @@ -1,4 +1,5 @@ check()) { - $linkId = (int) $value; + $linkId = (int)$value; $link = self::where('journal_links.id', $linkId) ->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id') ->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id') diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php index 94a9feba64..823bcb01a6 100644 --- a/app/Models/TransactionJournalMeta.php +++ b/app/Models/TransactionJournalMeta.php @@ -1,4 +1,5 @@ value] = $item->name; + } + return $array; + } + + /** + * @return array + */ + public static function getDeliveriesForValidation(): array + { + $array = []; + $set = WebhookDelivery::cases(); + foreach ($set as $item) { + $array[$item->name] = $item->value; + $array[$item->value] = $item->value; + } + return $array; + } + + /** + * @return array + */ + public static function getResponses(): array + { + $array = []; + $set = WebhookResponse::cases(); + foreach ($set as $item) { + $array[$item->value] = $item->name; + } + return $array; + } + + /** + * @return array + */ + public static function getResponsesForValidation(): array + { + $array = []; + $set = WebhookResponse::cases(); + foreach ($set as $item) { + $array[$item->name] = $item->value; + $array[$item->value] = $item->value; + } + return $array; + } + + /** + * @return array + */ + public static function getTriggers(): array + { + $array = []; + $set = WebhookTrigger::cases(); + foreach ($set as $item) { + $array[$item->value] = $item->name; + } + return $array; + } + + /** + * @return array + */ + public static function getTriggersForValidation(): array + { + $array = []; + $set = WebhookTrigger::cases(); + foreach ($set as $item) { + $array[$item->name] = $item->value; + $array[$item->value] = $item->value; + } + return $array; + } + /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * - * @param string $value + * @param string $value * * @return Webhook * @throws NotFoundHttpException @@ -101,7 +182,7 @@ class Webhook extends Model public static function routeBinder(string $value): Webhook { if (auth()->check()) { - $webhookId = (int) $value; + $webhookId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var Webhook $webhook */ @@ -130,85 +211,4 @@ class Webhook extends Model { return $this->hasMany(WebhookMessage::class); } - - /** - * @return array - */ - public static function getTriggers(): array - { - $array = []; - $set = WebhookTrigger::cases(); - foreach ($set as $item) { - $array[$item->value] = $item->name; - } - return $array; - } - - /** - * @return array - */ - public static function getTriggersForValidation(): array - { - $array = []; - $set = WebhookTrigger::cases(); - foreach ($set as $item) { - $array[$item->name] = $item->value; - $array[$item->value] = $item->value; - } - return $array; - } - - /** - * @return array - */ - public static function getResponsesForValidation(): array - { - $array = []; - $set = WebhookResponse::cases(); - foreach ($set as $item) { - $array[$item->name] = $item->value; - $array[$item->value] = $item->value; - } - return $array; - } - - /** - * @return array - */ - public static function getDeliveriesForValidation(): array - { - $array = []; - $set = WebhookDelivery::cases(); - foreach ($set as $item) { - $array[$item->name] = $item->value; - $array[$item->value] = $item->value; - } - return $array; - } - - /** - * @return array - */ - public static function getResponses(): array - { - $array = []; - $set = WebhookResponse::cases(); - foreach ($set as $item) { - $array[$item->value] = $item->name; - } - return $array; - } - - /** - * @return array - */ - public static function getDeliveries(): array - { - $array = []; - $set = WebhookDelivery::cases(); - foreach ($set as $item) { - $array[$item->value] = $item->name; - } - return $array; - } } diff --git a/app/Models/WebhookAttempt.php b/app/Models/WebhookAttempt.php index 97538899aa..9d1c296626 100644 --- a/app/Models/WebhookAttempt.php +++ b/app/Models/WebhookAttempt.php @@ -35,14 +35,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class WebhookAttempt * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property string|null $deleted_at - * @property int $webhook_message_id - * @property int $status_code - * @property string|null $logs - * @property string|null $response + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property string|null $deleted_at + * @property int $webhook_message_id + * @property int $status_code + * @property string|null $logs + * @property string|null $response * @property-read WebhookMessage $webhookMessage * @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newQuery() @@ -67,7 +67,7 @@ class WebhookAttempt extends Model /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * - * @param string $value + * @param string $value * * @return WebhookAttempt * @throws NotFoundHttpException @@ -75,7 +75,7 @@ class WebhookAttempt extends Model public static function routeBinder(string $value): WebhookAttempt { if (auth()->check()) { - $attemptId = (int) $value; + $attemptId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var WebhookAttempt $attempt */ diff --git a/app/Models/WebhookMessage.php b/app/Models/WebhookMessage.php index 03a740e4ec..19d62f451a 100644 --- a/app/Models/WebhookMessage.php +++ b/app/Models/WebhookMessage.php @@ -36,18 +36,18 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\WebhookMessage * - * @property int $id - * @property Carbon|null $created_at - * @property Carbon|null $updated_at - * @property string|null $deleted_at - * @property int $webhook_id - * @property bool $sent - * @property bool $errored - * @property int $attempts - * @property string $uuid - * @property array $message - * @property array|null $logs - * @property-read Webhook $webhook + * @property int $id + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property string|null $deleted_at + * @property int $webhook_id + * @property bool $sent + * @property bool $errored + * @property int $attempts + * @property string $uuid + * @property array $message + * @property array|null $logs + * @property-read Webhook $webhook * @method static Builder|WebhookMessage newModelQuery() * @method static Builder|WebhookMessage newQuery() * @method static Builder|WebhookMessage query() @@ -64,7 +64,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static Builder|WebhookMessage whereWebhookId($value) * @mixin Eloquent * @property-read Collection|WebhookAttempt[] $webhookAttempts - * @property-read int|null $webhook_attempts_count + * @property-read int|null $webhook_attempts_count */ class WebhookMessage extends Model { @@ -80,7 +80,7 @@ class WebhookMessage extends Model /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * - * @param string $value + * @param string $value * * @return WebhookMessage * @throws NotFoundHttpException @@ -88,7 +88,7 @@ class WebhookMessage extends Model public static function routeBinder(string $value): WebhookMessage { if (auth()->check()) { - $messageId = (int) $value; + $messageId = (int)$value; /** @var User $user */ $user = auth()->user(); /** @var WebhookMessage $message */ diff --git a/app/Notifications/Admin/TestNotification.php b/app/Notifications/Admin/TestNotification.php index 99d8437c87..ad21a8d2d7 100644 --- a/app/Notifications/Admin/TestNotification.php +++ b/app/Notifications/Admin/TestNotification.php @@ -48,45 +48,10 @@ class TestNotification extends Notification $this->address = $address; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail', 'slack']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.admin-test', ['email' => $this->address]) - ->subject((string) trans('email.admin_test_subject')); - } - - /** - * Get the Slack representation of the notification. - * - * @param mixed $notifiable - * @return SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage())->content((string) trans('email.admin_test_subject')); - } - /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) @@ -95,4 +60,39 @@ class TestNotification extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.admin-test', ['email' => $this->address]) + ->subject((string)trans('email.admin_test_subject')); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage())->content((string)trans('email.admin_test_subject')); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'slack']; + } } diff --git a/app/Notifications/Admin/UserInvitation.php b/app/Notifications/Admin/UserInvitation.php index cfc2af2ea5..5b17c60412 100644 --- a/app/Notifications/Admin/UserInvitation.php +++ b/app/Notifications/Admin/UserInvitation.php @@ -49,45 +49,10 @@ class UserInvitation extends Notification $this->invitee = $invitee; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail', 'slack']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.invitation-created', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]) - ->subject((string) trans('email.invitation_created_subject')); - } - - /** - * Get the Slack representation of the notification. - * - * @param mixed $notifiable - * @return SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage())->content((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])); - } - /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) @@ -96,4 +61,41 @@ class UserInvitation extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.invitation-created', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]) + ->subject((string)trans('email.invitation_created_subject')); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage())->content( + (string)trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]) + ); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'slack']; + } } diff --git a/app/Notifications/Admin/UserRegistration.php b/app/Notifications/Admin/UserRegistration.php index 16f4b517fa..a9636020a9 100644 --- a/app/Notifications/Admin/UserRegistration.php +++ b/app/Notifications/Admin/UserRegistration.php @@ -49,45 +49,10 @@ class UserRegistration extends Notification $this->user = $user; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail', 'slack']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id]) - ->subject((string) trans('email.registered_subject_admin')); - } - - /** - * Get the Slack representation of the notification. - * - * @param mixed $notifiable - * @return SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id])); - } - /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) @@ -96,4 +61,39 @@ class UserRegistration extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id]) + ->subject((string)trans('email.registered_subject_admin')); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage())->content((string)trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id])); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'slack']; + } } diff --git a/app/Notifications/Admin/VersionCheckResult.php b/app/Notifications/Admin/VersionCheckResult.php index 1cd56c1b33..a8d3ce7f1a 100644 --- a/app/Notifications/Admin/VersionCheckResult.php +++ b/app/Notifications/Admin/VersionCheckResult.php @@ -49,48 +49,10 @@ class VersionCheckResult extends Notification $this->message = $message; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail', 'slack']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.new-version', ['message' => $this->message]) - ->subject((string) trans('email.new_version_email_subject')); - } - - /** - * Get the Slack representation of the notification. - * - * @param mixed $notifiable - * @return SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage())->content($this->message) - ->attachment(function ($attachment) { - $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases'); - }); - } - /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ public function toArray($notifiable) @@ -99,4 +61,42 @@ class VersionCheckResult extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.new-version', ['message' => $this->message]) + ->subject((string)trans('email.new_version_email_subject')); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage())->content($this->message) + ->attachment(function ($attachment) { + $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases'); + }); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'slack']; + } } diff --git a/app/Notifications/User/BillReminder.php b/app/Notifications/User/BillReminder.php index d17b8f775f..677dd6fa47 100644 --- a/app/Notifications/User/BillReminder.php +++ b/app/Notifications/User/BillReminder.php @@ -38,8 +38,8 @@ class BillReminder extends Notification use Queueable; private Bill $bill; - private string $field; private int $diff; + private string $field; /** * Create a new notification instance. @@ -54,27 +54,29 @@ class BillReminder extends Notification } /** - * Get the notification's delivery channels. + * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ - public function via($notifiable) + public function toArray($notifiable) { - return ['mail', 'slack']; + return [ + // + ]; } /** * Get the mail representation of the notification. * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage + * @param mixed $notifiable + * @return MailMessage */ public function toMail($notifiable) { - $subject = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $subject = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); if (0 === $this->diff) { - $subject = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $subject = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); } return (new MailMessage()) @@ -85,35 +87,33 @@ class BillReminder extends Notification /** * Get the Slack representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return SlackMessage */ public function toSlack($notifiable) { - $message = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $message = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); if (0 === $this->diff) { - $message = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); + $message = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]); } $bill = $this->bill; $url = route('bills.show', [$bill->id]); return (new SlackMessage()) ->warning() ->attachment(function ($attachment) use ($bill, $url) { - $attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url); + $attachment->title((string)trans('firefly.visit_bill', ['name' => $bill->name]), $url); }) ->content($message); } /** - * Get the array representation of the notification. + * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable * @return array */ - public function toArray($notifiable) + public function via($notifiable) { - return [ - // - ]; + return ['mail', 'slack']; } } diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.php index d70919de2c..867c3fd4b9 100644 --- a/app/Notifications/User/NewAccessToken.php +++ b/app/Notifications/User/NewAccessToken.php @@ -42,40 +42,6 @@ class NewAccessToken extends Notification { } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail', 'slack']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.token-created') - ->subject((string) trans('email.access_token_created_subject')); - } - /** - * Get the Slack representation of the notification. - * - * @param mixed $notifiable - * @return SlackMessage - */ - public function toSlack($notifiable) - { - return (new SlackMessage())->content((string) trans('email.access_token_created_body')); - } - /** * Get the array representation of the notification. * @@ -88,4 +54,39 @@ class NewAccessToken extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.token-created') + ->subject((string)trans('email.access_token_created_subject')); + } + + /** + * Get the Slack representation of the notification. + * + * @param mixed $notifiable + * @return SlackMessage + */ + public function toSlack($notifiable) + { + return (new SlackMessage())->content((string)trans('email.access_token_created_body')); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'slack']; + } } diff --git a/app/Notifications/User/TransactionCreation.php b/app/Notifications/User/TransactionCreation.php index 7dea4fcbbb..102ab79087 100644 --- a/app/Notifications/User/TransactionCreation.php +++ b/app/Notifications/User/TransactionCreation.php @@ -27,7 +27,6 @@ namespace FireflyIII\Notifications\User; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -use Illuminate\Support\Collection; class TransactionCreation extends Notification { @@ -45,30 +44,6 @@ class TransactionCreation extends Notification $this->collection = $collection; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.report-new-journals', ['transformed' => $this->collection]) - ->subject((string) trans_choice('email.new_journals_subject', count($this->collection))); - } - /** * Get the array representation of the notification. * @@ -81,4 +56,28 @@ class TransactionCreation extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.report-new-journals', ['transformed' => $this->collection]) + ->subject((string)trans_choice('email.new_journals_subject', count($this->collection))); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } } diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.php index 263cc7db90..9ec2a5bc35 100644 --- a/app/Notifications/User/UserLogin.php +++ b/app/Notifications/User/UserLogin.php @@ -47,25 +47,27 @@ class UserLogin extends Notification } /** - * Get the notification's delivery channels. + * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ - public function via($notifiable) + public function toArray($notifiable) { - return ['mail', 'slack']; + return [ + // + ]; } /** * Get the mail representation of the notification. * * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage + * @return MailMessage */ public function toMail($notifiable) { - $time = now(config('app.timezone'))->isoFormat((string) trans('config.date_time_js')); + $time = now(config('app.timezone'))->isoFormat((string)trans('config.date_time_js')); $host = ''; try { $hostName = gethostbyaddr($this->ip); @@ -78,13 +80,13 @@ class UserLogin extends Notification return (new MailMessage()) ->markdown('emails.new-ip', ['time' => $time, 'ipAddress' => $this->ip, 'host' => $host]) - ->subject((string) trans('email.login_from_new_ip')); + ->subject((string)trans('email.login_from_new_ip')); } /** * Get the Slack representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable * @return SlackMessage */ public function toSlack($notifiable) @@ -99,19 +101,17 @@ class UserLogin extends Notification $host = $hostName; } - return (new SlackMessage())->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip])); + return (new SlackMessage())->content((string)trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip])); } /** - * Get the array representation of the notification. + * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ - public function toArray($notifiable) + public function via($notifiable) { - return [ - // - ]; + return ['mail', 'slack']; } } diff --git a/app/Notifications/User/UserNewPassword.php b/app/Notifications/User/UserNewPassword.php index 2141a634cc..48f14421b1 100644 --- a/app/Notifications/User/UserNewPassword.php +++ b/app/Notifications/User/UserNewPassword.php @@ -44,30 +44,6 @@ class UserNewPassword extends Notification $this->url = $url; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.password', ['url' => $this->url]) - ->subject((string) trans('email.reset_pw_subject')); - } - /** * Get the array representation of the notification. * @@ -80,4 +56,28 @@ class UserNewPassword extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.password', ['url' => $this->url]) + ->subject((string)trans('email.reset_pw_subject')); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } } diff --git a/app/Notifications/User/UserRegistration.php b/app/Notifications/User/UserRegistration.php index 0c30634939..ba5e39348a 100644 --- a/app/Notifications/User/UserRegistration.php +++ b/app/Notifications/User/UserRegistration.php @@ -41,30 +41,6 @@ class UserRegistration extends Notification { } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage()) - ->markdown('emails.registered', ['address' => route('index')]) - ->subject((string) trans('email.registered_subject')); - } - /** * Get the array representation of the notification. * @@ -77,4 +53,28 @@ class UserRegistration extends Notification // ]; } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage()) + ->markdown('emails.registered', ['address' => route('index')]) + ->subject((string)trans('email.registered_subject')); + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } } diff --git a/app/Providers/AccountServiceProvider.php b/app/Providers/AccountServiceProvider.php index c87627d280..ae57518c7b 100644 --- a/app/Providers/AccountServiceProvider.php +++ b/app/Providers/AccountServiceProvider.php @@ -1,4 +1,5 @@ 'no-store' + 'Cache-Control' => 'no-store', ]; - $uuid = (string) request()->header('X-Trace-Id'); + $uuid = (string)request()->header('X-Trace-Id'); if ('' !== trim($uuid) && (preg_match('/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', trim($uuid)) === 1)) { $headers['X-Trace-Id'] = $uuid; } diff --git a/app/Providers/AttachmentServiceProvider.php b/app/Providers/AttachmentServiceProvider.php index 94e3052727..712f631a73 100644 --- a/app/Providers/AttachmentServiceProvider.php +++ b/app/Providers/AttachmentServiceProvider.php @@ -1,4 +1,5 @@ registerBudgetEvents(); } + /** + * TODO needs a dedicated (static) method. + */ + protected function registerCreateEvents(): void + { + PiggyBank::created( + static function (PiggyBank $piggyBank) { + $repetition = new PiggyBankRepetition(); + $repetition->piggyBank()->associate($piggyBank); + $repetition->startdate = $piggyBank->startdate; + $repetition->targetdate = $piggyBank->targetdate; + $repetition->currentamount = 0; + $repetition->save(); + } + ); + } + /** * TODO needs a dedicated method. */ @@ -224,21 +241,4 @@ class EventServiceProvider extends ServiceProvider BudgetLimit::created($func); BudgetLimit::updated($func); } - - /** - * TODO needs a dedicated (static) method. - */ - protected function registerCreateEvents(): void - { - PiggyBank::created( - static function (PiggyBank $piggyBank) { - $repetition = new PiggyBankRepetition(); - $repetition->piggyBank()->associate($piggyBank); - $repetition->startdate = $piggyBank->startdate; - $repetition->targetdate = $piggyBank->targetdate; - $repetition->currentamount = 0; - $repetition->save(); - } - ); - } } diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 9e96be7b62..8bc336d545 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -1,4 +1,5 @@ user->accounts()->accountTypeIn($types)->count(); - } - /** * Moved here from account CRUD. * - * @param Account $account - * @param Account|null $moveTo + * @param Account $account + * @param Account|null $moveTo * * @return bool * @@ -84,7 +75,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Find account with same name OR same IBAN or both, but not the same type or ID. * - * @param Collection $accounts + * @param Collection $accounts * * @return Collection */ @@ -115,16 +106,6 @@ class AccountRepository implements AccountRepositoryInterface return $result; } - /** - * @param int $accountId - * - * @return Account|null - */ - public function find(int $accountId): ?Account - { - return $this->user->accounts()->find($accountId); - } - /** * @inheritDoc */ @@ -151,8 +132,8 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param string $iban - * @param array $types + * @param string $iban + * @param array $types * * @return Account|null */ @@ -169,8 +150,8 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param string $name - * @param array $types + * @param string $name + * @param array $types * * @return Account|null */ @@ -200,7 +181,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Return account type or null if not found. * - * @param string $type + * @param string $type * * @return AccountType|null */ @@ -210,7 +191,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param array $accountIds + * @param array $accountIds * * @return Collection */ @@ -229,16 +210,19 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param array $types + * @param array $types * * @return Collection */ public function getActiveAccountsByType(array $types): Collection { $query = $this->user->accounts()->with( - ['accountmeta' => function (HasMany $query) { - $query->where('name', 'account_role'); - }, 'attachments'] + [ + 'accountmeta' => function (HasMany $query) { + $query->where('name', 'account_role'); + }, + 'attachments', + ] ); if (0 !== count($types)) { $query->accountTypeIn($types); @@ -288,15 +272,23 @@ class AccountRepository implements AccountRepositoryInterface return $factory->findOrCreate('Cash account', $type->type); } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @inheritDoc */ public function getCreditTransactionGroup(Account $account): ?TransactionGroup { $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::LIABILITY_CREDIT]) - ->first(['transaction_journals.*']); + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::LIABILITY_CREDIT]) + ->first(['transaction_journals.*']); if (null === $journal) { return null; } @@ -305,16 +297,18 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param array $types + * @param array $types * * @return Collection */ public function getInactiveAccountsByType(array $types): Collection { $query = $this->user->accounts()->with( - ['accountmeta' => function (HasMany $query) { - $query->where('name', 'account_role'); - }] + [ + 'accountmeta' => function (HasMany $query) { + $query->where('name', 'account_role'); + }, + ] ); if (0 !== count($types)) { $query->accountTypeIn($types); @@ -338,7 +332,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Get note text or null. * - * @param Account $account + * @param Account $account * * @return null|string */ @@ -356,7 +350,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Returns the amount of the opening balance for this account. * - * @param Account $account + * @param Account $account * * @return string|null */ @@ -374,13 +368,13 @@ class AccountRepository implements AccountRepositoryInterface return null; } - return (string) $transaction->amount; + return (string)$transaction->amount; } /** * Return date of opening balance as string or null. * - * @param Account $account + * @param Account $account * * @return null|string */ @@ -398,7 +392,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account + * @param Account $account * * @return TransactionGroup|null */ @@ -410,20 +404,20 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account + * @param Account $account * * @return TransactionJournal|null */ public function getOpeningBalance(Account $account): ?TransactionJournal { return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->transactionTypes([TransactionType::OPENING_BALANCE]) - ->first(['transaction_journals.*']); + ->where('transactions.account_id', $account->id) + ->transactionTypes([TransactionType::OPENING_BALANCE]) + ->first(['transaction_journals.*']); } /** - * @param Account $account + * @param Account $account * * @return Collection */ @@ -433,7 +427,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account + * @param Account $account * * @return Account|null * @@ -476,7 +470,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account + * @param Account $account * * @return TransactionCurrency|null */ @@ -489,7 +483,7 @@ class AccountRepository implements AccountRepositoryInterface if (!in_array($type, $list, true)) { return null; } - $currencyId = (int) $this->getMetaValue($account, 'currency_id'); + $currencyId = (int)$this->getMetaValue($account, 'currency_id'); if ($currencyId > 0) { return TransactionCurrency::find($currencyId); } @@ -500,8 +494,8 @@ class AccountRepository implements AccountRepositoryInterface /** * Return meta value for account. Null if not found. * - * @param Account $account - * @param string $field + * @param Account $account + * @param string $field * * @return null|string */ @@ -516,12 +510,32 @@ class AccountRepository implements AccountRepositoryInterface return null; } if (1 === $result->count()) { - return (string) $result->first()->data; + return (string)$result->first()->data; } return null; } + /** + * @param array $types + * + * @return int + */ + public function count(array $types): int + { + return $this->user->accounts()->accountTypeIn($types)->count(); + } + + /** + * @param int $accountId + * + * @return Account|null + */ + public function find(int $accountId): ?Account + { + return $this->user->accounts()->find($accountId); + } + /** * @inheritDoc */ @@ -530,8 +544,8 @@ class AccountRepository implements AccountRepositoryInterface $info = $account->transactions()->get(['transaction_currency_id', 'foreign_currency_id'])->toArray(); $currencyIds = []; foreach ($info as $entry) { - $currencyIds[] = (int) $entry['transaction_currency_id']; - $currencyIds[] = (int) $entry['foreign_currency_id']; + $currencyIds[] = (int)$entry['transaction_currency_id']; + $currencyIds[] = (int)$entry['foreign_currency_id']; } $currencyIds = array_unique($currencyIds); @@ -539,7 +553,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account + * @param Account $account * * @return bool */ @@ -562,22 +576,22 @@ class AccountRepository implements AccountRepositoryInterface AccountType::MORTGAGE => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], ]; if (array_key_exists(ucfirst($type), $sets)) { - $order = (int) $this->getAccountsByType($sets[ucfirst($type)])->max('order'); + $order = (int)$this->getAccountsByType($sets[ucfirst($type)])->max('order'); Log::debug(sprintf('Return max order of "%s" set: %d', $type, $order)); return $order; } $specials = [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION]; - $order = (int) $this->getAccountsByType($specials)->max('order'); + $order = (int)$this->getAccountsByType($specials)->max('order'); Log::debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order)); return $order; } /** - * @param array $types - * @param array|null $sort + * @param array $types + * @param array|null $sort * * @return Collection */ @@ -610,7 +624,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Returns the date of the very first transaction in this account. * - * @param Account $account + * @param Account $account * * @return Carbon|null */ @@ -624,7 +638,7 @@ class AccountRepository implements AccountRepositoryInterface /** * Returns the date of the very first transaction in this account. * - * @param Account $account + * @param Account $account * * @return TransactionJournal|null */ @@ -638,7 +652,7 @@ class AccountRepository implements AccountRepositoryInterface ->orderBy('transaction_journals.id', 'ASC') ->first(['transaction_journals.id']); if (null !== $first) { - return TransactionJournal::find((int) $first->id); + return TransactionJournal::find((int)$first->id); } return null; @@ -665,7 +679,7 @@ class AccountRepository implements AccountRepositoryInterface $account->order = 0; continue; } - if ($index !== (int) $account->order) { + if ($index !== (int)$account->order) { Log::debug(sprintf('Account #%d ("%s"): order should %d be but is %d.', $account->id, $account->name, $index, $account->order)); $account->order = $index; $account->save(); @@ -676,9 +690,9 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param string $query - * @param array $types - * @param int $limit + * @param string $query + * @param array $types + * @param int $limit * * @return Collection */ @@ -745,15 +759,7 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param array $data + * @param array $data * * @return Account * @throws FireflyException @@ -769,8 +775,8 @@ class AccountRepository implements AccountRepositoryInterface } /** - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data * * @return Account * @throws FireflyException diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 8f585ad173..85b26128aa 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -1,4 +1,5 @@ id; $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency; $return['sums'][$currency->id] = $return['sums'][$currency->id] ?? [ - 'start' => '0', - 'end' => '0', - 'difference' => '0', - 'currency_id' => $currency->id, - 'currency_code' => $currency->code, - 'currency_symbol' => $currency->symbol, - 'currency_name' => $currency->name, - 'currency_decimal_places' => $currency->decimal_places,]; + 'start' => '0', + 'end' => '0', + 'difference' => '0', + 'currency_id' => $currency->id, + 'currency_code' => $currency->code, + 'currency_symbol' => $currency->symbol, + 'currency_name' => $currency->name, + 'currency_decimal_places' => $currency->decimal_places, + ]; $entry = [ 'name' => $account->name, 'id' => $account->id, @@ -114,9 +118,9 @@ class AccountTasker implements AccountTaskerInterface } /** - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts * * @return array */ @@ -140,7 +144,7 @@ class AccountTasker implements AccountTaskerInterface // Obtain a list of columns $sum = []; foreach ($report['accounts'] as $accountId => $row) { - $sum[$accountId] = (float) $row['sum']; // intentional float + $sum[$accountId] = (float)$row['sum']; // intentional float } array_multisort($sum, SORT_ASC, $report['accounts']); @@ -149,11 +153,11 @@ class AccountTasker implements AccountTaskerInterface } /** - * @param array $array + * @param array $array * * @return array - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ private function groupExpenseByDestination(array $array): array { @@ -168,22 +172,22 @@ class AccountTasker implements AccountTaskerInterface /** @var array $journal */ foreach ($array as $journal) { - $sourceId = (int) $journal['destination_account_id']; - $currencyId = (int) $journal['currency_id']; + $sourceId = (int)$journal['destination_account_id']; + $currencyId = (int)$journal['currency_id']; $key = sprintf('%s-%s', $sourceId, $currencyId); $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->find($currencyId); $report['accounts'][$key] = $report['accounts'][$key] ?? [ - 'id' => $sourceId, - 'name' => $journal['destination_account_name'], - 'sum' => '0', - 'average' => '0', - 'count' => 0, - 'currency_id' => $currencies[$currencyId]->id, - 'currency_name' => $currencies[$currencyId]->name, - 'currency_symbol' => $currencies[$currencyId]->symbol, - 'currency_code' => $currencies[$currencyId]->code, - 'currency_decimal_places' => $currencies[$currencyId]->decimal_places, - ]; + 'id' => $sourceId, + 'name' => $journal['destination_account_name'], + 'sum' => '0', + 'average' => '0', + 'count' => 0, + 'currency_id' => $currencies[$currencyId]->id, + 'currency_name' => $currencies[$currencyId]->name, + 'currency_symbol' => $currencies[$currencyId]->symbol, + 'currency_code' => $currencies[$currencyId]->code, + 'currency_decimal_places' => $currencies[$currencyId]->decimal_places, + ]; $report['accounts'][$key]['sum'] = bcadd($report['accounts'][$key]['sum'], $journal['amount']); Log::debug(sprintf('Sum for %s is now %s', $journal['destination_account_name'], $report['accounts'][$key]['sum'])); @@ -194,17 +198,17 @@ class AccountTasker implements AccountTaskerInterface // do averages and sums. foreach (array_keys($report['accounts']) as $key) { if ($report['accounts'][$key]['count'] > 1) { - $report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string) $report['accounts'][$key]['count']); + $report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string)$report['accounts'][$key]['count']); } $currencyId = $report['accounts'][$key]['currency_id']; $report['sums'][$currencyId] = $report['sums'][$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $report['accounts'][$key]['currency_id'], - 'currency_name' => $report['accounts'][$key]['currency_name'], - 'currency_symbol' => $report['accounts'][$key]['currency_symbol'], - 'currency_code' => $report['accounts'][$key]['currency_code'], - 'currency_decimal_places' => $report['accounts'][$key]['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $report['accounts'][$key]['currency_id'], + 'currency_name' => $report['accounts'][$key]['currency_name'], + 'currency_symbol' => $report['accounts'][$key]['currency_symbol'], + 'currency_code' => $report['accounts'][$key]['currency_code'], + 'currency_decimal_places' => $report['accounts'][$key]['currency_decimal_places'], + ]; $report['sums'][$currencyId]['sum'] = bcadd($report['sums'][$currencyId]['sum'], $report['accounts'][$key]['sum']); } @@ -212,9 +216,9 @@ class AccountTasker implements AccountTaskerInterface } /** - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts * * @return array */ @@ -235,7 +239,7 @@ class AccountTasker implements AccountTaskerInterface // Obtain a list of columns $sum = []; foreach ($report['accounts'] as $accountId => $row) { - $sum[$accountId] = (float) $row['sum']; // intentional float + $sum[$accountId] = (float)$row['sum']; // intentional float } array_multisort($sum, SORT_DESC, $report['accounts']); @@ -244,11 +248,11 @@ class AccountTasker implements AccountTaskerInterface } /** - * @param array $array + * @param array $array * * @return array - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ private function groupIncomeBySource(array $array): array { @@ -263,8 +267,8 @@ class AccountTasker implements AccountTaskerInterface /** @var array $journal */ foreach ($array as $journal) { - $sourceId = (int) $journal['source_account_id']; - $currencyId = (int) $journal['currency_id']; + $sourceId = (int)$journal['source_account_id']; + $currencyId = (int)$journal['currency_id']; $key = sprintf('%s-%s', $sourceId, $currencyId); if (!array_key_exists($key, $report['accounts'])) { $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->find($currencyId); @@ -288,17 +292,17 @@ class AccountTasker implements AccountTaskerInterface // do averages and sums. foreach (array_keys($report['accounts']) as $key) { if ($report['accounts'][$key]['count'] > 1) { - $report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string) $report['accounts'][$key]['count']); + $report['accounts'][$key]['average'] = bcdiv($report['accounts'][$key]['sum'], (string)$report['accounts'][$key]['count']); } $currencyId = $report['accounts'][$key]['currency_id']; $report['sums'][$currencyId] = $report['sums'][$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $report['accounts'][$key]['currency_id'], - 'currency_name' => $report['accounts'][$key]['currency_name'], - 'currency_symbol' => $report['accounts'][$key]['currency_symbol'], - 'currency_code' => $report['accounts'][$key]['currency_code'], - 'currency_decimal_places' => $report['accounts'][$key]['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $report['accounts'][$key]['currency_id'], + 'currency_name' => $report['accounts'][$key]['currency_name'], + 'currency_symbol' => $report['accounts'][$key]['currency_symbol'], + 'currency_code' => $report['accounts'][$key]['currency_code'], + 'currency_decimal_places' => $report['accounts'][$key]['currency_decimal_places'], + ]; $report['sums'][$currencyId]['sum'] = bcadd($report['sums'][$currencyId]['sum'], $report['accounts'][$key]['sum']); } @@ -306,7 +310,7 @@ class AccountTasker implements AccountTaskerInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { diff --git a/app/Repositories/Account/AccountTaskerInterface.php b/app/Repositories/Account/AccountTaskerInterface.php index cc6f68eed7..d7ff2c184d 100644 --- a/app/Repositories/Account/AccountTaskerInterface.php +++ b/app/Repositories/Account/AccountTaskerInterface.php @@ -1,4 +1,5 @@ user = $user; + } + + /** + * @param array $journals + * @param string $direction * * @return array */ @@ -87,20 +95,20 @@ class OperationsRepository implements OperationsRepositoryInterface { $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $journalId = (int) $journal['transaction_journal_id']; + $currencyId = (int)$journal['currency_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'currency_id' => $journal['currency_id'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - 'transaction_journals' => [], - ]; + 'currency_id' => $journal['currency_id'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + 'transaction_journals' => [], + ]; $array[$currencyId]['transaction_journals'][$journalId] = [ - 'amount' => app('steam')->$direction((string) $journal['amount']), + 'amount' => app('steam')->$direction((string)$journal['amount']), 'date' => $journal['date'], 'transaction_journal_id' => $journalId, 'budget_name' => $journal['budget_name'], @@ -125,9 +133,9 @@ class OperationsRepository implements OperationsRepositoryInterface * which have the specified accounts. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -138,14 +146,6 @@ class OperationsRepository implements OperationsRepositoryInterface return $this->sortByCurrency($journals, 'positive'); } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * @inheritDoc */ @@ -162,12 +162,12 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $opposing - * @param TransactionCurrency|null $currency - * @param string $type + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $opposing + * @param TransactionCurrency|null $currency + * @param string $type * * @return array */ @@ -246,8 +246,8 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param array $journals - * @param string $direction + * @param array $journals + * @param string $direction * * @return array */ @@ -256,28 +256,28 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->$direction($journal['amount'])); // also do foreign amount: - $foreignId = (int) $journal['foreign_currency_id']; + $foreignId = (int)$journal['foreign_currency_id']; if (0 !== $foreignId) { $array[$foreignId] = $array[$foreignId] ?? [ - 'sum' => '0', - 'currency_id' => $foreignId, - 'currency_name' => $journal['foreign_currency_name'], - 'currency_symbol' => $journal['foreign_currency_symbol'], - 'currency_code' => $journal['foreign_currency_code'], - 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $foreignId, + 'currency_name' => $journal['foreign_currency_name'], + 'currency_symbol' => $journal['foreign_currency_symbol'], + 'currency_code' => $journal['foreign_currency_code'], + 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], + ]; $array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->$direction($journal['foreign_amount'])); } } @@ -301,9 +301,9 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param array $journals - * @param string $direction - * @param string $method + * @param array $journals + * @param string $direction + * @param string $method * * @return array */ @@ -316,31 +316,31 @@ class OperationsRepository implements OperationsRepositoryInterface foreach ($journals as $journal) { $key = sprintf('%s-%s', $journal[$idKey], $journal['currency_id']); $array[$key] = $array[$key] ?? [ + 'id' => $journal[$idKey], + 'name' => $journal[$nameKey], + 'sum' => '0', + 'currency_id' => $journal['currency_id'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; + $array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['amount'])); + + // also do foreign amount: + if (0 !== (int)$journal['foreign_currency_id']) { + $key = sprintf('%s-%s', $journal[$idKey], $journal['foreign_currency_id']); + $array[$key] = $array[$key] ?? [ 'id' => $journal[$idKey], 'name' => $journal[$nameKey], 'sum' => '0', - 'currency_id' => $journal['currency_id'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], + 'currency_id' => $journal['foreign_currency_id'], + 'currency_name' => $journal['foreign_currency_name'], + 'currency_symbol' => $journal['foreign_currency_symbol'], + 'currency_code' => $journal['foreign_currency_code'], + 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], ]; - $array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string) $journal['amount'])); - - // also do foreign amount: - if (0 !== (int) $journal['foreign_currency_id']) { - $key = sprintf('%s-%s', $journal[$idKey], $journal['foreign_currency_id']); - $array[$key] = $array[$key] ?? [ - 'id' => $journal[$idKey], - 'name' => $journal[$nameKey], - 'sum' => '0', - 'currency_id' => $journal['foreign_currency_id'], - 'currency_name' => $journal['foreign_currency_name'], - 'currency_symbol' => $journal['foreign_currency_symbol'], - 'currency_code' => $journal['foreign_currency_code'], - 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], - ]; - $array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string) $journal['foreign_amount'])); + $array[$key]['sum'] = bcadd($array[$key]['sum'], app('steam')->$method((string)$journal['foreign_amount'])); } } @@ -418,7 +418,7 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param array $journals + * @param array $journals * * @return array */ @@ -431,9 +431,9 @@ class OperationsRepository implements OperationsRepositoryInterface } $final = []; foreach ($return as $array) { - $array['difference_float'] = (float) $array['difference']; - $array['in_float'] = (float) $array['in']; - $array['out_float'] = (float) $array['out']; + $array['difference_float'] = (float)$array['difference']; + $array['in_float'] = (float)$array['in']; + $array['out_float'] = (float)$array['out']; $final[] = $array; } @@ -441,8 +441,8 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param array $return - * @param array $journal + * @param array $return + * @param array $journal * * @return array */ @@ -457,31 +457,31 @@ class OperationsRepository implements OperationsRepositoryInterface // source first $return[$sourceKey] = $return[$sourceKey] ?? [ - 'id' => (string) $sourceId, - 'name' => $journal['source_account_name'], - 'difference' => '0', - 'difference_float' => 0, - 'in' => '0', - 'in_float' => 0, - 'out' => '0', - 'out_float' => 0, - 'currency_id' => (string) $currencyId, - 'currency_code' => $journal['currency_code'], - ]; + 'id' => (string)$sourceId, + 'name' => $journal['source_account_name'], + 'difference' => '0', + 'difference_float' => 0, + 'in' => '0', + 'in_float' => 0, + 'out' => '0', + 'out_float' => 0, + 'currency_id' => (string)$currencyId, + 'currency_code' => $journal['currency_code'], + ]; // dest next: $return[$destKey] = $return[$destKey] ?? [ - 'id' => (string) $destinationId, - 'name' => $journal['destination_account_name'], - 'difference' => '0', - 'difference_float' => 0, - 'in' => '0', - 'in_float' => 0, - 'out' => '0', - 'out_float' => 0, - 'currency_id' => (string) $currencyId, - 'currency_code' => $journal['currency_code'], - ]; + 'id' => (string)$destinationId, + 'name' => $journal['destination_account_name'], + 'difference' => '0', + 'difference_float' => 0, + 'in' => '0', + 'in_float' => 0, + 'out' => '0', + 'out_float' => 0, + 'currency_id' => (string)$currencyId, + 'currency_code' => $journal['currency_code'], + ]; // source account? money goes out! $return[$sourceKey]['out'] = bcadd($return[$sourceKey]['out'], app('steam')->negative($amount)); @@ -501,31 +501,31 @@ class OperationsRepository implements OperationsRepositoryInterface // same as above: // source first $return[$sourceKey] = $return[$sourceKey] ?? [ - 'id' => (string) $sourceId, - 'name' => $journal['source_account_name'], - 'difference' => '0', - 'difference_float' => 0, - 'in' => '0', - 'in_float' => 0, - 'out' => '0', - 'out_float' => 0, - 'currency_id' => (string) $currencyId, - 'currency_code' => $journal['foreign_currency_code'], - ]; + 'id' => (string)$sourceId, + 'name' => $journal['source_account_name'], + 'difference' => '0', + 'difference_float' => 0, + 'in' => '0', + 'in_float' => 0, + 'out' => '0', + 'out_float' => 0, + 'currency_id' => (string)$currencyId, + 'currency_code' => $journal['foreign_currency_code'], + ]; // dest next: $return[$destKey] = $return[$destKey] ?? [ - 'id' => (string) $destinationId, - 'name' => $journal['destination_account_name'], - 'difference' => '0', - 'difference_float' => 0, - 'in' => '0', - 'in_float' => 0, - 'out' => '0', - 'out_float' => 0, - 'currency_id' => (string) $currencyId, - 'currency_code' => $journal['foreign_currency_code'], - ]; + 'id' => (string)$destinationId, + 'name' => $journal['destination_account_name'], + 'difference' => '0', + 'difference_float' => 0, + 'in' => '0', + 'in_float' => 0, + 'out' => '0', + 'out_float' => 0, + 'currency_id' => (string)$currencyId, + 'currency_code' => $journal['foreign_currency_code'], + ]; // source account? money goes out! (same as above) $return[$sourceKey]['out'] = bcadd($return[$sourceKey]['out'], app('steam')->negative($amount)); $return[$sourceKey]['difference'] = bcadd($return[$sourceKey]['out'], $return[$sourceKey]['in']); diff --git a/app/Repositories/Account/OperationsRepositoryInterface.php b/app/Repositories/Account/OperationsRepositoryInterface.php index cd16d830c8..e70e27f4a4 100644 --- a/app/Repositories/Account/OperationsRepositoryInterface.php +++ b/app/Repositories/Account/OperationsRepositoryInterface.php @@ -38,9 +38,9 @@ interface OperationsRepositoryInterface * which have the specified accounts. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts * * @return array */ @@ -51,27 +51,27 @@ interface OperationsRepositoryInterface * which have the specified accounts. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** * Sum of withdrawal journals in period for a set of accounts, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $expense - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $expense + * @param TransactionCurrency|null $currency * * @return array */ @@ -86,11 +86,11 @@ interface OperationsRepositoryInterface /** * Sum of withdrawal journals in period for a set of accounts, grouped per destination / currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $expense - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $expense + * @param TransactionCurrency|null $currency * * @return array */ @@ -105,11 +105,11 @@ interface OperationsRepositoryInterface /** * Sum of withdrawal journals in period for a set of accounts, grouped per source / currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $expense - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $expense + * @param TransactionCurrency|null $currency * * @return array */ @@ -124,11 +124,11 @@ interface OperationsRepositoryInterface /** * Sum of income journals in period for a set of accounts, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $revenue - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $revenue + * @param TransactionCurrency|null $currency * * @return array */ @@ -143,16 +143,16 @@ interface OperationsRepositoryInterface /** * Sum of income journals in period for a set of accounts, grouped per destination + currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $revenue - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $revenue + * @param TransactionCurrency|null $currency * * @return array */ public function sumIncomeByDestination( - Carbon $start, + Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, @@ -162,16 +162,16 @@ interface OperationsRepositoryInterface /** * Sum of income journals in period for a set of accounts, grouped per source + currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $revenue - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $revenue + * @param TransactionCurrency|null $currency * * @return array */ public function sumIncomeBySource( - Carbon $start, + Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $revenue = null, @@ -181,10 +181,10 @@ interface OperationsRepositoryInterface /** * Sum of transfers in period for a set of accounts, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param TransactionCurrency|null $currency * * @return array */ diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php index b0e79c31d1..5fde3a1261 100644 --- a/app/Repositories/Attachment/AttachmentRepository.php +++ b/app/Repositories/Attachment/AttachmentRepository.php @@ -1,4 +1,5 @@ fileName(); + $unencryptedContent = ''; + + if ($disk->exists($file)) { + $encryptedContent = (string)$disk->get($file); + + try { + $unencryptedContent = Crypt::decrypt($encryptedContent); // verified + } catch (DecryptException $e) { + $unencryptedContent = $encryptedContent; + } + } + + return $unencryptedContent; + } + + /** + * @param Attachment $attachment * * @return bool */ @@ -86,35 +112,10 @@ class AttachmentRepository implements AttachmentRepositoryInterface return $this->user->attachments()->get(); } - /** - * @param Attachment $attachment - * - * @return string - */ - public function getContent(Attachment $attachment): string - { - // create a disk. - $disk = Storage::disk('upload'); - $file = $attachment->fileName(); - $unencryptedContent = ''; - - if ($disk->exists($file)) { - $encryptedContent = (string) $disk->get($file); - - try { - $unencryptedContent = Crypt::decrypt($encryptedContent); // verified - } catch (DecryptException $e) { - $unencryptedContent = $encryptedContent; - } - } - - return $unencryptedContent; - } - /** * Get attachment note text or empty string. * - * @param Attachment $attachment + * @param Attachment $attachment * * @return string|null */ @@ -122,22 +123,14 @@ class AttachmentRepository implements AttachmentRepositoryInterface { $note = $attachment->notes()->first(); if (null !== $note) { - return (string) $note->text; + return (string)$note->text; } return null; } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param array $data + * @param array $data * * @return Attachment * @throws FireflyException @@ -156,8 +149,16 @@ class AttachmentRepository implements AttachmentRepositoryInterface } /** - * @param Attachment $attachment - * @param array $data + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + + /** + * @param Attachment $attachment + * @param array $data * * @return Attachment * @throws Exception @@ -168,28 +169,28 @@ class AttachmentRepository implements AttachmentRepositoryInterface $attachment->title = $data['title']; } - if (array_key_exists('filename', $data) && '' !== (string) $data['filename'] && $data['filename'] !== $attachment->filename) { + if (array_key_exists('filename', $data) && '' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) { $attachment->filename = $data['filename']; } // update model (move attachment) // should be validated already: if (array_key_exists('attachable_type', $data) && array_key_exists('attachable_id', $data)) { - $attachment->attachable_id = (int) $data['attachable_id']; + $attachment->attachable_id = (int)$data['attachable_id']; $attachment->attachable_type = sprintf('FireflyIII\\Models\\%s', $data['attachable_type']); } $attachment->save(); $attachment->refresh(); if (array_key_exists('notes', $data)) { - $this->updateNote($attachment, (string) $data['notes']); + $this->updateNote($attachment, (string)$data['notes']); } return $attachment; } /** - * @param Attachment $attachment - * @param string $note + * @param Attachment $attachment + * @param string $note * * @return bool * @throws Exception diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.php index 0b64420736..50d2d3b8a9 100644 --- a/app/Repositories/Attachment/AttachmentRepositoryInterface.php +++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php @@ -1,4 +1,5 @@ id)->where('auditable_type', get_class($model))->get(); + } + /** * @inheritDoc */ @@ -48,12 +56,4 @@ class ALERepository implements ALERepositoryInterface $auditLogEntry->save(); return $auditLogEntry; } - - /** - * @inheritDoc - */ - public function getForObject(Model $model): Collection - { - return AuditLogEntry::where('auditable_id', $model->id)->where('auditable_type', get_class($model))->get(); - } } diff --git a/app/Repositories/AuditLogEntry/ALERepositoryInterface.php b/app/Repositories/AuditLogEntry/ALERepositoryInterface.php index 052ca28d4e..26117f8457 100644 --- a/app/Repositories/AuditLogEntry/ALERepositoryInterface.php +++ b/app/Repositories/AuditLogEntry/ALERepositoryInterface.php @@ -34,14 +34,14 @@ use Illuminate\Support\Collection; interface ALERepositoryInterface { /** - * @param array $data - * @return AuditLogEntry - */ - public function store(array $data): AuditLogEntry; - - /** - * @param Model $model + * @param Model $model * @return Collection */ public function getForObject(Model $model): Collection; + + /** + * @param array $data + * @return AuditLogEntry + */ + public function store(array $data): AuditLogEntry; } diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 59671f0298..462101a871 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -1,4 +1,5 @@ user->bills()->orderBy('order', 'ASC')->get(); - $current = 1; - foreach ($set as $bill) { - if ((int) $bill->order !== $current) { - $bill->order = $current; - $bill->save(); - } - $current++; - } - } - - /** - * @param Bill $bill - * - * @return bool - * - - */ - public function destroy(Bill $bill): bool - { - /** @var BillDestroyService $service */ - $service = app(BillDestroyService::class); - $service->destroy($bill); - - return true; - } - - /** - * @inheritDoc - */ - public function destroyAll(): void - { - $this->user->bills()->delete(); - } - - /** - * Find bill by parameters. - * - * @param int|null $billId - * @param string|null $billName - * - * @return Bill|null - */ - public function findBill(?int $billId, ?string $billName): ?Bill - { - if (null !== $billId) { - $searchResult = $this->find((int) $billId); - if (null !== $searchResult) { - Log::debug(sprintf('Found bill based on #%d, will return it.', $billId)); - - return $searchResult; - } - } - if (null !== $billName) { - $searchResult = $this->findByName((string) $billName); - if (null !== $searchResult) { - Log::debug(sprintf('Found bill based on "%s", will return it.', $billName)); - - return $searchResult; - } - } - Log::debug('Found nothing'); - - return null; - } - - /** - * Find a bill by ID. - * - * @param int $billId - * - * @return Bill|null - */ - public function find(int $billId): ?Bill - { - return $this->user->bills()->find($billId); - } - - /** - * Find a bill by name. - * - * @param string $name - * - * @return Bill|null - */ - public function findByName(string $name): ?Bill - { - return $this->user->bills()->where('name', $name)->first(['bills.*']); - } - - /** - * Get all attachments. - * - * @param Bill $bill - * - * @return Collection - */ - public function getAttachments(Bill $bill): Collection - { - $set = $bill->attachments()->get(); - - /** @var Storage $disk */ - $disk = Storage::disk('upload'); - - return $set->each( - static function (Attachment $attachment) use ($disk) { - $notes = $attachment->notes()->first(); - $attachment->file_exists = $disk->exists($attachment->fileName()); - $attachment->notes = $notes ? $notes->text : ''; - - return $attachment; - } - ); - } - - /** - * @return Collection - */ - public function getBills(): Collection - { - return $this->user->bills() - ->orderBy('order', 'ASC') - ->orderBy('active', 'DESC') - ->orderBy('name', 'ASC')->get(); - } - - /** - * @param Collection $accounts - * - * @return Collection - */ - public function getBillsForAccounts(Collection $accounts): Collection - { - $fields = ['bills.id', 'bills.created_at', 'bills.updated_at', 'bills.deleted_at', 'bills.user_id', 'bills.name', 'bills.amount_min', - 'bills.amount_max', 'bills.date', 'bills.transaction_currency_id', 'bills.repeat_freq', 'bills.skip', 'bills.automatch', 'bills.active',]; - $ids = $accounts->pluck('id')->toArray(); - - return $this->user->bills() - ->leftJoin( - 'transaction_journals', - static function (JoinClause $join) { - $join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at'); - } - ) - ->leftJoin( - 'transactions', - static function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); - } - ) - ->whereIn('transactions.account_id', $ids) - ->whereNull('transaction_journals.deleted_at') - ->orderBy('bills.active', 'DESC') - ->orderBy('bills.name', 'ASC') - ->groupBy($fields) - ->get($fields); - } - - /** - * Get the total amount of money paid for the users active bills in the date range given. - * This amount will be negative (they're expenses). This method is equal to - * getBillsUnpaidInRange. So the debug comments are gone. - * - * @param Carbon $start - * @param Carbon $end - * @return string - * @deprecated - */ - public function getBillsPaidInRange(Carbon $start, Carbon $end): string - { - $bills = $this->getActiveBills(); - $sum = '0'; - /** @var Bill $bill */ - foreach ($bills as $bill) { - /** @var Collection $set */ - $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); - if ($set->count() > 0) { - $journalIds = $set->pluck('id')->toArray(); - $amount = (string) Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); - $sum = bcadd($sum, $amount); - //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $amount, $sum)); - } - } - - return $sum; - } - /** * @return Collection */ @@ -309,74 +118,12 @@ class BillRepository implements BillRepositoryInterface ->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]); } - /** - * Get the total amount of money paid for the users active bills in the date range given, - * grouped per currency. - * @param Carbon $start - * @param Carbon $end - * - * @return array - * @deprecated - */ - public function getBillsPaidInRangePerCurrency(Carbon $start, Carbon $end): array - { - $bills = $this->getActiveBills(); - $return = []; - /** @var Bill $bill */ - foreach ($bills as $bill) { - /** @var Collection $set */ - $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); - $currencyId = (int) $bill->transaction_currency_id; - if ($set->count() > 0) { - $journalIds = $set->pluck('id')->toArray(); - $amount = (string) Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); - $return[$currencyId] = $return[$currencyId] ?? '0'; - $return[$currencyId] = bcadd($amount, $return[$currencyId]); - //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f (currency %d)', $amount, $return[$currencyId], $currencyId)); - } - } - - return $return; - } - - /** - * Get the total amount of money due for the users active bills in the date range given. This amount will be positive. - * - * @param Carbon $start - * @param Carbon $end - * @return string - * @deprecated - */ - public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string - { - $bills = $this->getActiveBills(); - $sum = '0'; - /** @var Bill $bill */ - foreach ($bills as $bill) { - //Log::debug(sprintf('Now at bill #%d (%s)', $bill->id, $bill->name)); - $dates = $this->getPayDatesInRange($bill, $start, $end); - $count = $bill->transactionJournals()->after($start)->before($end)->count(); - $total = $dates->count() - $count; - - //Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total)); - - if ($total > 0) { - $average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2'); - $multi = bcmul($average, (string) $total); - $sum = bcadd($sum, $multi); - //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $multi, $sum)); - } - } - - return $sum; - } - /** * Between start and end, tells you on which date(s) the bill is expected to hit. * - * @param Bill $bill - * @param Carbon $start - * @param Carbon $end + * @param Bill $bill + * @param Carbon $start + * @param Carbon $end * * @return Collection */ @@ -410,8 +157,8 @@ class BillRepository implements BillRepositoryInterface * Given a bill and a date, this method will tell you at which moment this bill expects its next * transaction. Whether or not it is there already, is not relevant. * - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return Carbon */ @@ -435,11 +182,302 @@ class BillRepository implements BillRepositoryInterface return $start; } + /** + * @param array $data + * + * @return Bill + * @throws FireflyException + */ + public function store(array $data): Bill + { + /** @var BillFactory $factory */ + $factory = app(BillFactory::class); + $factory->setUser($this->user); + + return $factory->create($data); + } + + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + + /** + * Correct order of piggies in case of issues. + */ + public function correctOrder(): void + { + $set = $this->user->bills()->orderBy('order', 'ASC')->get(); + $current = 1; + foreach ($set as $bill) { + if ((int)$bill->order !== $current) { + $bill->order = $current; + $bill->save(); + } + $current++; + } + } + + /** + * @param Bill $bill + * + * @return bool + * + + */ + public function destroy(Bill $bill): bool + { + /** @var BillDestroyService $service */ + $service = app(BillDestroyService::class); + $service->destroy($bill); + + return true; + } + + /** + * @inheritDoc + */ + public function destroyAll(): void + { + $this->user->bills()->delete(); + } + + /** + * Find bill by parameters. + * + * @param int|null $billId + * @param string|null $billName + * + * @return Bill|null + */ + public function findBill(?int $billId, ?string $billName): ?Bill + { + if (null !== $billId) { + $searchResult = $this->find((int)$billId); + if (null !== $searchResult) { + Log::debug(sprintf('Found bill based on #%d, will return it.', $billId)); + + return $searchResult; + } + } + if (null !== $billName) { + $searchResult = $this->findByName((string)$billName); + if (null !== $searchResult) { + Log::debug(sprintf('Found bill based on "%s", will return it.', $billName)); + + return $searchResult; + } + } + Log::debug('Found nothing'); + + return null; + } + + /** + * Find a bill by ID. + * + * @param int $billId + * + * @return Bill|null + */ + public function find(int $billId): ?Bill + { + return $this->user->bills()->find($billId); + } + + /** + * Find a bill by name. + * + * @param string $name + * + * @return Bill|null + */ + public function findByName(string $name): ?Bill + { + return $this->user->bills()->where('name', $name)->first(['bills.*']); + } + + /** + * Get all attachments. + * + * @param Bill $bill + * + * @return Collection + */ + public function getAttachments(Bill $bill): Collection + { + $set = $bill->attachments()->get(); + + /** @var Storage $disk */ + $disk = Storage::disk('upload'); + + return $set->each( + static function (Attachment $attachment) use ($disk) { + $notes = $attachment->notes()->first(); + $attachment->file_exists = $disk->exists($attachment->fileName()); + $attachment->notes = $notes ? $notes->text : ''; + + return $attachment; + } + ); + } + + /** + * @return Collection + */ + public function getBills(): Collection + { + return $this->user->bills() + ->orderBy('order', 'ASC') + ->orderBy('active', 'DESC') + ->orderBy('name', 'ASC')->get(); + } + + /** + * @param Collection $accounts + * + * @return Collection + */ + public function getBillsForAccounts(Collection $accounts): Collection + { + $fields = [ + 'bills.id', + 'bills.created_at', + 'bills.updated_at', + 'bills.deleted_at', + 'bills.user_id', + 'bills.name', + 'bills.amount_min', + 'bills.amount_max', + 'bills.date', + 'bills.transaction_currency_id', + 'bills.repeat_freq', + 'bills.skip', + 'bills.automatch', + 'bills.active', + ]; + $ids = $accounts->pluck('id')->toArray(); + + return $this->user->bills() + ->leftJoin( + 'transaction_journals', + static function (JoinClause $join) { + $join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at'); + } + ) + ->leftJoin( + 'transactions', + static function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0); + } + ) + ->whereIn('transactions.account_id', $ids) + ->whereNull('transaction_journals.deleted_at') + ->orderBy('bills.active', 'DESC') + ->orderBy('bills.name', 'ASC') + ->groupBy($fields) + ->get($fields); + } + + /** + * Get the total amount of money paid for the users active bills in the date range given. + * This amount will be negative (they're expenses). This method is equal to + * getBillsUnpaidInRange. So the debug comments are gone. + * + * @param Carbon $start + * @param Carbon $end + * @return string + * @deprecated + */ + public function getBillsPaidInRange(Carbon $start, Carbon $end): string + { + $bills = $this->getActiveBills(); + $sum = '0'; + /** @var Bill $bill */ + foreach ($bills as $bill) { + /** @var Collection $set */ + $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); + if ($set->count() > 0) { + $journalIds = $set->pluck('id')->toArray(); + $amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); + $sum = bcadd($sum, $amount); + //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $amount, $sum)); + } + } + + return $sum; + } + + /** + * Get the total amount of money paid for the users active bills in the date range given, + * grouped per currency. + * @param Carbon $start + * @param Carbon $end + * + * @return array + * @deprecated + */ + public function getBillsPaidInRangePerCurrency(Carbon $start, Carbon $end): array + { + $bills = $this->getActiveBills(); + $return = []; + /** @var Bill $bill */ + foreach ($bills as $bill) { + /** @var Collection $set */ + $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); + $currencyId = (int)$bill->transaction_currency_id; + if ($set->count() > 0) { + $journalIds = $set->pluck('id')->toArray(); + $amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); + $return[$currencyId] = $return[$currencyId] ?? '0'; + $return[$currencyId] = bcadd($amount, $return[$currencyId]); + //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f (currency %d)', $amount, $return[$currencyId], $currencyId)); + } + } + + return $return; + } + + /** + * Get the total amount of money due for the users active bills in the date range given. This amount will be positive. + * + * @param Carbon $start + * @param Carbon $end + * @return string + * @deprecated + */ + public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string + { + $bills = $this->getActiveBills(); + $sum = '0'; + /** @var Bill $bill */ + foreach ($bills as $bill) { + //Log::debug(sprintf('Now at bill #%d (%s)', $bill->id, $bill->name)); + $dates = $this->getPayDatesInRange($bill, $start, $end); + $count = $bill->transactionJournals()->after($start)->before($end)->count(); + $total = $dates->count() - $count; + + //Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total)); + + if ($total > 0) { + $average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2'); + $multi = bcmul($average, (string)$total); + $sum = bcadd($sum, $multi); + //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f', $multi, $sum)); + } + } + + return $sum; + } + /** * Get the total amount of money due for the users active bills in the date range given. * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * @return array * @deprecated */ @@ -453,13 +491,13 @@ class BillRepository implements BillRepositoryInterface $dates = $this->getPayDatesInRange($bill, $start, $end); $count = $bill->transactionJournals()->after($start)->before($end)->count(); $total = $dates->count() - $count; - $currencyId = (int) $bill->transaction_currency_id; + $currencyId = (int)$bill->transaction_currency_id; //Log::debug(sprintf('Dates = %d, journalCount = %d, total = %d', $dates->count(), $count, $total)); if ($total > 0) { - $average = bcdiv(bcadd((string) $bill->amount_max, (string) $bill->amount_min), '2'); - $multi = bcmul($average, (string) $total); + $average = bcdiv(bcadd((string)$bill->amount_max, (string)$bill->amount_min), '2'); + $multi = bcmul($average, (string)$total); $return[$currencyId] = $return[$currencyId] ?? '0'; $return[$currencyId] = bcadd($return[$currencyId], $multi); //Log::debug(sprintf('Total > 0, so add to sum %f, which becomes %f (for currency %d)', $multi, $return[$currencyId], $currencyId)); @@ -469,70 +507,10 @@ class BillRepository implements BillRepositoryInterface return $return; } - /** - * @inheritDoc - */ - public function sumUnpaidInRange(Carbon $start, Carbon $end): array - { - $bills = $this->getActiveBills(); - $return = []; - /** @var Bill $bill */ - foreach ($bills as $bill) { - $dates = $this->getPayDatesInRange($bill, $start, $end); - $count = $bill->transactionJournals()->after($start)->before($end)->count(); - $total = $dates->count() - $count; - - if ($total > 0) { - $currency = $bill->transactionCurrency; - $average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2'); - $return[$currency->id] = $return[$currency->id] ?? [ - 'id' => (string) $currency->id, - 'name' => $currency->name, - 'symbol' => $currency->symbol, - 'code' => $currency->code, - 'decimal_places' => $currency->decimal_places, - 'sum' => '0', - ]; - $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], bcmul($average, (string) $total)); - } - } - - return $return; - } - - /** - * @inheritDoc - */ - public function sumPaidInRange(Carbon $start, Carbon $end): array - { - $bills = $this->getActiveBills(); - $return = []; - /** @var Bill $bill */ - foreach ($bills as $bill) { - /** @var Collection $set */ - $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); - $currency = $bill->transactionCurrency; - if ($set->count() > 0) { - $journalIds = $set->pluck('id')->toArray(); - $amount = (string) Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); - $return[$currency->id] = $return[$currency->id] ?? [ - 'id' => (string) $currency->id, - 'name' => $currency->name, - 'symbol' => $currency->symbol, - 'code' => $currency->code, - 'decimal_places' => $currency->decimal_places, - 'sum' => '0', - ]; - $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount); - } - } - return $return; - } - /** * Get all bills with these ID's. * - * @param array $billIds + * @param array $billIds * * @return Collection */ @@ -544,7 +522,7 @@ class BillRepository implements BillRepositoryInterface /** * Get text or return empty string. * - * @param Bill $bill + * @param Bill $bill * * @return string */ @@ -553,14 +531,14 @@ class BillRepository implements BillRepositoryInterface /** @var Note $note */ $note = $bill->notes()->first(); if (null !== $note) { - return (string) $note->text; + return (string)$note->text; } return ''; } /** - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -578,35 +556,35 @@ class BillRepository implements BillRepositoryInterface foreach ($journals as $journal) { /** @var Transaction $transaction */ $transaction = $journal->transactions()->where('amount', '<', 0)->first(); - $currencyId = (int) $journal->transaction_currency_id; + $currencyId = (int)$journal->transaction_currency_id; $currency = $journal->transactionCurrency; $result[$currencyId] = $result[$currencyId] ?? [ - 'sum' => '0', - 'count' => 0, - 'avg' => '0', - 'currency_id' => $currency->id, - 'currency_code' => $currency->code, - 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => $currency->decimal_places, - ]; + 'sum' => '0', + 'count' => 0, + 'avg' => '0', + 'currency_id' => $currency->id, + 'currency_code' => $currency->code, + 'currency_symbol' => $currency->symbol, + 'currency_decimal_places' => $currency->decimal_places, + ]; $result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount); $result[$currencyId]['count']++; } // after loop, re-loop for avg. /** - * @var int $currencyId + * @var int $currencyId * @var array $arr */ foreach ($result as $currencyId => $arr) { - $result[$currencyId]['avg'] = bcdiv($arr['sum'], (string) $arr['count']); + $result[$currencyId]['avg'] = bcdiv($arr['sum'], (string)$arr['count']); } return $result; } /** - * @param int $size + * @param int $size * * @return LengthAwarePaginator */ @@ -620,9 +598,9 @@ class BillRepository implements BillRepositoryInterface /** * The "paid dates" list is a list of dates of transaction journals that are linked to this bill. * - * @param Bill $bill - * @param Carbon $start - * @param Carbon $end + * @param Bill $bill + * @param Carbon $start + * @param Carbon $end * * @return Collection */ @@ -633,7 +611,8 @@ class BillRepository implements BillRepositoryInterface return $bill->transactionJournals() ->before($end)->after($start)->get( [ - 'transaction_journals.id', 'transaction_journals.date', + 'transaction_journals.id', + 'transaction_journals.date', 'transaction_journals.transaction_group_id', ] ); @@ -642,7 +621,7 @@ class BillRepository implements BillRepositoryInterface /** * Return all rules for one bill * - * @param Bill $bill + * @param Bill $bill * * @return Collection */ @@ -661,7 +640,7 @@ class BillRepository implements BillRepositoryInterface * * 5 => [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']] * - * @param Collection $collection + * @param Collection $collection * * @return array */ @@ -686,8 +665,8 @@ class BillRepository implements BillRepositoryInterface } /** - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return array */ @@ -701,8 +680,8 @@ class BillRepository implements BillRepositoryInterface $result = []; $journals = $bill->transactionJournals() - ->where('date', '>=', $date->year . '-01-01 00:00:00') - ->where('date', '<=', $date->year . '-12-31 23:59:59') + ->where('date', '>=', $date->year.'-01-01 00:00:00') + ->where('date', '<=', $date->year.'-12-31 23:59:59') ->get(); /** @var TransactionJournal $journal */ @@ -712,28 +691,28 @@ class BillRepository implements BillRepositoryInterface if (null === $transaction) { continue; } - $currencyId = (int) $journal->transaction_currency_id; + $currencyId = (int)$journal->transaction_currency_id; $currency = $journal->transactionCurrency; $result[$currencyId] = $result[$currencyId] ?? [ - 'sum' => '0', - 'count' => 0, - 'avg' => '0', - 'currency_id' => $currency->id, - 'currency_code' => $currency->code, - 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => $currency->decimal_places, - ]; + 'sum' => '0', + 'count' => 0, + 'avg' => '0', + 'currency_id' => $currency->id, + 'currency_code' => $currency->code, + 'currency_symbol' => $currency->symbol, + 'currency_decimal_places' => $currency->decimal_places, + ]; $result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], $transaction->amount); $result[$currencyId]['count']++; } // after loop, re-loop for avg. /** - * @var int $currencyId + * @var int $currencyId * @var array $arr */ foreach ($result as $currencyId => $arr) { - $result[$currencyId]['avg'] = bcdiv($arr['sum'], (string) $arr['count']); + $result[$currencyId]['avg'] = bcdiv($arr['sum'], (string)$arr['count']); } return $result; @@ -742,14 +721,14 @@ class BillRepository implements BillRepositoryInterface /** * Link a set of journals to a bill. * - * @param Bill $bill - * @param array $transactions + * @param Bill $bill + * @param array $transactions */ public function linkCollectionToBill(Bill $bill, array $transactions): void { /** @var Transaction $transaction */ foreach ($transactions as $transaction) { - $journal = $bill->user->transactionJournals()->find((int) $transaction['transaction_journal_id']); + $journal = $bill->user->transactionJournals()->find((int)$transaction['transaction_journal_id']); $journal->bill_id = $bill->id; $journal->save(); Log::debug(sprintf('Linked journal #%d to bill #%d', $journal->id, $bill->id)); @@ -759,8 +738,8 @@ class BillRepository implements BillRepositoryInterface /** * Given the date in $date, this method will return a moment in the future where the bill is expected to be paid. * - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return Carbon * @throws JsonException @@ -776,12 +755,12 @@ class BillRepository implements BillRepositoryInterface } // find the most recent date for this bill NOT in the future. Cache this date: $start = clone $bill->date; - Log::debug('nextExpectedMatch: Start is ' . $start->format('Y-m-d')); + Log::debug('nextExpectedMatch: Start is '.$start->format('Y-m-d')); while ($start < $date) { Log::debug(sprintf('$start (%s) < $date (%s)', $start->format('Y-m-d'), $date->format('Y-m-d'))); $start = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); - Log::debug('Start is now ' . $start->format('Y-m-d')); + Log::debug('Start is now '.$start->format('Y-m-d')); } $end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); @@ -795,8 +774,8 @@ class BillRepository implements BillRepositoryInterface $start = clone $end; $end = app('navigation')->addPeriod($start, $bill->repeat_freq, $bill->skip); } - Log::debug('nextExpectedMatch: Final start is ' . $start->format('Y-m-d')); - Log::debug('nextExpectedMatch: Matching end is ' . $end->format('Y-m-d')); + Log::debug('nextExpectedMatch: Final start is '.$start->format('Y-m-d')); + Log::debug('nextExpectedMatch: Matching end is '.$end->format('Y-m-d')); $cache->store($start); @@ -814,8 +793,8 @@ class BillRepository implements BillRepositoryInterface } /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ @@ -849,30 +828,67 @@ class BillRepository implements BillRepositoryInterface } /** - * @param User $user + * @inheritDoc */ - public function setUser(User $user): void + public function sumPaidInRange(Carbon $start, Carbon $end): array { - $this->user = $user; + $bills = $this->getActiveBills(); + $return = []; + /** @var Bill $bill */ + foreach ($bills as $bill) { + /** @var Collection $set */ + $set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']); + $currency = $bill->transactionCurrency; + if ($set->count() > 0) { + $journalIds = $set->pluck('id')->toArray(); + $amount = (string)Transaction::whereIn('transaction_journal_id', $journalIds)->where('amount', '<', 0)->sum('amount'); + $return[$currency->id] = $return[$currency->id] ?? [ + 'id' => (string)$currency->id, + 'name' => $currency->name, + 'symbol' => $currency->symbol, + 'code' => $currency->code, + 'decimal_places' => $currency->decimal_places, + 'sum' => '0', + ]; + $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount); + } + } + return $return; } /** - * @param array $data - * - * @return Bill - * @throws FireflyException + * @inheritDoc */ - public function store(array $data): Bill + public function sumUnpaidInRange(Carbon $start, Carbon $end): array { - /** @var BillFactory $factory */ - $factory = app(BillFactory::class); - $factory->setUser($this->user); + $bills = $this->getActiveBills(); + $return = []; + /** @var Bill $bill */ + foreach ($bills as $bill) { + $dates = $this->getPayDatesInRange($bill, $start, $end); + $count = $bill->transactionJournals()->after($start)->before($end)->count(); + $total = $dates->count() - $count; - return $factory->create($data); + if ($total > 0) { + $currency = $bill->transactionCurrency; + $average = bcdiv(bcadd($bill->amount_max, $bill->amount_min), '2'); + $return[$currency->id] = $return[$currency->id] ?? [ + 'id' => (string)$currency->id, + 'name' => $currency->name, + 'symbol' => $currency->symbol, + 'code' => $currency->code, + 'decimal_places' => $currency->decimal_places, + 'sum' => '0', + ]; + $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], bcmul($average, (string)$total)); + } + } + + return $return; } /** - * @param Bill $bill + * @param Bill $bill */ public function unlinkAll(Bill $bill): void { @@ -880,8 +896,8 @@ class BillRepository implements BillRepositoryInterface } /** - * @param Bill $bill - * @param array $data + * @param Bill $bill + * @param array $data * * @return Bill */ diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php index 4b6cfbb125..372d2da8b1 100644 --- a/app/Repositories/Bill/BillRepositoryInterface.php +++ b/app/Repositories/Bill/BillRepositoryInterface.php @@ -1,4 +1,5 @@ [['id' => 1, 'title' => 'Some rule'],['id' => 2, 'title' => 'Some other rule']] * - * @param Collection $collection + * @param Collection $collection * * @return array */ public function getRulesForBills(Collection $collection): array; /** - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return array */ @@ -276,8 +259,8 @@ interface BillRepositoryInterface /** * Link a set of journals to a bill. * - * @param Bill $bill - * @param array $transactions + * @param Bill $bill + * @param array $transactions */ public function linkCollectionToBill(Bill $bill, array $transactions): void; @@ -285,39 +268,39 @@ interface BillRepositoryInterface * Given a bill and a date, this method will tell you at which moment this bill expects its next * transaction. Whether or not it is there already, is not relevant. * - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return Carbon */ public function nextDateMatch(Bill $bill, Carbon $date): Carbon; /** - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return Carbon */ public function nextExpectedMatch(Bill $bill, Carbon $date): Carbon; /** - * @param Bill $bill + * @param Bill $bill * * @return Bill */ public function removeObjectGroup(Bill $bill): Bill; /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ public function searchBill(string $query, int $limit): Collection; /** - * @param Bill $bill - * @param string $objectGroupTitle + * @param Bill $bill + * @param string $objectGroupTitle * * @return Bill */ @@ -326,18 +309,18 @@ interface BillRepositoryInterface /** * Set specific piggy bank to specific order. * - * @param Bill $bill - * @param int $order + * @param Bill $bill + * @param int $order */ public function setOrder(Bill $bill, int $order): void; /** - * @param User $user + * @param User $user */ public function setUser(User $user); /** - * @param array $data + * @param array $data * * @return Bill * @throws FireflyException @@ -345,13 +328,31 @@ interface BillRepositoryInterface public function store(array $data): Bill; /** - * @param Bill $bill + * Collect multi-currency of sum of bills already paid. + * + * @param Carbon $start + * @param Carbon $end + * @return array + */ + public function sumPaidInRange(Carbon $start, Carbon $end): array; + + /** + * Collect multi-currency of sum of bills yet to pay. + * + * @param Carbon $start + * @param Carbon $end + * @return array + */ + public function sumUnpaidInRange(Carbon $start, Carbon $end): array; + + /** + * @param Bill $bill */ public function unlinkAll(Bill $bill): void; /** - * @param Bill $bill - * @param array $data + * @param Bill $bill + * @param array $data * * @return Bill */ diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php index 57820051d3..62983b91c1 100644 --- a/app/Repositories/Budget/AvailableBudgetRepository.php +++ b/app/Repositories/Budget/AvailableBudgetRepository.php @@ -48,7 +48,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param AvailableBudget $availableBudget + * @param AvailableBudget $availableBudget */ public function destroyAvailableBudget(AvailableBudget $availableBudget): void { @@ -59,12 +59,20 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } } + /** + * @inheritDoc + */ + public function findById(int $id): ?AvailableBudget + { + return $this->user->availableBudgets->find($id); + } + /** * Find existing AB. * - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end * * @return AvailableBudget|null */ @@ -78,18 +86,51 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @inheritDoc + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * + * @return string */ - public function findById(int $id): ?AvailableBudget + public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string { - return $this->user->availableBudgets->find($id); + $amount = '0'; + $availableBudget = $this->user->availableBudgets() + ->where('transaction_currency_id', $currency->id) + ->where('start_date', $start->format('Y-m-d')) + ->where('end_date', $end->format('Y-m-d'))->first(); + if (null !== $availableBudget) { + $amount = (string)$availableBudget->amount; + } + + return $amount; + } + + /** + * @param Carbon $start + * @param Carbon $end + * + * @return array + */ + public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array + { + $return = []; + $availableBudgets = $this->user->availableBudgets() + ->where('start_date', $start->format('Y-m-d')) + ->where('end_date', $end->format('Y-m-d'))->get(); + /** @var AvailableBudget $availableBudget */ + foreach ($availableBudgets as $availableBudget) { + $return[$availableBudget->transaction_currency_id] = $availableBudget->amount; + } + + return $return; } /** * Return a list of all available budgets (in all currencies) (for the selected period). * - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ @@ -108,51 +149,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface return $query->get(['available_budgets.*']); } - /** - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end - * - * @return string - */ - public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string - { - $amount = '0'; - $availableBudget = $this->user->availableBudgets() - ->where('transaction_currency_id', $currency->id) - ->where('start_date', $start->format('Y-m-d')) - ->where('end_date', $end->format('Y-m-d'))->first(); - if (null !== $availableBudget) { - $amount = (string) $availableBudget->amount; - } - - return $amount; - } - - /** - * @param Carbon $start - * @param Carbon $end - * - * @return array - */ - public function getAvailableBudgetWithCurrency(Carbon $start, Carbon $end): array - { - $return = []; - $availableBudgets = $this->user->availableBudgets() - ->where('start_date', $start->format('Y-m-d')) - ->where('end_date', $end->format('Y-m-d'))->get(); - /** @var AvailableBudget $availableBudget */ - foreach ($availableBudgets as $availableBudget) { - $return[$availableBudget->transaction_currency_id] = $availableBudget->amount; - } - - return $return; - } - /** * Returns all available budget objects. * - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency * * @return Collection */ @@ -164,8 +164,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface /** * Returns all available budget objects. * - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection * @@ -197,10 +197,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end - * @param string $amount + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * @param string $amount * * @return AvailableBudget * @deprecated @@ -225,7 +225,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -233,7 +233,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param array $data + * @param array $data * * @return AvailableBudget|null */ @@ -261,8 +261,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param AvailableBudget $availableBudget - * @param array $data + * @param AvailableBudget $availableBudget + * @param array $data * * @return AvailableBudget */ @@ -277,8 +277,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface } /** - * @param AvailableBudget $availableBudget - * @param array $data + * @param AvailableBudget $availableBudget + * @param array $data * * @return AvailableBudget */ diff --git a/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php b/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php index 7a4cc93b24..7537291f96 100644 --- a/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php +++ b/app/Repositories/Budget/AvailableBudgetRepositoryInterface.php @@ -40,23 +40,23 @@ interface AvailableBudgetRepositoryInterface public function destroyAll(): void; /** - * @param AvailableBudget $availableBudget + * @param AvailableBudget $availableBudget */ public function destroyAvailableBudget(AvailableBudget $availableBudget): void; /** * Find existing AB. * - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end * * @return AvailableBudget|null */ public function find(TransactionCurrency $currency, Carbon $start, Carbon $end): ?AvailableBudget; /** - * @param int $id + * @param int $id * * @return AvailableBudget|null */ @@ -65,17 +65,17 @@ interface AvailableBudgetRepositoryInterface /** * Return a list of all available budgets (in all currencies) (for the selected period). * - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ public function get(?Carbon $start = null, ?Carbon $end = null): Collection; /** - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end * * @return string * @deprecated @@ -83,8 +83,8 @@ interface AvailableBudgetRepositoryInterface public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string; /** - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -93,7 +93,7 @@ interface AvailableBudgetRepositoryInterface /** * Returns all available budget objects. * - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency * * @return Collection */ @@ -102,8 +102,8 @@ interface AvailableBudgetRepositoryInterface /** * Returns all available budget objects. * - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection * @@ -113,19 +113,19 @@ interface AvailableBudgetRepositoryInterface /** * Get by transaction currency and date. Should always result in one entry or NULL. * - * @param Carbon $start - * @param Carbon $end - * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * @param TransactionCurrency $currency * * @return null|AvailableBudget */ public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget; /** - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end - * @param string $amount + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * @param string $amount * * @return AvailableBudget * @deprecated @@ -133,28 +133,28 @@ interface AvailableBudgetRepositoryInterface public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** - * @param array $data + * @param array $data * * @return AvailableBudget|null */ public function store(array $data): ?AvailableBudget; /** - * @param AvailableBudget $availableBudget - * @param array $data + * @param AvailableBudget $availableBudget + * @param array $data * * @return AvailableBudget */ public function update(AvailableBudget $availableBudget, array $data): AvailableBudget; /** - * @param AvailableBudget $availableBudget - * @param array $data + * @param AvailableBudget $availableBudget + * @param array $data * * @return AvailableBudget */ diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.php index 43fb51fb02..e314f23551 100644 --- a/app/Repositories/Budget/BudgetLimitRepository.php +++ b/app/Repositories/Budget/BudgetLimitRepository.php @@ -48,10 +48,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface * Tells you which amount has been budgeted (for the given budgets) * in the selected query. Returns a positive amount as a string. * - * @param Carbon $start - * @param Carbon $end - * @param TransactionCurrency $currency - * @param Collection|null $budgets + * @param Carbon $start + * @param Carbon $end + * @param TransactionCurrency $currency + * @param Collection|null $budgets * * @return string */ @@ -60,37 +60,37 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface $query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') // same complex where query as below. - ->where( - static function (Builder $q5) use ($start, $end) { - $q5->where( - static function (Builder $q1) use ($start, $end) { - $q1->where( - static function (Builder $q2) use ($start, $end) { - $q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d')); - $q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d')); + ->where( + static function (Builder $q5) use ($start, $end) { + $q5->where( + static function (Builder $q1) use ($start, $end) { + $q1->where( + static function (Builder $q2) use ($start, $end) { + $q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d')); + $q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d')); + } + ) + ->orWhere( + static function (Builder $q3) use ($start, $end) { + $q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d')); + $q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d')); + } + ); + } + ) + ->orWhere( + static function (Builder $q4) use ($start, $end) { + // or start is before start AND end is after end. + $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d')); + $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d')); + } + ); } ) - ->orWhere( - static function (Builder $q3) use ($start, $end) { - $q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d')); - $q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d')); - } - ); - } - ) - ->orWhere( - static function (Builder $q4) use ($start, $end) { - // or start is before start AND end is after end. - $q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d')); - $q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d')); - } - ); - } - ) - ->where('budget_limits.transaction_currency_id', $currency->id) - ->whereNull('budgets.deleted_at') - ->where('budgets.active', true) - ->where('budgets.user_id', $this->user->id); + ->where('budget_limits.transaction_currency_id', $currency->id) + ->whereNull('budgets.deleted_at') + ->where('budgets.active', true) + ->where('budgets.user_id', $this->user->id); if (null !== $budgets && $budgets->count() > 0) { $query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray()); } @@ -120,7 +120,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface /** * Destroy a budget limit. * - * @param BudgetLimit $budgetLimit + * @param BudgetLimit $budgetLimit */ public function destroyBudgetLimit(BudgetLimit $budgetLimit): void { @@ -132,25 +132,9 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param Budget $budget - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end - * - * @return BudgetLimit|null - */ - public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit - { - return $budget->budgetlimits() - ->where('transaction_currency_id', $currency->id) - ->where('start_date', $start->format('Y-m-d')) - ->where('end_date', $end->format('Y-m-d'))->first(); - } - - /** - * @param TransactionCurrency $currency - * @param Carbon|null $start - * @param Carbon|null $end + * @param TransactionCurrency $currency + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ @@ -164,8 +148,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ @@ -232,9 +216,9 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param Budget $budget - * @param Carbon|null $start - * @param Carbon|null $end + * @param Budget $budget + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ @@ -292,7 +276,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -300,7 +284,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param array $data + * @param array $data * * @return BudgetLimit * @throws FireflyException @@ -319,7 +303,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface $currency->save(); // find the budget: - $budget = $this->user->budgets()->find((int) $data['budget_id']); + $budget = $this->user->budgets()->find((int)$data['budget_id']); if (null === $budget) { throw new FireflyException('200004: Budget does not exist.'); } @@ -349,8 +333,24 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param BudgetLimit $budgetLimit - * @param array $data + * @param Budget $budget + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end + * + * @return BudgetLimit|null + */ + public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit + { + return $budget->budgetlimits() + ->where('transaction_currency_id', $currency->id) + ->where('start_date', $start->format('Y-m-d')) + ->where('end_date', $end->format('Y-m-d'))->first(); + } + + /** + * @param BudgetLimit $budgetLimit + * @param array $data * * @return BudgetLimit * @throws FireflyException @@ -386,10 +386,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * @param string $amount + * @param Budget $budget + * @param Carbon $start + * @param Carbon $end + * @param string $amount * * @return BudgetLimit|null * diff --git a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php index ae7adc15b5..3c6c914c8a 100644 --- a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php @@ -39,10 +39,10 @@ interface BudgetLimitRepositoryInterface * Tells you which amount has been budgeted (for the given budgets) * in the selected query. Returns a positive amount as a string. * - * @param Carbon $start - * @param Carbon $end - * @param TransactionCurrency $currency - * @param Collection|null $budgets + * @param Carbon $start + * @param Carbon $end + * @param TransactionCurrency $currency + * @param Collection|null $budgets * * @return string */ @@ -56,15 +56,15 @@ interface BudgetLimitRepositoryInterface /** * Destroy a budget limit. * - * @param BudgetLimit $budgetLimit + * @param BudgetLimit $budgetLimit */ public function destroyBudgetLimit(BudgetLimit $budgetLimit): void; /** - * @param Budget $budget - * @param TransactionCurrency $currency - * @param Carbon $start - * @param Carbon $end + * @param Budget $budget + * @param TransactionCurrency $currency + * @param Carbon $start + * @param Carbon $end * * @return BudgetLimit|null */ @@ -73,56 +73,56 @@ interface BudgetLimitRepositoryInterface /** * TODO this method is not multi currency aware. * - * @param Carbon|null $start - * @param Carbon|null $end + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ public function getAllBudgetLimits(Carbon $start = null, Carbon $end = null): Collection; /** - * @param TransactionCurrency $currency - * @param Carbon|null $start - * @param Carbon|null $end + * @param TransactionCurrency $currency + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, Carbon $start = null, Carbon $end = null): Collection; /** - * @param Budget $budget - * @param Carbon|null $start - * @param Carbon|null $end + * @param Budget $budget + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ public function getBudgetLimits(Budget $budget, Carbon $start = null, Carbon $end = null): Collection; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** - * @param array $data + * @param array $data * * @return BudgetLimit */ public function store(array $data): BudgetLimit; /** - * @param BudgetLimit $budgetLimit - * @param array $data + * @param BudgetLimit $budgetLimit + * @param array $data * * @return BudgetLimit */ public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit; /** - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end - * @param string $amount + * @param Budget $budget + * @param Carbon $start + * @param Carbon $end + * @param string $amount * * @return BudgetLimit|null */ diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index c5586f8297..549d7487b9 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -1,4 +1,5 @@ id)); $currency = $limit->transactionCurrency; $return[$currency->id] = $return[$currency->id] ?? [ - 'id' => (string) $currency->id, - 'name' => $currency->name, - 'symbol' => $currency->symbol, - 'code' => $currency->code, - 'decimal_places' => $currency->decimal_places, - 'sum' => '0', - ]; + 'id' => (string)$currency->id, + 'name' => $currency->name, + 'symbol' => $currency->symbol, + 'code' => $currency->code, + 'decimal_places' => $currency->decimal_places, + 'sum' => '0', + ]; // same period if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) { - $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string) $limit->amount); + $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount); Log::debug(sprintf('Add full amount [1]: %s', $limit->amount)); continue; } // limit is inside of date range if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) { - $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string) $limit->amount); + $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string)$limit->amount); Log::debug(sprintf('Add full amount [2]: %s', $limit->amount)); continue; } $total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself. $days = $this->daysInOverlap($limit, $start, $end); - $amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days); + $amount = bcmul(bcdiv((string)$limit->amount, (string)$total), (string)$days); $return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount); - Log::debug(sprintf( - 'Amount per day: %s (%s over %d days). Total amount for %d days: %s', - bcdiv((string) $limit->amount, (string) $total), - $limit->amount, - $total, - $days, - $amount - )); + Log::debug( + sprintf( + 'Amount per day: %s (%s over %d days). Total amount for %d days: %s', + bcdiv((string)$limit->amount, (string)$total), + $limit->amount, + $total, + $days, + $amount + ) + ); } } return $return; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @return Collection */ @@ -155,9 +166,9 @@ class BudgetRepository implements BudgetRepositoryInterface /** * How many days of this budget limit are between start and end? * - * @param BudgetLimit $limit - * @param Carbon $start - * @param Carbon $end + * @param BudgetLimit $limit + * @param Carbon $start + * @param Carbon $end * @return int */ private function daysInOverlap(BudgetLimit $limit, Carbon $start, Carbon $end): int @@ -203,7 +214,7 @@ class BudgetRepository implements BudgetRepositoryInterface } $budgets = $this->getActiveBudgets(); /** - * @var int $index + * @var int $index * @var Budget $budget */ foreach ($budgets as $index => $budget) { @@ -217,7 +228,193 @@ class BudgetRepository implements BudgetRepositoryInterface } /** - * @param Budget $budget + * @param Budget $budget + * @param array $data + * + * @return Budget + */ + public function update(Budget $budget, array $data): Budget + { + Log::debug('Now in update()'); + + $oldName = $budget->name; + if (array_key_exists('name', $data)) { + $budget->name = $data['name']; + $this->updateRuleActions($oldName, $budget->name); + $this->updateRuleTriggers($oldName, $budget->name); + } + if (array_key_exists('active', $data)) { + $budget->active = $data['active']; + } + if (array_key_exists('notes', $data)) { + $this->setNoteText($budget, (string)$data['notes']); + } + $budget->save(); + + // update or create auto-budget: + $autoBudget = $this->getAutoBudget($budget); + + // first things first: delete when no longer required: + $autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null; + + if (0 === $autoBudgetType && null !== $autoBudget) { + // delete! + $autoBudget->delete(); + + return $budget; + } + if (0 === $autoBudgetType && null === $autoBudget) { + return $budget; + } + if (null === $autoBudgetType && null === $autoBudget) { + return $budget; + } + $this->updateAutoBudget($budget, $data); + + return $budget; + } + + /** + * @param string $oldName + * @param string $newName + */ + private function updateRuleActions(string $oldName, string $newName): void + { + $types = ['set_budget',]; + $actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id') + ->where('rules.user_id', $this->user->id) + ->whereIn('rule_actions.action_type', $types) + ->where('rule_actions.action_value', $oldName) + ->get(['rule_actions.*']); + Log::debug(sprintf('Found %d actions to update.', $actions->count())); + /** @var RuleAction $action */ + foreach ($actions as $action) { + $action->action_value = $newName; + $action->save(); + Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value)); + } + } + + /** + * @param string $oldName + * @param string $newName + */ + private function updateRuleTriggers(string $oldName, string $newName): void + { + $types = ['budget_is',]; + $triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id') + ->where('rules.user_id', $this->user->id) + ->whereIn('rule_triggers.trigger_type', $types) + ->where('rule_triggers.trigger_value', $oldName) + ->get(['rule_triggers.*']); + Log::debug(sprintf('Found %d triggers to update.', $triggers->count())); + /** @var RuleTrigger $trigger */ + foreach ($triggers as $trigger) { + $trigger->trigger_value = $newName; + $trigger->save(); + Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value)); + } + } + + /** + * @param Budget $budget + * @param string $text + * @return void + */ + private function setNoteText(Budget $budget, string $text): void + { + $dbNote = $budget->notes()->first(); + if ('' !== $text) { + if (null === $dbNote) { + $dbNote = new Note(); + $dbNote->noteable()->associate($budget); + } + $dbNote->text = trim($text); + $dbNote->save(); + + return; + } + if (null !== $dbNote) { + try { + $dbNote->delete(); + } catch (Exception $e) { + // @ignoreException + } + } + } + + /** + * @inheritDoc + */ + public function getAutoBudget(Budget $budget): ?AutoBudget + { + return $budget->autoBudgets()->first(); + } + + /** + * @param Budget $budget + * @param array $data + * @throws FireflyException + * @throws JsonException + */ + private function updateAutoBudget(Budget $budget, array $data): void + { + // update or create auto-budget: + $autoBudget = $this->getAutoBudget($budget); + + // grab default currency: + $currency = app('amount')->getDefaultCurrencyByUser($this->user); + + if (null === $autoBudget) { + // at this point it's a blind assumption auto_budget_type is 1 or 2. + $autoBudget = new AutoBudget(); + $autoBudget->auto_budget_type = $data['auto_budget_type']; + $autoBudget->budget_id = $budget->id; + $autoBudget->transaction_currency_id = $currency->id; + } + + // set or update the currency. + if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) { + $repos = app(CurrencyRepositoryInterface::class); + $currencyId = (int)($data['currency_id'] ?? 0); + $currencyCode = (string)($data['currency_code'] ?? ''); + $currency = $repos->find($currencyId); + if (null === $currency) { + $currency = $repos->findByCodeNull($currencyCode); + } + if (null !== $currency) { + $autoBudget->transaction_currency_id = $currency->id; + } + } + + // change values if submitted or presented: + if (array_key_exists('auto_budget_type', $data)) { + $autoBudget->auto_budget_type = $data['auto_budget_type']; + } + if (array_key_exists('auto_budget_amount', $data)) { + $autoBudget->amount = $data['auto_budget_amount']; + } + if (array_key_exists('auto_budget_period', $data)) { + $autoBudget->period = $data['auto_budget_period']; + } + + $autoBudget->save(); + } + + /** + * Find a budget or return NULL + * + * @param int|null $budgetId |null + * + * @return Budget|null + */ + public function find(int $budgetId = null): ?Budget + { + return $this->user->budgets()->find($budgetId); + } + + /** + * @param Budget $budget * * @return bool */ @@ -238,10 +435,10 @@ class BudgetRepository implements BudgetRepositoryInterface $budgets = $this->getBudgets(); /** @var Budget $budget */ foreach ($budgets as $budget) { - DB::table('budget_transaction')->where('budget_id', (int) $budget->id)->delete(); - DB::table('budget_transaction_journal')->where('budget_id', (int) $budget->id)->delete(); - RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string) $budget->id)->delete(); - RuleAction::where('action_type', 'set_budget')->where('action_value', (string) $budget->id)->delete(); + DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete(); + DB::table('budget_transaction_journal')->where('budget_id', (int)$budget->id)->delete(); + RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', (string)$budget->id)->delete(); + RuleAction::where('action_type', 'set_budget')->where('action_value', (string)$budget->id)->delete(); $budget->delete(); } } @@ -267,8 +464,8 @@ class BudgetRepository implements BudgetRepositoryInterface } /** - * @param int|null $budgetId - * @param string|null $budgetName + * @param int|null $budgetId + * @param string|null $budgetName * * @return Budget|null */ @@ -276,10 +473,10 @@ class BudgetRepository implements BudgetRepositoryInterface { Log::debug('Now in findBudget()'); Log::debug(sprintf('Searching for budget with ID #%d...', $budgetId)); - $result = $this->find((int) $budgetId); + $result = $this->find((int)$budgetId); if (null === $result && null !== $budgetName && '' !== $budgetName) { Log::debug(sprintf('Searching for budget with name %s...', $budgetName)); - $result = $this->findByName((string) $budgetName); + $result = $this->findByName((string)$budgetName); } if (null !== $result) { Log::debug(sprintf('Found budget #%d: %s', $result->id, $result->name)); @@ -289,22 +486,10 @@ class BudgetRepository implements BudgetRepositoryInterface return $result; } - /** - * Find a budget or return NULL - * - * @param int|null $budgetId |null - * - * @return Budget|null - */ - public function find(int $budgetId = null): ?Budget - { - return $this->user->budgets()->find($budgetId); - } - /** * Find budget by name. * - * @param string|null $name + * @param string|null $name * * @return Budget|null */ @@ -322,7 +507,7 @@ class BudgetRepository implements BudgetRepositoryInterface * This method returns the oldest journal or transaction date known to this budget. * Will cache result. * - * @param Budget $budget + * @param Budget $budget * * @return Carbon|null */ @@ -360,7 +545,7 @@ class BudgetRepository implements BudgetRepositoryInterface /** * Get all budgets with these ID's. * - * @param array $budgetIds + * @param array $budgetIds * * @return Collection */ @@ -393,8 +578,8 @@ class BudgetRepository implements BudgetRepositoryInterface } /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ @@ -411,8 +596,8 @@ class BudgetRepository implements BudgetRepositoryInterface } /** - * @param Budget $budget - * @param int $order + * @param Budget $budget + * @param int $order */ public function setBudgetOrder(Budget $budget, int $order): void { @@ -420,14 +605,6 @@ class BudgetRepository implements BudgetRepositoryInterface $budget->save(); } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * @inheritDoc */ @@ -462,28 +639,28 @@ class BudgetRepository implements BudgetRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'id' => (string) $currencyId, - 'name' => $journal['currency_name'], - 'symbol' => $journal['currency_symbol'], - 'code' => $journal['currency_code'], - 'decimal_places' => $journal['currency_decimal_places'], - 'sum' => '0', - ]; + 'id' => (string)$currencyId, + 'name' => $journal['currency_name'], + 'symbol' => $journal['currency_symbol'], + 'code' => $journal['currency_code'], + 'decimal_places' => $journal['currency_decimal_places'], + 'sum' => '0', + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'])); // also do foreign amount: - $foreignId = (int) $journal['foreign_currency_id']; + $foreignId = (int)$journal['foreign_currency_id']; if (0 !== $foreignId) { $array[$foreignId] = $array[$foreignId] ?? [ - 'id' => (string) $foreignId, - 'name' => $journal['foreign_currency_name'], - 'symbol' => $journal['foreign_currency_symbol'], - 'code' => $journal['foreign_currency_code'], - 'decimal_places' => $journal['foreign_currency_decimal_places'], - 'sum' => '0', - ]; + 'id' => (string)$foreignId, + 'name' => $journal['foreign_currency_name'], + 'symbol' => $journal['foreign_currency_symbol'], + 'code' => $journal['foreign_currency_code'], + 'decimal_places' => $journal['foreign_currency_decimal_places'], + 'sum' => '0', + ]; $array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount'])); } } @@ -492,7 +669,7 @@ class BudgetRepository implements BudgetRepositoryInterface } /** - * @param array $data + * @param array $data * * @return Budget * @throws FireflyException @@ -518,7 +695,7 @@ class BudgetRepository implements BudgetRepositoryInterface // set notes if (array_key_exists('notes', $data)) { - $this->setNoteText($newBudget, (string) $data['notes']); + $this->setNoteText($newBudget, (string)$data['notes']); } if (!array_key_exists('auto_budget_type', $data) || !array_key_exists('auto_budget_amount', $data) || !array_key_exists('auto_budget_period', $data)) { @@ -542,10 +719,10 @@ class BudgetRepository implements BudgetRepositoryInterface $repos = app(CurrencyRepositoryInterface::class); $currency = null; if (array_key_exists('currency_id', $data)) { - $currency = $repos->find((int) $data['currency_id']); + $currency = $repos->find((int)$data['currency_id']); } if (array_key_exists('currency_code', $data)) { - $currency = $repos->findByCode((string) $data['currency_code']); + $currency = $repos->findByCode((string)$data['currency_code']); } if (null === $currency) { $currency = app('amount')->getDefaultCurrencyByUser($this->user); @@ -581,180 +758,6 @@ class BudgetRepository implements BudgetRepositoryInterface public function getMaxOrder(): int { - return (int) $this->user->budgets()->max('order'); - } - - /** - * @param Budget $budget - * @param string $text - * @return void - */ - private function setNoteText(Budget $budget, string $text): void - { - $dbNote = $budget->notes()->first(); - if ('' !== $text) { - if (null === $dbNote) { - $dbNote = new Note(); - $dbNote->noteable()->associate($budget); - } - $dbNote->text = trim($text); - $dbNote->save(); - - return; - } - if (null !== $dbNote) { - try { - $dbNote->delete(); - } catch (Exception $e) { - // @ignoreException - } - } - } - - /** - * @param Budget $budget - * @param array $data - * - * @return Budget - */ - public function update(Budget $budget, array $data): Budget - { - Log::debug('Now in update()'); - - $oldName = $budget->name; - if (array_key_exists('name', $data)) { - $budget->name = $data['name']; - $this->updateRuleActions($oldName, $budget->name); - $this->updateRuleTriggers($oldName, $budget->name); - } - if (array_key_exists('active', $data)) { - $budget->active = $data['active']; - } - if (array_key_exists('notes', $data)) { - $this->setNoteText($budget, (string) $data['notes']); - } - $budget->save(); - - // update or create auto-budget: - $autoBudget = $this->getAutoBudget($budget); - - // first things first: delete when no longer required: - $autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null; - - if (0 === $autoBudgetType && null !== $autoBudget) { - // delete! - $autoBudget->delete(); - - return $budget; - } - if (0 === $autoBudgetType && null === $autoBudget) { - return $budget; - } - if (null === $autoBudgetType && null === $autoBudget) { - return $budget; - } - $this->updateAutoBudget($budget, $data); - - return $budget; - } - - /** - * @param string $oldName - * @param string $newName - */ - private function updateRuleActions(string $oldName, string $newName): void - { - $types = ['set_budget',]; - $actions = RuleAction::leftJoin('rules', 'rules.id', '=', 'rule_actions.rule_id') - ->where('rules.user_id', $this->user->id) - ->whereIn('rule_actions.action_type', $types) - ->where('rule_actions.action_value', $oldName) - ->get(['rule_actions.*']); - Log::debug(sprintf('Found %d actions to update.', $actions->count())); - /** @var RuleAction $action */ - foreach ($actions as $action) { - $action->action_value = $newName; - $action->save(); - Log::debug(sprintf('Updated action %d: %s', $action->id, $action->action_value)); - } - } - - /** - * @param string $oldName - * @param string $newName - */ - private function updateRuleTriggers(string $oldName, string $newName): void - { - $types = ['budget_is',]; - $triggers = RuleTrigger::leftJoin('rules', 'rules.id', '=', 'rule_triggers.rule_id') - ->where('rules.user_id', $this->user->id) - ->whereIn('rule_triggers.trigger_type', $types) - ->where('rule_triggers.trigger_value', $oldName) - ->get(['rule_triggers.*']); - Log::debug(sprintf('Found %d triggers to update.', $triggers->count())); - /** @var RuleTrigger $trigger */ - foreach ($triggers as $trigger) { - $trigger->trigger_value = $newName; - $trigger->save(); - Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value)); - } - } - - /** - * @inheritDoc - */ - public function getAutoBudget(Budget $budget): ?AutoBudget - { - return $budget->autoBudgets()->first(); - } - - /** - * @param Budget $budget - * @param array $data - * @throws FireflyException - * @throws JsonException - */ - private function updateAutoBudget(Budget $budget, array $data): void - { - // update or create auto-budget: - $autoBudget = $this->getAutoBudget($budget); - - // grab default currency: - $currency = app('amount')->getDefaultCurrencyByUser($this->user); - - if (null === $autoBudget) { - // at this point it's a blind assumption auto_budget_type is 1 or 2. - $autoBudget = new AutoBudget(); - $autoBudget->auto_budget_type = $data['auto_budget_type']; - $autoBudget->budget_id = $budget->id; - $autoBudget->transaction_currency_id = $currency->id; - } - - // set or update the currency. - if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) { - $repos = app(CurrencyRepositoryInterface::class); - $currencyId = (int) ($data['currency_id'] ?? 0); - $currencyCode = (string) ($data['currency_code'] ?? ''); - $currency = $repos->find($currencyId); - if (null === $currency) { - $currency = $repos->findByCodeNull($currencyCode); - } - if (null !== $currency) { - $autoBudget->transaction_currency_id = $currency->id; - } - } - - // change values if submitted or presented: - if (array_key_exists('auto_budget_type', $data)) { - $autoBudget->auto_budget_type = $data['auto_budget_type']; - } - if (array_key_exists('auto_budget_amount', $data)) { - $autoBudget->amount = $data['auto_budget_amount']; - } - if (array_key_exists('auto_budget_period', $data)) { - $autoBudget->period = $data['auto_budget_period']; - } - - $autoBudget->save(); + return (int)$this->user->budgets()->max('order'); } } diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index d40d4ad76a..9441b3b76a 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -1,4 +1,5 @@ 0, - 'name' => sprintf('%s (%s)', trans('firefly.no_budget'), $journal['currency_name']), - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_code' => $journal['currency_code'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - 'entries' => [], - ]; + 'id' => 0, + 'name' => sprintf('%s (%s)', trans('firefly.no_budget'), $journal['currency_name']), + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_code' => $journal['currency_code'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + 'entries' => [], + ]; $date = $journal['date']->format($carbonFormat); if (!array_key_exists($date, $data[$currencyId]['entries'])) { @@ -86,17 +86,9 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -133,7 +125,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface /** @var TransactionCurrency $currency */ $currency = $currencies[$code]; $return[] = [ - 'currency_id' => (string) $currency['id'], + 'currency_id' => (string)$currency['id'], 'currency_code' => $code, 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], @@ -145,14 +137,22 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface return $return; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * TODO this method does not include multi currency. It just counts. * TODO this probably also applies to the other "sumExpenses" methods. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param TransactionCurrency|null $currency * * @return array */ @@ -174,15 +174,15 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'])); } diff --git a/app/Repositories/Budget/NoBudgetRepositoryInterface.php b/app/Repositories/Budget/NoBudgetRepositoryInterface.php index bfe8c83661..f431b59522 100644 --- a/app/Repositories/Budget/NoBudgetRepositoryInterface.php +++ b/app/Repositories/Budget/NoBudgetRepositoryInterface.php @@ -34,9 +34,9 @@ use Illuminate\Support\Collection; interface NoBudgetRepositoryInterface { /** - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -44,14 +44,14 @@ interface NoBudgetRepositoryInterface public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -59,10 +59,10 @@ interface NoBudgetRepositoryInterface public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array; /** - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param TransactionCurrency|null $currency * * @return array */ diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index b3281a3685..84092ab31b 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -46,7 +46,7 @@ class OperationsRepository implements OperationsRepositoryInterface * A method that returns the amount of money budgeted per day for this budget, * on average. * - * @param Budget $budget + * @param Budget $budget * * @return string */ @@ -58,15 +58,15 @@ class OperationsRepository implements OperationsRepositoryInterface foreach ($budget->budgetlimits as $limit) { $diff = $limit->start_date->diffInDays($limit->end_date); $diff = 0 === $diff ? 1 : $diff; - $amount = (string) $limit->amount; - $perDay = bcdiv($amount, (string) $diff); + $amount = (string)$limit->amount; + $perDay = bcdiv($amount, (string)$diff); $total = bcadd($total, $perDay); $count++; Log::debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total)); } $avg = $total; if ($count > 0) { - $avg = bcdiv($total, (string) $count); + $avg = bcdiv($total, (string)$count); } Log::debug(sprintf('%s / %d = %s = average.', $total, $count, $avg)); @@ -77,10 +77,10 @@ class OperationsRepository implements OperationsRepositoryInterface * This method is being used to generate the budget overview in the year/multi-year report. Its used * in both the year/multi-year budget overview AND in the accompanying chart. * - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -100,22 +100,22 @@ class OperationsRepository implements OperationsRepositoryInterface /** @var array $journal */ foreach ($journals as $journal) { // prep data array for currency: - $budgetId = (int) $journal['budget_id']; + $budgetId = (int)$journal['budget_id']; $budgetName = $journal['budget_name']; - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $key = sprintf('%d-%d', $budgetId, $currencyId); $data[$key] = $data[$key] ?? [ - 'id' => $budgetId, - 'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']), - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_code' => $journal['currency_code'], - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - 'entries' => [], - ]; + 'id' => $budgetId, + 'name' => sprintf('%s (%s)', $budgetName, $journal['currency_name']), + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_code' => $journal['currency_code'], + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + 'entries' => [], + ]; $date = $journal['date']->format($carbonFormat); $data[$key]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $journal['amount']); } @@ -128,10 +128,10 @@ class OperationsRepository implements OperationsRepositoryInterface * which have the specified budget set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $budgets + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $budgets * * @return array */ @@ -154,9 +154,9 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $budgetId = (int) $journal['budget_id']; - $budgetName = (string) $journal['budget_name']; + $currencyId = (int)$journal['currency_id']; + $budgetId = (int)$journal['budget_id']; + $budgetName = (string)$journal['budget_name']; // catch "no category" entries. if (0 === $budgetId) { @@ -165,24 +165,24 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ - 'budgets' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'budgets' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the categories: $array[$currencyId]['budgets'][$budgetId] = $array[$currencyId]['budgets'][$budgetId] ?? [ - 'id' => $budgetId, - 'name' => $budgetName, - 'transaction_journals' => [], - ]; + 'id' => $budgetId, + 'name' => $budgetName, + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), 'destination_account_id' => $journal['destination_account_id'], @@ -199,6 +199,14 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @return Collection */ @@ -210,20 +218,11 @@ class OperationsRepository implements OperationsRepositoryInterface return $repos->getActiveBudgets(); } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -268,7 +267,7 @@ class OperationsRepository implements OperationsRepositoryInterface /** @var TransactionCurrency $currency */ $currency = $currencies[$code]; $return[] = [ - 'currency_id' => (string) $currency['id'], + 'currency_id' => (string)$currency['id'], 'currency_code' => $code, 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], @@ -281,13 +280,13 @@ class OperationsRepository implements OperationsRepositoryInterface } /** - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $budgets - * @param TransactionCurrency|null $currency - * @deprecated + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $budgets + * @param TransactionCurrency|null $currency * @return array + * @deprecated */ public function sumExpenses( Carbon $start, @@ -355,28 +354,28 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'])); // also do foreign amount: - $foreignId = (int) $journal['foreign_currency_id']; + $foreignId = (int)$journal['foreign_currency_id']; if (0 !== $foreignId) { $array[$foreignId] = $array[$foreignId] ?? [ - 'sum' => '0', - 'currency_id' => $foreignId, - 'currency_name' => $journal['foreign_currency_name'], - 'currency_symbol' => $journal['foreign_currency_symbol'], - 'currency_code' => $journal['foreign_currency_code'], - 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $foreignId, + 'currency_name' => $journal['foreign_currency_name'], + 'currency_symbol' => $journal['foreign_currency_symbol'], + 'currency_code' => $journal['foreign_currency_code'], + 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], + ]; $array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount'])); } } @@ -388,9 +387,9 @@ class OperationsRepository implements OperationsRepositoryInterface * For now, simply refer to whichever repository holds this function. * TODO perhaps better in the future. * - * @param Budget $budget - * @param Carbon|null $start - * @param Carbon|null $end + * @param Budget $budget + * @param Carbon|null $start + * @param Carbon|null $end * * @return Collection */ diff --git a/app/Repositories/Budget/OperationsRepositoryInterface.php b/app/Repositories/Budget/OperationsRepositoryInterface.php index 317b8fdb8a..42d25221c1 100644 --- a/app/Repositories/Budget/OperationsRepositoryInterface.php +++ b/app/Repositories/Budget/OperationsRepositoryInterface.php @@ -38,17 +38,17 @@ interface OperationsRepositoryInterface * A method that returns the amount of money budgeted per day for this budget, * on average. * - * @param Budget $budget + * @param Budget $budget * * @return string */ public function budgetedPerDay(Budget $budget): string; /** - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -60,17 +60,17 @@ interface OperationsRepositoryInterface * which have the specified budget set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $budgets + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $budgets * * @return array */ public function listExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; @@ -78,10 +78,10 @@ interface OperationsRepositoryInterface /** * Return multi-currency spent information. * - * @param Collection $budgets - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $budgets + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @deprecated @@ -89,14 +89,14 @@ interface OperationsRepositoryInterface public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array; /** - * @deprecated - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $budgets - * @param TransactionCurrency|null $currency + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $budgets + * @param TransactionCurrency|null $currency * * @return array + * @deprecated */ public function sumExpenses( Carbon $start, diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index e8120221c6..cbfd18453e 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -1,4 +1,5 @@ find((int) $categoryId); + $result = $this->find((int)$categoryId); if (null === $result) { Log::debug(sprintf('Searching for category with name %s...', $categoryName)); - $result = $this->findByName((string) $categoryName); - if (null === $result && '' !== (string) $categoryName) { + $result = $this->findByName((string)$categoryName); + if (null === $result && '' !== (string)$categoryName) { // create it! $result = $this->store(['name' => $categoryName]); } @@ -145,7 +146,7 @@ class CategoryRepository implements CategoryRepositoryInterface /** * Find a category or return NULL * - * @param int $categoryId + * @param int $categoryId * * @return Category|null */ @@ -157,7 +158,7 @@ class CategoryRepository implements CategoryRepositoryInterface /** * Find a category. * - * @param string $name + * @param string $name * * @return Category|null */ @@ -167,7 +168,7 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param array $data + * @param array $data * * @return Category * @throws FireflyException @@ -195,7 +196,15 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + + /** + * @param Category $category */ public function removeNotes(Category $category): void { @@ -217,7 +226,7 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category + * @param Category $category * * @return Carbon|null * @@ -245,7 +254,7 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category + * @param Category $category * * @return Carbon|null */ @@ -262,7 +271,7 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category + * @param Category $category * * @return Carbon|null */ @@ -305,7 +314,7 @@ class CategoryRepository implements CategoryRepositoryInterface /** * Get all categories with ID's. * - * @param array $categoryIds + * @param array $categoryIds * * @return Collection */ @@ -328,8 +337,8 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category - * @param Collection $accounts + * @param Category $category + * @param Collection $accounts * * @return Carbon|null * @throws Exception @@ -357,8 +366,8 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category - * @param Collection $accounts + * @param Category $category + * @param Collection $accounts * * @return Carbon|null */ @@ -381,8 +390,8 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param Category $category - * @param Collection $accounts + * @param Category $category + * @param Collection $accounts * * @return Carbon|null * @throws Exception @@ -407,8 +416,8 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ @@ -423,16 +432,8 @@ class CategoryRepository implements CategoryRepositoryInterface } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param Category $category - * @param array $data + * @param Category $category + * @param array $data * * @return Category * @throws Exception diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.php index 924e3b46cf..b660fe9332 100644 --- a/app/Repositories/Category/CategoryRepositoryInterface.php +++ b/app/Repositories/Category/CategoryRepositoryInterface.php @@ -1,4 +1,5 @@ [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the non-existent category: $array[$currencyId]['categories'][0] = $array[$currencyId]['categories'][0] ?? [ - 'id' => 0, - 'name' => (string) trans('firefly.noCategory'), - 'transaction_journals' => [], - ]; + 'id' => 0, + 'name' => (string)trans('firefly.noCategory'), + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][0]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), @@ -89,14 +89,22 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface return $array; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * This method returns a list of all the deposit transaction journals (as arrays) set in that period * which have no category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -112,25 +120,25 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'categories' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the non-existent category: $array[$currencyId]['categories'][0] = $array[$currencyId]['categories'][0] ?? [ - 'id' => 0, - 'name' => (string) trans('firefly.noCategory'), - 'transaction_journals' => [], - ]; + 'id' => 0, + 'name' => (string)trans('firefly.noCategory'), + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][0]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->positive($journal['amount']), @@ -141,20 +149,12 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface return $array; } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -171,15 +171,15 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'] ?? '0')); } @@ -189,9 +189,9 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface /** * Sum of income journals in period without a category, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -208,15 +208,15 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($journal['amount'])); } @@ -239,15 +239,15 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($journal['amount'])); } diff --git a/app/Repositories/Category/NoCategoryRepositoryInterface.php b/app/Repositories/Category/NoCategoryRepositoryInterface.php index c1835114b5..483f3f505d 100644 --- a/app/Repositories/Category/NoCategoryRepositoryInterface.php +++ b/app/Repositories/Category/NoCategoryRepositoryInterface.php @@ -38,9 +38,9 @@ interface NoCategoryRepositoryInterface * which have no category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -51,25 +51,25 @@ interface NoCategoryRepositoryInterface * which have no category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** * Sum of withdrawal journals in period without a category, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -78,9 +78,9 @@ interface NoCategoryRepositoryInterface /** * Sum of income journals in period without a category, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ @@ -89,9 +89,9 @@ interface NoCategoryRepositoryInterface /** * Sum of transfers in period without a category, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts * * @return array */ diff --git a/app/Repositories/Category/OperationsRepository.php b/app/Repositories/Category/OperationsRepository.php index 146c02c418..a2dabc2a7d 100644 --- a/app/Repositories/Category/OperationsRepository.php +++ b/app/Repositories/Category/OperationsRepository.php @@ -44,10 +44,10 @@ class OperationsRepository implements OperationsRepositoryInterface * * First currency, then categories. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -70,9 +70,9 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $categoryId = (int) $journal['category_id']; - $categoryName = (string) $journal['category_name']; + $currencyId = (int)$journal['currency_id']; + $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; // catch "no category" entries. if (0 === $categoryId) { @@ -81,24 +81,24 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ - 'categories' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ - 'id' => $categoryId, - 'name' => $categoryName, - 'transaction_journals' => [], - ]; + 'id' => $categoryId, + 'name' => $categoryName, + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), 'date' => $journal['date'], @@ -115,6 +115,14 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * Returns a list of all the categories belonging to a user. * @@ -130,10 +138,10 @@ class OperationsRepository implements OperationsRepositoryInterface * which have the specified category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -156,35 +164,35 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $categoryId = (int) $journal['category_id']; - $categoryName = (string) $journal['category_name']; + $currencyId = (int)$journal['currency_id']; + $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; // catch "no category" entries. if (0 === $categoryId) { - $categoryName = (string) trans('firefly.no_category'); + $categoryName = (string)trans('firefly.no_category'); } // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ - 'categories' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ - 'id' => $categoryId, - 'name' => $categoryName, - 'transaction_journals' => [], - ]; + 'id' => $categoryId, + 'name' => $categoryName, + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->positive($journal['amount']), 'date' => $journal['date'], @@ -220,9 +228,9 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $categoryId = (int) $journal['category_id']; - $categoryName = (string) $journal['category_name']; + $currencyId = (int)$journal['currency_id']; + $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; // catch "no category" entries. if (0 === $categoryId) { @@ -231,24 +239,24 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ - 'categories' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ - 'id' => $categoryId, - 'name' => $categoryName, - 'transaction_journals' => [], - ]; + 'id' => $categoryId, + 'name' => $categoryName, + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->positive($journal['amount']), 'date' => $journal['date'], @@ -285,9 +293,9 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; - $categoryId = (int) $journal['category_id']; - $categoryName = (string) $journal['category_name']; + $currencyId = (int)$journal['currency_id']; + $categoryId = (int)$journal['category_id']; + $categoryName = (string)$journal['category_name']; // catch "no category" entries. if (0 === $categoryId) { @@ -296,24 +304,24 @@ class OperationsRepository implements OperationsRepositoryInterface // info about the currency: $array[$currencyId] = $array[$currencyId] ?? [ - 'categories' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'categories' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // info about the categories: $array[$currencyId]['categories'][$categoryId] = $array[$currencyId]['categories'][$categoryId] ?? [ - 'id' => $categoryId, - 'name' => $categoryName, - 'transaction_journals' => [], - ]; + 'id' => $categoryId, + 'name' => $categoryName, + 'transaction_journals' => [], + ]; // add journal to array: // only a subset of the fields. - $journalId = (int) $journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['categories'][$categoryId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), 'date' => $journal['date'], @@ -330,21 +338,13 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -367,15 +367,15 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => (int) $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => (int)$journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount'])); } @@ -385,10 +385,10 @@ class OperationsRepository implements OperationsRepositoryInterface /** * Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -410,15 +410,15 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($journal['amount'])); } @@ -428,10 +428,10 @@ class OperationsRepository implements OperationsRepositoryInterface /** * Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -453,15 +453,15 @@ class OperationsRepository implements OperationsRepositoryInterface $array = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'sum' => '0', - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'sum' => '0', + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->positive($journal['amount'])); } diff --git a/app/Repositories/Category/OperationsRepositoryInterface.php b/app/Repositories/Category/OperationsRepositoryInterface.php index 0f24e11ad5..1a30eee764 100644 --- a/app/Repositories/Category/OperationsRepositoryInterface.php +++ b/app/Repositories/Category/OperationsRepositoryInterface.php @@ -38,10 +38,10 @@ interface OperationsRepositoryInterface * which have the specified category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -52,10 +52,10 @@ interface OperationsRepositoryInterface * which have the specified category set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -67,10 +67,10 @@ interface OperationsRepositoryInterface * It excludes any transfers between the listed accounts. * It's grouped per currency, with as few details in the array as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts + * @param Collection|null $categories * * @return array */ @@ -82,27 +82,27 @@ interface OperationsRepositoryInterface * It excludes any transfers between the listed accounts. * It's grouped per currency, with as few details in the array as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection $accounts + * @param Collection|null $categories * * @return array */ public function listTransferredOut(Carbon $start, Carbon $end, Collection $accounts, ?Collection $categories = null): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** * Sum of withdrawal journals in period for a set of categories, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -111,10 +111,10 @@ interface OperationsRepositoryInterface /** * Sum of income journals in period for a set of categories, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ @@ -123,10 +123,10 @@ interface OperationsRepositoryInterface /** * Sum of transfers in period for a set of categories, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $categories + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $categories * * @return array */ diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php index 93f5d22678..96ff6e83a1 100644 --- a/app/Repositories/Currency/CurrencyRepository.php +++ b/app/Repositories/Currency/CurrencyRepository.php @@ -1,4 +1,5 @@ where('data', json_encode((string) $currency->id))->count(); + $meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string)$currency->id))->count(); if ($meta > 0) { Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); @@ -113,8 +114,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface // is being used in accounts (as integer) $meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') - ->whereNull('accounts.deleted_at') - ->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode((int) $currency->id))->count(); + ->whereNull('accounts.deleted_at') + ->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode((int)$currency->id))->count(); if ($meta > 0) { Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta)); @@ -151,7 +152,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency * * @return int */ @@ -172,7 +173,15 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param TransactionCurrency $currency + * @return Collection + */ + public function get(): Collection + { + return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get(); + } + + /** + * @param TransactionCurrency $currency * * @return bool */ @@ -192,7 +201,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Disables a currency * - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency */ public function disable(TransactionCurrency $currency): void { @@ -219,11 +228,21 @@ class CurrencyRepository implements CurrencyRepositoryInterface } } + /** + * @param TransactionCurrency $currency + * Enables a currency + */ + public function enable(TransactionCurrency $currency): void + { + $currency->enabled = true; + $currency->save(); + } + /** * Find by currency code, return NULL if unfound. * Used in Import Currency! * - * @param string $currencyCode + * @param string $currencyCode * * @return TransactionCurrency|null * @deprecated @@ -236,7 +255,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by currency name. * - * @param string $currencyName + * @param string $currencyName * * @return TransactionCurrency|null */ @@ -249,7 +268,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface * Find by currency name or return null. * Used in Import Currency! * - * @param string $currencyName + * @param string $currencyName * * @return TransactionCurrency|null * @deprecated @@ -262,7 +281,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by currency symbol. * - * @param string $currencySymbol + * @param string $currencySymbol * * @return TransactionCurrency|null */ @@ -275,7 +294,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface * Find by currency symbol or return NULL * Used in Import Currency! * - * @param string $currencySymbol + * @param string $currencySymbol * * @return TransactionCurrency|null * @deprecated @@ -288,8 +307,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by object, ID or code. Returns user default or system default. * - * @param int|null $currencyId - * @param string|null $currencyCode + * @param int|null $currencyId + * @param string|null $currencyCode * * @return TransactionCurrency * @throws FireflyException @@ -320,18 +339,18 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by object, ID or code. Returns NULL if nothing found. * - * @param int|null $currencyId - * @param string|null $currencyCode + * @param int|null $currencyId + * @param string|null $currencyCode * * @return TransactionCurrency|null */ public function findCurrencyNull(?int $currencyId, ?string $currencyCode): ?TransactionCurrency { Log::debug('Now in findCurrencyNull()'); - $result = $this->find((int) $currencyId); + $result = $this->find((int)$currencyId); if (null === $result) { Log::debug(sprintf('Searching for currency with code %s...', $currencyCode)); - $result = $this->findByCode((string) $currencyCode); + $result = $this->findByCode((string)$currencyCode); } if (null !== $result && false === $result->enabled) { Log::debug(sprintf('Also enabled currency %s', $result->code)); @@ -344,7 +363,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by ID, return NULL if not found. * - * @param int $currencyId + * @param int $currencyId * * @return TransactionCurrency|null */ @@ -356,7 +375,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Find by currency code, return NULL if unfound. * - * @param string $currencyCode + * @param string $currencyCode * * @return TransactionCurrency|null */ @@ -366,25 +385,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param TransactionCurrency $currency - * Enables a currency - */ - public function enable(TransactionCurrency $currency): void - { - $currency->enabled = true; - $currency->save(); - } - - /** - * @return Collection - */ - public function get(): Collection - { - return TransactionCurrency::where('enabled', true)->orderBy('code', 'ASC')->get(); - } - - /** - * @param array $ids + * @param array $ids * * @return Collection */ @@ -394,7 +395,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param Preference $preference + * @param Preference $preference * * @return TransactionCurrency */ @@ -411,9 +412,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface /** * Get currency exchange rate. * - * @param TransactionCurrency $fromCurrency - * @param TransactionCurrency $toCurrency - * @param Carbon $date + * @param TransactionCurrency $fromCurrency + * @param TransactionCurrency $toCurrency + * @param Carbon $date * * @return CurrencyExchangeRate|null */ @@ -440,12 +441,36 @@ class CurrencyRepository implements CurrencyRepositoryInterface return null; } + /** + * @inheritDoc + */ + public function isFallbackCurrency(TransactionCurrency $currency): bool + { + return $currency->code === config('firefly.default_currency', 'EUR'); + } + + /** + * @param string $search + * @param int $limit + * + * @return Collection + */ + public function searchCurrency(string $search, int $limit): Collection + { + $query = TransactionCurrency::where('enabled', true); + if ('' !== $search) { + $query->where('name', 'LIKE', sprintf('%%%s%%', $search)); + } + + return $query->take($limit)->get(); + } + /** * TODO must be a factory - * @param TransactionCurrency $fromCurrency - * @param TransactionCurrency $toCurrency - * @param Carbon $date - * @param float $rate + * @param TransactionCurrency $fromCurrency + * @param TransactionCurrency $toCurrency + * @param Carbon $date + * @param float $rate * @return CurrencyExchangeRate */ public function setExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date, float $rate): CurrencyExchangeRate @@ -462,31 +487,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @inheritDoc - */ - public function isFallbackCurrency(TransactionCurrency $currency): bool - { - return $currency->code === config('firefly.default_currency', 'EUR'); - } - - /** - * @param string $search - * @param int $limit - * - * @return Collection - */ - public function searchCurrency(string $search, int $limit): Collection - { - $query = TransactionCurrency::where('enabled', true); - if ('' !== $search) { - $query->where('name', 'LIKE', sprintf('%%%s%%', $search)); - } - - return $query->take($limit)->get(); - } - - /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -494,7 +495,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param array $data + * @param array $data * * @return TransactionCurrency * @throws FireflyException @@ -513,8 +514,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface } /** - * @param TransactionCurrency $currency - * @param array $data + * @param TransactionCurrency $currency + * @param array $data * * @return TransactionCurrency */ diff --git a/app/Repositories/Currency/CurrencyRepositoryInterface.php b/app/Repositories/Currency/CurrencyRepositoryInterface.php index e1c0e6c3ca..7c45bf9e27 100644 --- a/app/Repositories/Currency/CurrencyRepositoryInterface.php +++ b/app/Repositories/Currency/CurrencyRepositoryInterface.php @@ -1,4 +1,5 @@ whereIn('transaction_types.type', $types) - ->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account']) - ->get(['transaction_journals.*']); + ->whereIn('transaction_types.type', $types) + ->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account']) + ->get(['transaction_journals.*']); } /** * Return the ID of the budget linked to the journal (if any) or the transactions (if any). * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return int */ @@ -80,7 +79,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface /** * Return the ID of the category linked to the journal (if any) or to the transactions (if any). * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return int */ @@ -111,8 +110,8 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface /** * Return Carbon value of a meta field (or NULL). * - * @param TransactionJournal $journal - * @param string $field + * @param TransactionJournal $journal + * @param string $field * * @return null|Carbon */ @@ -154,8 +153,8 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface /** * Return value of a meta field (or NULL) as a string. * - * @param TransactionJournal $journal - * @param string $field + * @param TransactionJournal $journal + * @param string $field * * @return null|string */ @@ -185,7 +184,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface } // return when something else: - $return = (string) $value; + $return = (string)$value; try { $cache->store($return); } catch (Exception $e) { @@ -198,7 +197,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface /** * Return text of a note attached to journal, or NULL * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string|null */ @@ -221,25 +220,25 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface public function getSplitJournals(): Collection { $query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') - ->groupBy('transaction_journals.id'); + ->groupBy('transaction_journals.id'); $result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]); $journalIds = []; /** @var stdClass $row */ foreach ($result as $row) { - if ((int) $row->transaction_count > 2) { - $journalIds[] = (int) $row->id; + if ((int)$row->transaction_count > 2) { + $journalIds[] = (int)$row->id; } } $journalIds = array_unique($journalIds); return TransactionJournal::with(['transactions']) - ->whereIn('id', $journalIds)->get(); + ->whereIn('id', $journalIds)->get(); } /** * Return all tags as strings in an array. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return array */ @@ -249,7 +248,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { diff --git a/app/Repositories/Journal/JournalCLIRepositoryInterface.php b/app/Repositories/Journal/JournalCLIRepositoryInterface.php index cec8ec564d..b226973bda 100644 --- a/app/Repositories/Journal/JournalCLIRepositoryInterface.php +++ b/app/Repositories/Journal/JournalCLIRepositoryInterface.php @@ -36,7 +36,7 @@ interface JournalCLIRepositoryInterface /** * Get all transaction journals with a specific type, regardless of user. * - * @param array $types + * @param array $types * * @return Collection */ @@ -45,7 +45,7 @@ interface JournalCLIRepositoryInterface /** * Return the ID of the budget linked to the journal (if any) or the transactions (if any). * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return int */ @@ -54,7 +54,7 @@ interface JournalCLIRepositoryInterface /** * Return the ID of the category linked to the journal (if any) or to the transactions (if any). * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return int */ @@ -70,8 +70,8 @@ interface JournalCLIRepositoryInterface /** * Return Carbon value of a meta field (or NULL). * - * @param TransactionJournal $journal - * @param string $field + * @param TransactionJournal $journal + * @param string $field * * @return null|Carbon */ @@ -80,8 +80,8 @@ interface JournalCLIRepositoryInterface /** * Return value of a meta field (or NULL). * - * @param TransactionJournal $journal - * @param string $field + * @param TransactionJournal $journal + * @param string $field * * @return null|string */ @@ -90,7 +90,7 @@ interface JournalCLIRepositoryInterface /** * Return text of a note attached to journal, or NULL * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string|null */ @@ -107,14 +107,14 @@ interface JournalCLIRepositoryInterface /** * Return all tags as strings in an array. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return array */ public function getTags(TransactionJournal $journal): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user); } diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 750bd295b5..b48ed7fc75 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -1,4 +1,5 @@ destroy($journal); } - /** - * Find a specific journal. - * - * @param int $journalId - * - * @return TransactionJournal|null - */ - public function find(int $journalId): ?TransactionJournal - { - return $this->user->transactionJournals()->find($journalId); - } - /** * @inheritDoc */ @@ -127,7 +115,7 @@ class JournalRepository implements JournalRepositoryInterface /** * Return total amount of journal. Is always positive. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string */ @@ -142,7 +130,7 @@ class JournalRepository implements JournalRepositoryInterface // saves on queries: $amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount'); - $amount = (string) $amount; + $amount = (string)$amount; $cache->store($amount); return $amount; @@ -164,7 +152,7 @@ class JournalRepository implements JournalRepositoryInterface } /** - * @param TransactionJournalLink $link + * @param TransactionJournalLink $link * * @return string */ @@ -182,8 +170,8 @@ class JournalRepository implements JournalRepositoryInterface /** * Return Carbon value of a meta field (or NULL). * - * @param int $journalId - * @param string $field + * @param int $journalId + * @param string $field * * @return null|Carbon */ @@ -223,7 +211,7 @@ class JournalRepository implements JournalRepositoryInterface } /** - * @param int $journalId + * @param int $journalId */ public function reconcileById(int $journalId): void { @@ -232,11 +220,23 @@ class JournalRepository implements JournalRepositoryInterface $journal?->transactions()->update(['reconciled' => true]); } + /** + * Find a specific journal. + * + * @param int $journalId + * + * @return TransactionJournal|null + */ + public function find(int $journalId): ?TransactionJournal + { + return $this->user->transactionJournals()->find($journalId); + } + /** * Search in journal descriptions. * - * @param string $search - * @param int $limit + * @param string $search + * @param int $limit * * @return Collection */ @@ -252,7 +252,7 @@ class JournalRepository implements JournalRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -262,8 +262,8 @@ class JournalRepository implements JournalRepositoryInterface /** * Update budget for a journal. * - * @param TransactionJournal $journal - * @param int $budgetId + * @param TransactionJournal $journal + * @param int $budgetId * * @return TransactionJournal */ @@ -287,8 +287,8 @@ class JournalRepository implements JournalRepositoryInterface /** * Update category for a journal. * - * @param TransactionJournal $journal - * @param string $category + * @param TransactionJournal $journal + * @param string $category * * @return TransactionJournal */ @@ -311,8 +311,8 @@ class JournalRepository implements JournalRepositoryInterface /** * Update tag(s) for a journal. * - * @param TransactionJournal $journal - * @param array $tags + * @param TransactionJournal $journal + * @param array $tags * * @return TransactionJournal */ diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php index 523ab22637..2dac2b5d3d 100644 --- a/app/Repositories/Journal/JournalRepositoryInterface.php +++ b/app/Repositories/Journal/JournalRepositoryInterface.php @@ -1,4 +1,5 @@ name = $data['name']; + } + if (array_key_exists('inward', $data) && '' !== (string)$data['inward']) { + $linkType->inward = $data['inward']; + } + if (array_key_exists('outward', $data) && '' !== (string)$data['outward']) { + $linkType->outward = $data['outward']; + } + $linkType->save(); + + return $linkType; + } + + /** + * @param TransactionJournalLink $link * * @return bool * @throws Exception @@ -83,8 +106,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface /** * Check if link exists between journals. * - * @param TransactionJournal $one - * @param TransactionJournal $two + * @param TransactionJournal $one + * @param TransactionJournal $two * * @return bool */ @@ -97,18 +120,10 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface return $count + $opposingCount > 0; } - /** - * @return Collection - */ - public function get(): Collection - { - return LinkType::orderBy('name', 'ASC')->get(); - } - /** * Return array of all journal ID's for this type of link. * - * @param LinkType $linkType + * @param LinkType $linkType * * @return array */ @@ -121,22 +136,30 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface return array_unique(array_merge($sources, $destinations)); } + /** + * @return Collection + */ + public function get(): Collection + { + return LinkType::orderBy('name', 'ASC')->get(); + } + /** * Returns all the journal links (of a specific type). * - * @param LinkType|null $linkType + * @param LinkType|null $linkType * * @return Collection */ public function getJournalLinks(LinkType $linkType = null): Collection { $query = TransactionJournalLink::with(['source', 'destination']) - ->leftJoin('transaction_journals as source_journals', 'journal_links.source_id', '=', 'source_journals.id') - ->leftJoin('transaction_journals as dest_journals', 'journal_links.destination_id', '=', 'dest_journals.id') - ->where('source_journals.user_id', $this->user->id) - ->where('dest_journals.user_id', $this->user->id) - ->whereNull('source_journals.deleted_at') - ->whereNull('dest_journals.deleted_at'); + ->leftJoin('transaction_journals as source_journals', 'journal_links.source_id', '=', 'source_journals.id') + ->leftJoin('transaction_journals as dest_journals', 'journal_links.destination_id', '=', 'dest_journals.id') + ->where('source_journals.user_id', $this->user->id) + ->where('dest_journals.user_id', $this->user->id) + ->whereNull('source_journals.deleted_at') + ->whereNull('dest_journals.deleted_at'); if (null !== $linkType) { $query->where('journal_links.link_type_id', $linkType->id); @@ -158,7 +181,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface /** * Return list of existing connections. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Collection */ @@ -176,7 +199,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -184,7 +207,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface } /** - * @param array $data + * @param array $data * * @return LinkType */ @@ -203,16 +226,16 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface /** * Store link between two journals. * - * @param array $information - * @param TransactionJournal $inward - * @param TransactionJournal $outward + * @param array $information + * @param TransactionJournal $inward + * @param TransactionJournal $outward * * @return TransactionJournalLink|null * @throws Exception */ public function storeLink(array $information, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink { - $linkType = $this->find((int) ($information['link_type_id'] ?? 0)); + $linkType = $this->find((int)($information['link_type_id'] ?? 0)); if (null === $linkType) { $linkType = $this->findByName($information['link_type_name']); @@ -244,13 +267,13 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface $link->save(); // make note in noteable: - $this->setNoteText($link, (string) $information['notes']); + $this->setNoteText($link, (string)$information['notes']); return $link; } /** - * @param int $linkTypeId + * @param int $linkTypeId * * @return LinkType|null */ @@ -260,7 +283,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface } /** - * @param string|null $name + * @param string|null $name * * @return LinkType|null */ @@ -276,22 +299,22 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface /** * See if such a link already exists (and get it). * - * @param LinkType $linkType - * @param TransactionJournal $inward - * @param TransactionJournal $outward + * @param LinkType $linkType + * @param TransactionJournal $inward + * @param TransactionJournal $outward * * @return TransactionJournalLink|null */ public function findSpecificLink(LinkType $linkType, TransactionJournal $inward, TransactionJournal $outward): ?TransactionJournalLink { return TransactionJournalLink::where('link_type_id', $linkType->id) - ->where('source_id', $inward->id) - ->where('destination_id', $outward->id)->first(); + ->where('source_id', $inward->id) + ->where('destination_id', $outward->id)->first(); } /** - * @param TransactionJournalLink $link - * @param string $text + * @param TransactionJournalLink $link + * @param string $text * * @throws Exception */ @@ -332,7 +355,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface } /** - * @param TransactionJournalLink $link + * @param TransactionJournalLink $link * * @return bool */ @@ -346,33 +369,11 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface return true; } - /** - * @param LinkType $linkType - * @param array $data - * - * @return LinkType - */ - public function update(LinkType $linkType, array $data): LinkType - { - if (array_key_exists('name', $data) && '' !== (string) $data['name']) { - $linkType->name = $data['name']; - } - if (array_key_exists('inward', $data) && '' !== (string) $data['inward']) { - $linkType->inward = $data['inward']; - } - if (array_key_exists('outward', $data) && '' !== (string) $data['outward']) { - $linkType->outward = $data['outward']; - } - $linkType->save(); - - return $linkType; - } - /** * Update an existing transaction journal link. * - * @param TransactionJournalLink $journalLink - * @param array $data + * @param TransactionJournalLink $journalLink + * @param array $data * * @return TransactionJournalLink * @throws Exception diff --git a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php index 2898350046..9c3c9f338a 100644 --- a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php +++ b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php @@ -1,4 +1,5 @@ user->objectGroups()->max('order'); + return (int)$this->user->objectGroups()->max('order'); } /** - * @param string $title + * @param string $title * * @return bool */ @@ -81,7 +81,7 @@ trait CreatesObjectGroups } /** - * @param string $title + * @param string $title * * @return null|ObjectGroup */ diff --git a/app/Repositories/ObjectGroup/ObjectGroupRepository.php b/app/Repositories/ObjectGroup/ObjectGroupRepository.php index 958c8d69b2..35a42991fa 100644 --- a/app/Repositories/ObjectGroup/ObjectGroupRepository.php +++ b/app/Repositories/ObjectGroup/ObjectGroupRepository.php @@ -118,7 +118,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface $index = 1; /** @var ObjectGroup $objectGroup */ foreach ($list as $objectGroup) { - if ($index !== (int) $objectGroup->order) { + if ($index !== (int)$objectGroup->order) { Log::debug( sprintf('objectGroup #%d ("%s"): order should %d be but is %d.', $objectGroup->id, $objectGroup->title, $index, $objectGroup->order) ); @@ -130,8 +130,8 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface } /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ @@ -151,7 +151,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -168,7 +168,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface } if (array_key_exists('order', $data)) { - $this->setOrder($objectGroup, (int) $data['order']); + $this->setOrder($objectGroup, (int)$data['order']); } $objectGroup->save(); @@ -181,7 +181,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface */ public function setOrder(ObjectGroup $objectGroup, int $newOrder): ObjectGroup { - $oldOrder = (int) $objectGroup->order; + $oldOrder = (int)$objectGroup->order; if ($newOrder > $oldOrder) { $this->user->objectGroups()->where('object_groups.order', '<=', $newOrder)->where('object_groups.order', '>', $oldOrder) diff --git a/app/Repositories/ObjectGroup/ObjectGroupRepositoryInterface.php b/app/Repositories/ObjectGroup/ObjectGroupRepositoryInterface.php index cf70d8b912..2a5b2c44e7 100644 --- a/app/Repositories/ObjectGroup/ObjectGroupRepositoryInterface.php +++ b/app/Repositories/ObjectGroup/ObjectGroupRepositoryInterface.php @@ -44,7 +44,7 @@ interface ObjectGroupRepositoryInterface public function deleteEmpty(): void; /** - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup */ public function destroy(ObjectGroup $objectGroup): void; @@ -54,14 +54,14 @@ interface ObjectGroupRepositoryInterface public function get(): Collection; /** - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return Collection */ public function getBills(ObjectGroup $objectGroup): Collection; /** - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return Collection */ @@ -73,29 +73,29 @@ interface ObjectGroupRepositoryInterface public function resetOrder(): void; /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ public function search(string $query, int $limit): Collection; /** - * @param ObjectGroup $objectGroup - * @param int $newOrder + * @param ObjectGroup $objectGroup + * @param int $newOrder * * @return ObjectGroup */ public function setOrder(ObjectGroup $objectGroup, int $newOrder): ObjectGroup; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** - * @param ObjectGroup $objectGroup - * @param array $data + * @param ObjectGroup $objectGroup + * @param array $data * * @return ObjectGroup */ diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index 9565808176..dff0581e6f 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -42,6 +42,46 @@ trait ModifiesPiggyBanks { use CreatesObjectGroups; + /** + * @param PiggyBankRepetition $repetition + * @param string $amount + * + * @return void + */ + public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void + { + Log::debug(sprintf('addAmountToRepetition: %s', $amount)); + if (-1 === bccomp($amount, '0')) { + Log::debug('Remove amount.'); + $this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal); + } + if (1 === bccomp($amount, '0')) { + Log::debug('Add amount.'); + $this->addAmount($repetition->piggyBank, $amount, $journal); + } + } + + /** + * @param PiggyBank $piggyBank + * @param string $amount + * + * @return bool + */ + public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool + { + $repetition = $this->getRepetition($piggyBank); + if (null === $repetition) { + return false; + } + $repetition->currentamount = bcsub($repetition->currentamount, $amount); + $repetition->save(); + + Log::debug('addAmount: Trigger change for negative amount.'); + event(new ChangedPiggyBankAmount($piggyBank, bcmul($amount, '-1'), $journal, null)); + + return true; + } + /** * @param PiggyBank $piggyBank * @param string $amount @@ -64,25 +104,6 @@ trait ModifiesPiggyBanks return true; } - /** - * @param PiggyBankRepetition $repetition - * @param string $amount - * - * @return void - */ - public function addAmountToRepetition(PiggyBankRepetition $repetition, string $amount, TransactionJournal $journal): void - { - Log::debug(sprintf('addAmountToRepetition: %s', $amount)); - if (-1 === bccomp($amount, '0')) { - Log::debug('Remove amount.'); - $this->removeAmount($repetition->piggyBank, bcmul($amount, '-1'), $journal); - } - if (1 === bccomp($amount, '0')) { - Log::debug('Add amount.'); - $this->addAmount($repetition->piggyBank, $amount, $journal); - } - } - /** * @param PiggyBank $piggyBank * @param string $amount @@ -144,27 +165,6 @@ trait ModifiesPiggyBanks return true; } - /** - * @param PiggyBank $piggyBank - * @param string $amount - * - * @return bool - */ - public function removeAmount(PiggyBank $piggyBank, string $amount, ?TransactionJournal $journal = null): bool - { - $repetition = $this->getRepetition($piggyBank); - if (null === $repetition) { - return false; - } - $repetition->currentamount = bcsub($repetition->currentamount, $amount); - $repetition->save(); - - Log::debug('addAmount: Trigger change for negative amount.'); - event(new ChangedPiggyBankAmount($piggyBank, bcmul($amount, '-1'), $journal, null)); - - return true; - } - /** * @inheritDoc */ diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index b34a7d29c7..221d15ae87 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -1,4 +1,5 @@ find((int) $piggyBankId); + $searchResult = $this->find((int)$piggyBankId); if (null !== $searchResult) { Log::debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId)); @@ -73,7 +76,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface } } if (null !== $piggyBankName) { - $searchResult = $this->findByName((string) $piggyBankName); + $searchResult = $this->findByName((string)$piggyBankName); if (null !== $searchResult) { Log::debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName)); @@ -86,7 +89,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface } /** - * @param int $piggyBankId + * @param int $piggyBankId * * @return PiggyBank|null */ @@ -98,7 +101,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** * Find by name or return NULL. * - * @param string $name + * @param string $name * * @return PiggyBank|null */ @@ -131,7 +134,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** * Get current amount saved in piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return string */ @@ -142,11 +145,11 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface return '0'; } - return (string) $rep->currentamount; + return (string)$rep->currentamount; } /** - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return PiggyBankRepetition|null */ @@ -156,7 +159,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface } /** - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return Collection */ @@ -168,13 +171,13 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** * Used for connecting to a piggy bank. * - * @param PiggyBank $piggyBank - * @param PiggyBankRepetition $repetition - * @param TransactionJournal $journal + * @param PiggyBank $piggyBank + * @param PiggyBankRepetition $repetition + * @param TransactionJournal $journal * * @return string - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ public function getExactAmount(PiggyBank $piggyBank, PiggyBankRepetition $repetition, TransactionJournal $journal): string { @@ -221,11 +224,11 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface // currency of the account + the piggy bank currency are almost the same. // which amount from the transaction matches? $amount = null; - if ((int) $source->transaction_currency_id === (int) $currency->id) { + if ((int)$source->transaction_currency_id === (int)$currency->id) { Log::debug('Use normal amount'); $amount = app('steam')->$operator($source->amount); } - if ((int) $source->foreign_currency_id === (int) $currency->id) { + if ((int)$source->foreign_currency_id === (int)$currency->id) { Log::debug('Use foreign amount'); $amount = app('steam')->$operator($source->foreign_amount); } @@ -236,10 +239,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface } Log::debug(sprintf('The currency is %s and the amount is %s', $currency->code, $amount)); - $room = bcsub((string) $piggyBank->targetamount, (string) $repetition->currentamount); + $room = bcsub((string)$piggyBank->targetamount, (string)$repetition->currentamount); $compare = bcmul($repetition->currentamount, '-1'); - if (bccomp((string) $piggyBank->targetamount, '0') === 0) { + if (bccomp((string)$piggyBank->targetamount, '0') === 0) { // amount is zero? then the "room" is positive amount of we wish to add or remove. $room = app('steam')->positive($amount); Log::debug(sprintf('Room is now %s', $room)); @@ -266,7 +269,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface return $compare; } - return (string) $amount; + return (string)$amount; + } + + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; } /** @@ -274,13 +285,13 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface */ public function getMaxOrder(): int { - return (int) $this->user->piggyBanks()->max('piggy_banks.order'); + return (int)$this->user->piggyBanks()->max('piggy_banks.order'); } /** * Return note for piggy bank. * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return string */ @@ -309,7 +320,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** @var PiggyBank $piggy */ foreach ($set as $piggy) { $currentAmount = $this->getRepetition($piggy)->currentamount ?? '0'; - $piggy->name = $piggy->name . ' (' . app('amount')->formatAnything($currency, $currentAmount, false) . ')'; + $piggy->name = $piggy->name.' ('.app('amount')->formatAnything($currency, $currentAmount, false).')'; } return $set; @@ -326,7 +337,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** * Returns the suggested amount the user should save per month, or "". * - * @param PiggyBank $piggyBank + * @param PiggyBank $piggyBank * * @return string * @@ -346,7 +357,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface // more than 1 month to go and still need money to save: if ($diffInMonths > 0 && 1 === bccomp($remainingAmount, '0')) { - $savePerMonth = bcdiv($remainingAmount, (string) $diffInMonths); + $savePerMonth = bcdiv($remainingAmount, (string)$diffInMonths); } // less than 1 month to go but still need money to save: @@ -361,11 +372,11 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface /** * Get for piggy account what is left to put in piggies. * - * @param PiggyBank $piggyBank - * @param Carbon $date + * @param PiggyBank $piggyBank + * @param Carbon $date * * @return string - * @throws \JsonException + * @throws JsonException */ public function leftOnAccount(PiggyBank $piggyBank, Carbon $date): string { @@ -399,12 +410,4 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface return $search->take($limit)->get(); } - - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } } diff --git a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php index e3b83132b2..d786a77364 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php +++ b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php @@ -1,4 +1,5 @@ where('name', 'recurrence_id'); + $q1->where('data', json_encode((string)$recurrence->id)); + })->get(['journal_meta.transaction_journal_id']); + + // there are X journals made for this recurrence. Any of them meant for today? + foreach ($set as $journalMeta) { + $count = TransactionJournalMeta::where(function (Builder $q2) use ($date) { + $string = (string)$date; + Log::debug(sprintf('Search for date: %s', json_encode($string))); + $q2->where('name', 'recurrence_date'); + $q2->where('data', json_encode($string)); + }) + ->where('transaction_journal_id', $journalMeta->transaction_journal_id) + ->count(); + if ($count > 0) { + Log::debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id)); + return true; + } + } + return false; + } + /** * Destroy a recurring transaction. * @@ -81,6 +111,20 @@ class RecurringRepository implements RecurringRepositoryInterface $this->user->recurrences()->delete(); } + /** + * Get ALL recurring transactions. + * + * @return Collection + */ + public function getAll(): Collection + { + // grab ALL recurring transactions: + return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions']) + ->orderBy('active', 'DESC') + ->orderBy('title', 'ASC') + ->get(); + } + /** * Returns all of the user's recurring transactions. * @@ -96,20 +140,6 @@ class RecurringRepository implements RecurringRepositoryInterface ->get(); } - /** - * Get ALL recurring transactions. - * - * @return Collection - */ - public function getAll(): Collection - { - // grab ALL recurring transactions: - return Recurrence::with(['TransactionCurrency', 'TransactionType', 'RecurrenceRepetitions', 'RecurrenceTransactions']) - ->orderBy('active', 'DESC') - ->orderBy('title', 'ASC') - ->get(); - } - /** * @inheritDoc */ @@ -314,6 +344,16 @@ class RecurringRepository implements RecurringRepositoryInterface return $collector->getPaginatedGroups(); } + /** + * Set user for in repository. + * + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @param Recurrence $recurrence * @@ -521,16 +561,6 @@ class RecurringRepository implements RecurringRepositoryInterface return $search->take($limit)->get(['id', 'title', 'description']); } - /** - * Set user for in repository. - * - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * @param array $data * @@ -629,34 +659,4 @@ class RecurringRepository implements RecurringRepositoryInterface return $service->update($recurrence, $data); } - - /** - * @inheritDoc - */ - public function createdPreviously(Recurrence $recurrence, Carbon $date): bool - { - // if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well. - $set = - TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) { - $q1->where('name', 'recurrence_id'); - $q1->where('data', json_encode((string)$recurrence->id)); - })->get(['journal_meta.transaction_journal_id']); - - // there are X journals made for this recurrence. Any of them meant for today? - foreach ($set as $journalMeta) { - $count = TransactionJournalMeta::where(function (Builder $q2) use ($date) { - $string = (string)$date; - Log::debug(sprintf('Search for date: %s', json_encode($string))); - $q2->where('name', 'recurrence_date'); - $q2->where('data', json_encode($string)); - }) - ->where('transaction_journal_id', $journalMeta->transaction_journal_id) - ->count(); - if ($count > 0) { - Log::debug(sprintf('Looks like journal #%d was already created', $journalMeta->transaction_journal_id)); - return true; - } - } - return false; - } } diff --git a/app/Repositories/Recurring/RecurringRepositoryInterface.php b/app/Repositories/Recurring/RecurringRepositoryInterface.php index eddce93351..c4fca83361 100644 --- a/app/Repositories/Recurring/RecurringRepositoryInterface.php +++ b/app/Repositories/Recurring/RecurringRepositoryInterface.php @@ -38,13 +38,6 @@ use Illuminate\Support\Collection; */ interface RecurringRepositoryInterface { - /** - * Destroy a recurring transaction. - * - * @param Recurrence $recurrence - */ - public function destroy(Recurrence $recurrence): void; - /** * @param Recurrence $recurrence * @param Carbon $date @@ -52,6 +45,13 @@ interface RecurringRepositoryInterface */ public function createdPreviously(Recurrence $recurrence, Carbon $date): bool; + /** + * Destroy a recurring transaction. + * + * @param Recurrence $recurrence + */ + public function destroy(Recurrence $recurrence): void; + /** * Destroy all recurring transactions. */ diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.php index 9cb52c36a7..32a1377b4b 100644 --- a/app/Repositories/Rule/RuleRepository.php +++ b/app/Repositories/Rule/RuleRepository.php @@ -1,4 +1,5 @@ user->rules()->count(); - } - - /** - * @param Rule $rule + * @param Rule $rule * * @return bool * @throws Exception @@ -76,7 +69,7 @@ class RuleRepository implements RuleRepositoryInterface public function duplicate(Rule $rule): Rule { $newRule = $rule->replicate(); - $newRule->title = (string) trans('firefly.rule_copy_of', ['title' => $rule->title]); + $newRule->title = (string)trans('firefly.rule_copy_of', ['title' => $rule->title]); $newRule->save(); // replicate all triggers @@ -98,16 +91,6 @@ class RuleRepository implements RuleRepositoryInterface return $newRule; } - /** - * @param int $ruleId - * - * @return Rule|null - */ - public function find(int $ruleId): ?Rule - { - return $this->user->rules()->find($ruleId); - } - /** * Get all the users rules. * @@ -129,17 +112,17 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return int */ public function getHighestOrderInRuleGroup(RuleGroup $ruleGroup): int { - return (int) $ruleGroup->rules()->max('order'); + return (int)$ruleGroup->rules()->max('order'); } /** - * @param Rule $rule + * @param Rule $rule * * @return string * @@ -149,14 +132,22 @@ class RuleRepository implements RuleRepositoryInterface { $count = $rule->ruleTriggers()->count(); if (0 === $count) { - throw new FireflyException('Rules should have more than zero triggers, rule #' . $rule->id . ' has none!'); + throw new FireflyException('Rules should have more than zero triggers, rule #'.$rule->id.' has none!'); } return $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value; } /** - * @param Rule $rule + * @return int + */ + public function count(): int + { + return $this->user->rules()->count(); + } + + /** + * @param Rule $rule * * @return Collection */ @@ -166,7 +157,7 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param Rule $rule + * @param Rule $rule * * @return Collection */ @@ -268,15 +259,7 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param array $data + * @param array $data * * @return Rule * @throws FireflyException @@ -330,8 +313,18 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param string $moment - * @param Rule $rule + * @param int $ruleId + * + * @return Rule|null + */ + public function find(int $ruleId): ?Rule + { + return $this->user->rules()->find($ruleId); + } + + /** + * @param string $moment + * @param Rule $rule */ private function setRuleTrigger(string $moment, Rule $rule): void { @@ -354,7 +347,7 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return bool */ @@ -367,13 +360,21 @@ class RuleRepository implements RuleRepositoryInterface return true; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @inheritDoc */ public function setOrder(Rule $rule, int $newOrder): void { - $oldOrder = (int) $rule->order; - $groupId = (int) $rule->rule_group_id; + $oldOrder = (int)$rule->order; + $groupId = (int)$rule->rule_group_id; $maxOrder = $this->maxOrder($rule->ruleGroup); $newOrder = $newOrder > $maxOrder ? $maxOrder + 1 : $newOrder; Log::debug(sprintf('New order will be %d', $newOrder)); @@ -408,12 +409,12 @@ class RuleRepository implements RuleRepositoryInterface */ public function maxOrder(RuleGroup $ruleGroup): int { - return (int) $ruleGroup->rules()->max('order'); + return (int)$ruleGroup->rules()->max('order'); } /** - * @param Rule $rule - * @param array $data + * @param Rule $rule + * @param array $data * * @return void */ @@ -442,8 +443,8 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param Rule $rule - * @param array $values + * @param Rule $rule + * @param array $values * * @return RuleTrigger */ @@ -462,8 +463,8 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param Rule $rule - * @param array $data + * @param Rule $rule + * @param array $data * * @return void */ @@ -487,8 +488,8 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param Rule $rule - * @param array $values + * @param Rule $rule + * @param array $values * * @return RuleAction */ @@ -507,8 +508,8 @@ class RuleRepository implements RuleRepositoryInterface } /** - * @param Rule $rule - * @param array $data + * @param Rule $rule + * @param array $data * * @return Rule */ @@ -534,7 +535,7 @@ class RuleRepository implements RuleRepositoryInterface // update the order: $this->resetRuleOrder($group); if (array_key_exists('order', $data)) { - $this->moveRule($rule, $group, (int) $data['order']); + $this->moveRule($rule, $group, (int)$data['order']); } diff --git a/app/Repositories/Rule/RuleRepositoryInterface.php b/app/Repositories/Rule/RuleRepositoryInterface.php index 0fc7c4bf5e..5f2577737e 100644 --- a/app/Repositories/Rule/RuleRepositoryInterface.php +++ b/app/Repositories/Rule/RuleRepositoryInterface.php @@ -1,4 +1,5 @@ user->ruleGroups()->orderBy('order', 'ASC')->get(); + } + /** * @return int */ @@ -70,8 +79,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $ruleGroup - * @param RuleGroup|null $moveTo + * @param RuleGroup $ruleGroup + * @param RuleGroup|null $moveTo * * @return bool * @throws Exception @@ -128,7 +137,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return bool */ @@ -142,7 +151,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface $count = 1; /** @var Rule $entry */ foreach ($set as $entry) { - if ((int) $entry->order !== $count) { + if ((int)$entry->order !== $count) { Log::debug(sprintf('Rule #%d was on spot %d but must be on spot %d', $entry->id, $entry->order, $count)); $entry->order = $count; $entry->save(); @@ -157,7 +166,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param Rule $rule + * @param Rule $rule */ private function resetRuleActionOrder(Rule $rule): void { @@ -169,7 +178,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface $index = 1; /** @var RuleAction $action */ foreach ($actions as $action) { - if ((int) $action->order !== $index) { + if ((int)$action->order !== $index) { $action->order = $index; $action->save(); Log::debug(sprintf('Rule action #%d was on spot %d but must be on spot %d', $action->id, $action->order, $index)); @@ -179,7 +188,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param Rule $rule + * @param Rule $rule */ private function resetRuleTriggerOrder(Rule $rule): void { @@ -191,7 +200,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface $index = 1; /** @var RuleTrigger $trigger */ foreach ($triggers as $trigger) { - $order = (int) $trigger->order; + $order = (int)$trigger->order; if ($order !== $index) { $trigger->order = $index; $trigger->save(); @@ -215,15 +224,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @return Collection - */ - public function get(): Collection - { - return $this->user->ruleGroups()->orderBy('order', 'ASC')->get(); - } - - /** - * @param int $ruleGroupId + * @param int $ruleGroupId * * @return RuleGroup|null */ @@ -233,7 +234,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param string $title + * @param string $title * * @return RuleGroup|null */ @@ -251,7 +252,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $group + * @param RuleGroup $group * * @return Collection */ @@ -263,7 +264,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $group + * @param RuleGroup $group * * @return Collection */ @@ -278,7 +279,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $group + * @param RuleGroup $group * * @return Collection */ @@ -293,7 +294,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param string|null $filter + * @param string|null $filter * * @return Collection */ @@ -351,11 +352,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface { $entry = $this->user->ruleGroups()->max('order'); - return (int) $entry; + return (int)$entry; } /** - * @param string|null $filter + * @param string|null $filter * * @return Collection */ @@ -408,7 +409,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $group + * @param RuleGroup $group * * @return Collection */ @@ -423,7 +424,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface */ public function maxOrder(): int { - return (int) $this->user->ruleGroups()->where('active', true)->max('order'); + return (int)$this->user->ruleGroups()->where('active', true)->max('order'); } /** @@ -442,7 +443,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -450,7 +451,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param array $data + * @param array $data * * @return RuleGroup */ @@ -479,7 +480,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface */ public function setOrder(RuleGroup $ruleGroup, int $newOrder): void { - $oldOrder = (int) $ruleGroup->order; + $oldOrder = (int)$ruleGroup->order; if ($newOrder > $oldOrder) { $this->user->ruleGroups()->where('rule_groups.order', '<=', $newOrder)->where('rule_groups.order', '>', $oldOrder) @@ -501,8 +502,8 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface } /** - * @param RuleGroup $ruleGroup - * @param array $data + * @param RuleGroup $ruleGroup + * @param array $data * * @return RuleGroup */ @@ -521,7 +522,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface // order if (array_key_exists('order', $data) && $ruleGroup->order !== $data['order']) { $this->resetOrder(); - $this->setOrder($ruleGroup, (int) $data['order']); + $this->setOrder($ruleGroup, (int)$data['order']); } $ruleGroup->save(); diff --git a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php index aa1ef97406..f2fa871fde 100644 --- a/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php +++ b/app/Repositories/RuleGroup/RuleGroupRepositoryInterface.php @@ -1,4 +1,5 @@ [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'tags' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // may have multiple tags: foreach ($journal['tags'] as $tag) { - $tagId = (int) $tag['id']; - $tagName = (string) $tag['name']; - $journalId = (int) $journal['transaction_journal_id']; + $tagId = (int)$tag['id']; + $tagName = (string)$tag['name']; + $journalId = (int)$journal['transaction_journal_id']; if (in_array($journalId, $listedJournals, true)) { continue; } $listedJournals[] = $journalId; $array[$currencyId]['tags'][$tagId] = $array[$currencyId]['tags'][$tagId] ?? [ - 'id' => $tagId, - 'name' => $tagName, - 'transaction_journals' => [], - ]; + 'id' => $tagId, + 'name' => $tagName, + 'transaction_journals' => [], + ]; $array[$currencyId]['tags'][$tagId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), @@ -114,10 +116,18 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @return Collection - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function getTags(): Collection { @@ -131,10 +141,10 @@ class OperationsRepository implements OperationsRepositoryInterface * which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array */ @@ -158,21 +168,21 @@ class OperationsRepository implements OperationsRepositoryInterface $listedJournals = []; foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $array[$currencyId] = $array[$currencyId] ?? [ - 'tags' => [], - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_code' => $journal['currency_code'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - ]; + 'tags' => [], + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_code' => $journal['currency_code'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + ]; // may have multiple tags: foreach ($journal['tags'] as $tag) { - $tagId = (int) $tag['id']; - $tagName = (string) $tag['name']; - $journalId = (int) $journal['transaction_journal_id']; + $tagId = (int)$tag['id']; + $tagName = (string)$tag['name']; + $journalId = (int)$journal['transaction_journal_id']; if (in_array($journalId, $listedJournals, true)) { continue; @@ -180,11 +190,11 @@ class OperationsRepository implements OperationsRepositoryInterface $listedJournals[] = $journalId; $array[$currencyId]['tags'][$tagId] = $array[$currencyId]['tags'][$tagId] ?? [ - 'id' => $tagId, - 'name' => $tagName, - 'transaction_journals' => [], - ]; - $journalId = (int) $journal['transaction_journal_id']; + 'id' => $tagId, + 'name' => $tagName, + 'transaction_journals' => [], + ]; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['tags'][$tagId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->positive($journal['amount']), 'date' => $journal['date'], @@ -202,21 +212,13 @@ class OperationsRepository implements OperationsRepositoryInterface return $array; } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * Sum of withdrawal journals in period for a set of tags, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array * @throws FireflyException @@ -229,10 +231,10 @@ class OperationsRepository implements OperationsRepositoryInterface /** * Sum of income journals in period for a set of tags, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array * @throws FireflyException diff --git a/app/Repositories/Tag/OperationsRepositoryInterface.php b/app/Repositories/Tag/OperationsRepositoryInterface.php index bb254c841b..f5f6dd09b1 100644 --- a/app/Repositories/Tag/OperationsRepositoryInterface.php +++ b/app/Repositories/Tag/OperationsRepositoryInterface.php @@ -39,10 +39,10 @@ interface OperationsRepositoryInterface * which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array */ @@ -53,27 +53,27 @@ interface OperationsRepositoryInterface * which have the specified tag(s) set to them. It's grouped per currency, with as few details in the array * as possible. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array */ public function listIncome(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $tags = null): array; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** * Sum of withdrawal journals in period for a set of tags, grouped per currency. Amounts are always negative. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array */ @@ -82,10 +82,10 @@ interface OperationsRepositoryInterface /** * Sum of income journals in period for a set of tags, grouped per currency. Amounts are always positive. * - * @param Carbon $start - * @param Carbon $end - * @param Collection|null $accounts - * @param Collection|null $tags + * @param Carbon $start + * @param Carbon $end + * @param Collection|null $accounts + * @param Collection|null $tags * * @return array */ diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 32cc326ab5..8e37750467 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -1,4 +1,5 @@ user = $user; + } + + /** + * @param int $tagId * * @return Tag|null */ @@ -118,7 +127,7 @@ class TagRepository implements TagRepositoryInterface } /** - * @param string $tag + * @param string $tag * * @return Tag|null */ @@ -128,7 +137,7 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag + * @param Tag $tag * * @return Carbon|null */ @@ -163,7 +172,7 @@ class TagRepository implements TagRepositoryInterface } /** - * @param int|null $year + * @param int|null $year * * @return array */ @@ -180,7 +189,7 @@ class TagRepository implements TagRepositoryInterface if (null !== $year) { Log::debug(sprintf('Get tags with year %s.', $year)); - $tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59'); + $tagQuery->where('tags.date', '>=', $year.'-01-01 00:00:00')->where('tags.date', '<=', $year.'-12-31 23:59:59'); } $collection = $tagQuery->get(); $return = []; @@ -200,9 +209,9 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag - * @param Carbon $start - * @param Carbon $end + * @param Tag $tag + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -218,7 +227,7 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag + * @param Tag $tag * * @return Carbon|null */ @@ -253,7 +262,7 @@ class TagRepository implements TagRepositoryInterface /** * Find one or more tags based on the query. * - * @param string $query + * @param string $query * * @return Collection */ @@ -267,8 +276,8 @@ class TagRepository implements TagRepositoryInterface /** * Search the users tags. * - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ @@ -285,15 +294,7 @@ class TagRepository implements TagRepositoryInterface } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param array $data + * @param array $data * * @return Tag */ @@ -307,9 +308,9 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag - * @param Carbon|null $start - * @param Carbon|null $end + * @param Tag $tag + * @param Carbon|null $start + * @param Carbon|null $end * * @return array * @@ -330,21 +331,21 @@ class TagRepository implements TagRepositoryInterface /** @var array $journal */ foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $sums[$currencyId] = $sums[$currencyId] ?? [ - 'currency_id' => $currencyId, - 'currency_name' => $journal['currency_name'], - 'currency_symbol' => $journal['currency_symbol'], - 'currency_decimal_places' => $journal['currency_decimal_places'], - TransactionType::WITHDRAWAL => '0', - TransactionType::DEPOSIT => '0', - TransactionType::TRANSFER => '0', - TransactionType::RECONCILIATION => '0', - TransactionType::OPENING_BALANCE => '0', - ]; + 'currency_id' => $currencyId, + 'currency_name' => $journal['currency_name'], + 'currency_symbol' => $journal['currency_symbol'], + 'currency_decimal_places' => $journal['currency_decimal_places'], + TransactionType::WITHDRAWAL => '0', + TransactionType::DEPOSIT => '0', + TransactionType::TRANSFER => '0', + TransactionType::RECONCILIATION => '0', + TransactionType::OPENING_BALANCE => '0', + ]; // add amount to correct type: - $amount = app('steam')->positive((string) $journal['amount']); + $amount = app('steam')->positive((string)$journal['amount']); $type = $journal['transaction_type_type']; if (TransactionType::WITHDRAWAL === $type) { $amount = bcmul($amount, '-1'); @@ -354,18 +355,18 @@ class TagRepository implements TagRepositoryInterface $foreignCurrencyId = $journal['foreign_currency_id']; if (null !== $foreignCurrencyId && 0 !== $foreignCurrencyId) { $sums[$foreignCurrencyId] = $sums[$foreignCurrencyId] ?? [ - 'currency_id' => $foreignCurrencyId, - 'currency_name' => $journal['foreign_currency_name'], - 'currency_symbol' => $journal['foreign_currency_symbol'], - 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], - TransactionType::WITHDRAWAL => '0', - TransactionType::DEPOSIT => '0', - TransactionType::TRANSFER => '0', - TransactionType::RECONCILIATION => '0', - TransactionType::OPENING_BALANCE => '0', - ]; + 'currency_id' => $foreignCurrencyId, + 'currency_name' => $journal['foreign_currency_name'], + 'currency_symbol' => $journal['foreign_currency_symbol'], + 'currency_decimal_places' => $journal['foreign_currency_decimal_places'], + TransactionType::WITHDRAWAL => '0', + TransactionType::DEPOSIT => '0', + TransactionType::TRANSFER => '0', + TransactionType::RECONCILIATION => '0', + TransactionType::OPENING_BALANCE => '0', + ]; // add foreign amount to correct type: - $amount = app('steam')->positive((string) $journal['foreign_amount']); + $amount = app('steam')->positive((string)$journal['foreign_amount']); $type = $journal['transaction_type_type']; if (TransactionType::WITHDRAWAL === $type) { $amount = bcmul($amount, '-1'); @@ -378,9 +379,9 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag - * @param Carbon $start - * @param Carbon $end + * @param Tag $tag + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -395,8 +396,8 @@ class TagRepository implements TagRepositoryInterface } /** - * @param Tag $tag - * @param array $data + * @param Tag $tag + * @param array $data * * @return Tag */ diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index afe80115ed..0a5bbd76cc 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -1,4 +1,5 @@ user->transactionGroups()->find($groupId); + } + + /** + * @param TransactionGroup $group */ public function destroy(TransactionGroup $group): void { @@ -92,7 +105,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return array */ @@ -119,7 +132,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } /** - * @param Transaction $transaction + * @param Transaction $transaction * * @return array */ @@ -141,22 +154,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface return $array; } - /** - * Find a transaction group by its ID. - * - * @param int $groupId - * - * @return TransactionGroup|null - */ - public function find(int $groupId): ?TransactionGroup - { - return $this->user->transactionGroups()->find($groupId); - } - /** * Return all attachments for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -173,7 +174,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface $result = []; /** @var Attachment $attachment */ foreach ($set as $attachment) { - $journalId = (int) $attachment->attachable_id; + $journalId = (int)$attachment->attachable_id; $result[$journalId] = $result[$journalId] ?? []; $current = $attachment->toArray(); $current['file_exists'] = true; @@ -185,10 +186,38 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface return $result; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + + /** + * Get the note text for a journal (by ID). + * + * @param int $journalId + * + * @return string|null + */ + public function getNoteText(int $journalId): ?string + { + /** @var Note|null $note */ + $note = Note::where('noteable_id', $journalId) + ->where('noteable_type', TransactionJournal::class) + ->first(); + if (null === $note) { + return null; + } + + return $note->text; + } + /** * Return all journal links for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -202,9 +231,9 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface $q->orWhereIn('destination_id', $journals); } ) - ->with(['source', 'destination', 'source.transactions']) - ->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id') - ->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']); + ->with(['source', 'destination', 'source.transactions']) + ->leftJoin('link_types', 'link_types.id', '=', 'journal_links.link_type_id') + ->get(['journal_links.*', 'link_types.inward', 'link_types.outward', 'link_types.editable']); /** @var TransactionJournalLink $entry */ foreach ($set as $entry) { $journalId = in_array($entry->source_id, $journals, true) ? $entry->source_id : $entry->destination_id; @@ -242,7 +271,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string */ @@ -265,7 +294,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string */ @@ -307,8 +336,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface /** * Return object with all found meta field things as Carbon objects. * - * @param int $journalId - * @param array $fields + * @param int $journalId + * @param array $fields * * @return NullArrayObject * @throws Exception @@ -316,10 +345,10 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface public function getMetaDateFields(int $journalId, array $fields): NullArrayObject { $query = DB::table('journal_meta') - ->where('transaction_journal_id', $journalId) - ->whereIn('name', $fields) - ->whereNull('deleted_at') - ->get(['name', 'data']); + ->where('transaction_journal_id', $journalId) + ->whereIn('name', $fields) + ->whereNull('deleted_at') + ->get(['name', 'data']); $return = []; foreach ($query as $row) { @@ -332,18 +361,18 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface /** * Return object with all found meta field things. * - * @param int $journalId - * @param array $fields + * @param int $journalId + * @param array $fields * * @return NullArrayObject */ public function getMetaFields(int $journalId, array $fields): NullArrayObject { $query = DB::table('journal_meta') - ->where('transaction_journal_id', $journalId) - ->whereIn('name', $fields) - ->whereNull('deleted_at') - ->get(['name', 'data']); + ->where('transaction_journal_id', $journalId) + ->whereIn('name', $fields) + ->whereNull('deleted_at') + ->get(['name', 'data']); $return = []; foreach ($query as $row) { @@ -353,34 +382,14 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface return new NullArrayObject($return); } - /** - * Get the note text for a journal (by ID). - * - * @param int $journalId - * - * @return string|null - */ - public function getNoteText(int $journalId): ?string - { - /** @var Note|null $note */ - $note = Note::where('noteable_id', $journalId) - ->where('noteable_type', TransactionJournal::class) - ->first(); - if (null === $note) { - return null; - } - - return $note->text; - } - /** * Return all piggy bank events for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array * @throws FireflyException - * @throws \JsonException + * @throws JsonException */ public function getPiggyEvents(TransactionGroup $group): array { @@ -388,8 +397,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface $journals = $group->transactionJournals->pluck('id')->toArray(); $currency = app('amount')->getDefaultCurrencyByUser($this->user); $data = PiggyBankEvent::whereIn('transaction_journal_id', $journals) - ->with('piggyBank', 'piggyBank.account') - ->get(['piggy_bank_events.*']); + ->with('piggyBank', 'piggyBank.account') + ->get(['piggy_bank_events.*']); /** @var PiggyBankEvent $row */ foreach ($data as $row) { if (null === $row->piggyBank) { @@ -397,8 +406,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } // get currency preference. $currencyPreference = AccountMeta::where('account_id', $row->piggyBank->account_id) - ->where('name', 'currency_id') - ->first(); + ->where('name', 'currency_id') + ->first(); if (null !== $currencyPreference) { $currency = TransactionCurrency::where('id', $currencyPreference->data)->first(); } @@ -406,7 +415,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface $currencyCode = app('preferences')->getForUser($this->user, 'currencyPreference', 'EUR')->data; $currency = TransactionCurrency::where('code', $currencyCode)->first(); } - $journalId = (int) $row->transaction_journal_id; + $journalId = (int)$row->transaction_journal_id; $return[$journalId] = $return[$journalId] ?? []; $return[$journalId][] = [ @@ -433,31 +442,23 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface /** * Get the tags for a journal (by ID). * - * @param int $journalId + * @param int $journalId * * @return array */ public function getTags(int $journalId): array { $result = DB::table('tag_transaction_journal') - ->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id') - ->where('tag_transaction_journal.transaction_journal_id', $journalId) - ->orderBy('tags.tag', 'ASC') - ->get(['tags.tag']); + ->leftJoin('tags', 'tag_transaction_journal.tag_id', '=', 'tags.id') + ->where('tag_transaction_journal.transaction_journal_id', $journalId) + ->orderBy('tags.tag', 'ASC') + ->get(['tags.tag']); return $result->pluck('tag')->toArray(); } /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - - /** - * @param array $data + * @param array $data * * @return TransactionGroup * @throws DuplicateTransactionException @@ -482,8 +483,8 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface } /** - * @param TransactionGroup $transactionGroup - * @param array $data + * @param TransactionGroup $transactionGroup + * @param array $data * * @return TransactionGroup * diff --git a/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php b/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php index 9d3900071f..36a1186d4c 100644 --- a/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php +++ b/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php @@ -37,21 +37,21 @@ use Illuminate\Support\Collection; interface TransactionGroupRepositoryInterface { /** - * @param int $journalId + * @param int $journalId * * @return int */ public function countAttachments(int $journalId): int; /** - * @param TransactionGroup $group + * @param TransactionGroup $group */ public function destroy(TransactionGroup $group): void; /** * Return a group and expand all meta data etc. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -60,7 +60,7 @@ interface TransactionGroupRepositoryInterface /** * Find a transaction group by its ID. * - * @param int $groupId + * @param int $groupId * * @return TransactionGroup|null */ @@ -69,7 +69,7 @@ interface TransactionGroupRepositoryInterface /** * Return all attachments for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -78,7 +78,7 @@ interface TransactionGroupRepositoryInterface /** * Return all journal links for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -87,7 +87,7 @@ interface TransactionGroupRepositoryInterface /** * Get the location of a journal or NULL. * - * @param int $journalId + * @param int $journalId * * @return Location|null */ @@ -96,8 +96,8 @@ interface TransactionGroupRepositoryInterface /** * Return object with all found meta field things as Carbon objects. * - * @param int $journalId - * @param array $fields + * @param int $journalId + * @param array $fields * * @return NullArrayObject */ @@ -106,8 +106,8 @@ interface TransactionGroupRepositoryInterface /** * Return object with all found meta field things. * - * @param int $journalId - * @param array $fields + * @param int $journalId + * @param array $fields * * @return NullArrayObject */ @@ -116,7 +116,7 @@ interface TransactionGroupRepositoryInterface /** * Get the note text for a journal (by ID). * - * @param int $journalId + * @param int $journalId * * @return string|null */ @@ -125,7 +125,7 @@ interface TransactionGroupRepositoryInterface /** * Return all piggy bank events for all journals in the group. * - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array */ @@ -134,7 +134,7 @@ interface TransactionGroupRepositoryInterface /** * Get the tags for a journal (by ID) as Tag objects. * - * @param int $journalId + * @param int $journalId * * @return Collection */ @@ -143,7 +143,7 @@ interface TransactionGroupRepositoryInterface /** * Get the tags for a journal (by ID). * - * @param int $journalId + * @param int $journalId * * @return array */ @@ -152,14 +152,14 @@ interface TransactionGroupRepositoryInterface /** * Set the user. * - * @param User $user + * @param User $user */ public function setUser(User $user): void; /** * Create a new transaction group. * - * @param array $data + * @param array $data * * @return TransactionGroup * @throws DuplicateTransactionException @@ -170,8 +170,8 @@ interface TransactionGroupRepositoryInterface /** * Update an existing transaction group. * - * @param TransactionGroup $transactionGroup - * @param array $data + * @param TransactionGroup $transactionGroup + * @param array $data * * @return TransactionGroup */ diff --git a/app/Repositories/TransactionType/TransactionTypeRepository.php b/app/Repositories/TransactionType/TransactionTypeRepository.php index 62e8071169..40f8edb19b 100644 --- a/app/Repositories/TransactionType/TransactionTypeRepository.php +++ b/app/Repositories/TransactionType/TransactionTypeRepository.php @@ -33,8 +33,8 @@ use Log; class TransactionTypeRepository implements TransactionTypeRepositoryInterface { /** - * @param TransactionType|null $type - * @param string|null $typeString + * @param TransactionType|null $type + * @param string|null $typeString * * @return TransactionType */ @@ -57,7 +57,7 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface } /** - * @param string $type + * @param string $type * * @return TransactionType|null */ @@ -69,8 +69,8 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface } /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ diff --git a/app/Repositories/TransactionType/TransactionTypeRepositoryInterface.php b/app/Repositories/TransactionType/TransactionTypeRepositoryInterface.php index ff4c4b296f..f0a1e4c19a 100644 --- a/app/Repositories/TransactionType/TransactionTypeRepositoryInterface.php +++ b/app/Repositories/TransactionType/TransactionTypeRepositoryInterface.php @@ -32,23 +32,23 @@ use Illuminate\Support\Collection; interface TransactionTypeRepositoryInterface { /** - * @param string $type + * @param string $type * * @return TransactionType|null */ public function findByType(string $type): ?TransactionType; /** - * @param TransactionType|null $type - * @param string|null $typeString + * @param TransactionType|null $type + * @param string|null $typeString * * @return TransactionType */ public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType; /** - * @param string $query - * @param int $limit + * @param string $query + * @param int $limit * * @return Collection */ diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php index baa06ead7e..3a49eb1893 100644 --- a/app/Repositories/User/UserRepository.php +++ b/app/Repositories/User/UserRepository.php @@ -1,4 +1,5 @@ setForUser($user, 'previous_email_latest', $oldEmail); - app('preferences')->setForUser($user, 'previous_email_' . date('Y-m-d-H-i-s'), $oldEmail); + app('preferences')->setForUser($user, 'previous_email_'.date('Y-m-d-H-i-s'), $oldEmail); // set undo and confirm token: app('preferences')->setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16))); @@ -75,8 +76,8 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user - * @param string $password + * @param User $user + * @param string $password * * @return bool */ @@ -89,9 +90,9 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user - * @param bool $isBlocked - * @param string $code + * @param User $user + * @param bool $isBlocked + * @param string $code * * @return bool */ @@ -106,9 +107,9 @@ class UserRepository implements UserRepositoryInterface } /** - * @param string $name - * @param string $displayName - * @param string $description + * @param string $name + * @param string $displayName + * @param string $description * * @return Role */ @@ -118,7 +119,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user + * @param User $user * * @return bool * @throws Exception @@ -167,7 +168,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param int $userId + * @param int $userId * * @return User|null */ @@ -177,7 +178,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param string $email + * @param string $email * * @return User|null */ @@ -197,7 +198,15 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user + * @inheritDoc + */ + public function getInvitedUsers(): Collection + { + return InvitedUser::with('user')->get(); + } + + /** + * @param User $user * * @return string|null */ @@ -215,7 +224,7 @@ class UserRepository implements UserRepositoryInterface /** * Return basic user information. * - * @param User $user + * @param User $user * * @return array */ @@ -226,7 +235,7 @@ class UserRepository implements UserRepositoryInterface // two factor: $return['has_2fa'] = $user->mfa_secret !== null; $return['is_admin'] = $this->hasRole($user, 'owner'); - $return['blocked'] = 1 === (int) $user->blocked; + $return['blocked'] = 1 === (int)$user->blocked; $return['blocked_code'] = $user->blocked_code; $return['accounts'] = $user->accounts()->count(); $return['journals'] = $user->transactionJournals()->count(); @@ -250,8 +259,8 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user - * @param string $role + * @param User $user + * @param string $role * * @return bool */ @@ -285,11 +294,23 @@ class UserRepository implements UserRepositoryInterface return $invitee; } + /** + * @inheritDoc + */ + public function redeemCode(string $code): void + { + $obj = InvitedUser::where('invite_code', $code)->where('redeemed', 0)->first(); + if ($obj) { + $obj->redeemed = true; + $obj->save(); + } + } + /** * Set MFA code. * - * @param User $user - * @param string|null $code + * @param User $user + * @param string|null $code */ public function setMFACode(User $user, ?string $code): void { @@ -298,7 +319,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param array $data + * @param array $data * * @return User */ @@ -321,8 +342,8 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user - * @param string $role + * @param User $user + * @param string $role * * @return bool */ @@ -346,7 +367,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param User $user + * @param User $user */ public function unblockUser(User $user): void { @@ -358,8 +379,8 @@ class UserRepository implements UserRepositoryInterface /** * Update user info. * - * @param User $user - * @param array $data + * @param User $user + * @param array $data * * @return User * @throws FireflyException @@ -387,8 +408,8 @@ class UserRepository implements UserRepositoryInterface * This updates the users email address. Same as changeEmail just without most logging. This makes sure that the undo/confirm routine can't catch this one. * The user is NOT blocked. * - * @param User $user - * @param string $newEmail + * @param User $user + * @param string $newEmail * * @return bool * @throws FireflyException @@ -403,7 +424,7 @@ class UserRepository implements UserRepositoryInterface // save old email as pref app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail); - app('preferences')->setForUser($user, 'admin_previous_email_' . date('Y-m-d-H-i-s'), $oldEmail); + app('preferences')->setForUser($user, 'admin_previous_email_'.date('Y-m-d-H-i-s'), $oldEmail); $user->email = $newEmail; $user->save(); @@ -414,8 +435,8 @@ class UserRepository implements UserRepositoryInterface /** * Remove any role the user has. * - * @param User $user - * @param string $role + * @param User $user + * @param string $role */ public function removeRole(User $user, string $role): void { @@ -427,7 +448,7 @@ class UserRepository implements UserRepositoryInterface } /** - * @param string $role + * @param string $role * * @return Role|null */ @@ -436,14 +457,6 @@ class UserRepository implements UserRepositoryInterface return Role::where('name', $role)->first(); } - /** - * @inheritDoc - */ - public function getInvitedUsers(): Collection - { - return InvitedUser::with('user')->get(); - } - /** * @inheritDoc */ @@ -453,16 +466,4 @@ class UserRepository implements UserRepositoryInterface $invitee = InvitedUser::where('invite_code', $code)->where('expires', '>', $now->format('Y-m-d H:i:s'))->where('redeemed', 0)->first(); return null !== $invitee; } - - /** - * @inheritDoc - */ - public function redeemCode(string $code): void - { - $obj = InvitedUser::where('invite_code', $code)->where('redeemed', 0)->first(); - if ($obj) { - $obj->redeemed = true; - $obj->save(); - } - } } diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.php index 040ca46f7c..cd5aeb4f24 100644 --- a/app/Repositories/User/UserRepositoryInterface.php +++ b/app/Repositories/User/UserRepositoryInterface.php @@ -1,4 +1,5 @@ check()) { return true; } - $attribute = (string) $attribute; + $attribute = (string)$attribute; Log::debug(sprintf('Going to validate %s', $attribute)); return match ($attribute) { - 'piggy_bank_id' => $this->validatePiggyBankId((int) $value), + 'piggy_bank_id' => $this->validatePiggyBankId((int)$value), 'piggy_bank_name' => $this->validatePiggyBankName($value), - 'bill_id' => $this->validateBillId((int) $value), - 'transaction_journal_id' => $this->validateJournalId((int) $value), + 'bill_id' => $this->validateBillId((int)$value), + 'transaction_journal_id' => $this->validateJournalId((int)$value), 'bill_name' => $this->validateBillName($value), - 'budget_id' => $this->validateBudgetId((int) $value), - 'category_id' => $this->validateCategoryId((int) $value), + 'budget_id' => $this->validateBudgetId((int)$value), + 'category_id' => $this->validateCategoryId((int)$value), 'budget_name' => $this->validateBudgetName($value), - 'source_id', 'destination_id' => $this->validateAccountId((int) $value), + 'source_id', 'destination_id' => $this->validateAccountId((int)$value), default => throw new FireflyException(sprintf('Rule BelongUser cannot handle "%s"', $attribute)), }; } /** - * @param string $attribute + * @param string $attribute * * @return string */ @@ -113,7 +113,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -127,7 +127,7 @@ class BelongsUser implements Rule } /** - * @param string $value + * @param string $value * * @return bool */ @@ -139,9 +139,9 @@ class BelongsUser implements Rule } /** - * @param string $class - * @param string $field - * @param string $value + * @param string $class + * @param string $field + * @param string $value * * @return int * @@ -160,7 +160,7 @@ class BelongsUser implements Rule } $count = 0; foreach ($objects as $object) { - $objectValue = trim((string) $object->$field); + $objectValue = trim((string)$object->$field); Log::debug(sprintf('Comparing object "%s" with value "%s"', $objectValue, $value)); if ($objectValue === $value) { $count++; @@ -172,7 +172,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -187,7 +187,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -202,7 +202,7 @@ class BelongsUser implements Rule } /** - * @param string $value + * @param string $value * * @return bool */ @@ -215,7 +215,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -230,7 +230,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -242,7 +242,7 @@ class BelongsUser implements Rule } /** - * @param string $value + * @param string $value * * @return bool */ @@ -254,7 +254,7 @@ class BelongsUser implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ diff --git a/app/Rules/IsAssetAccountId.php b/app/Rules/IsAssetAccountId.php index f30a327b58..7eb32b0d9d 100644 --- a/app/Rules/IsAssetAccountId.php +++ b/app/Rules/IsAssetAccountId.php @@ -1,4 +1,5 @@ find($accountId); if (null === $account) { return false; diff --git a/app/Rules/IsBoolean.php b/app/Rules/IsBoolean.php index f4e034829b..5ccea1498b 100644 --- a/app/Rules/IsBoolean.php +++ b/app/Rules/IsBoolean.php @@ -39,14 +39,14 @@ class IsBoolean implements Rule */ public function message(): string { - return (string) trans('validation.boolean'); + return (string)trans('validation.boolean'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ diff --git a/app/Rules/IsDateOrTime.php b/app/Rules/IsDateOrTime.php index 63c5a63139..0fb9fff6b6 100644 --- a/app/Rules/IsDateOrTime.php +++ b/app/Rules/IsDateOrTime.php @@ -43,20 +43,20 @@ class IsDateOrTime implements Rule */ public function message() { - return (string) trans('validation.date_or_time'); + return (string)trans('validation.date_or_time'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ public function passes($attribute, $value): bool { - $value = (string) $value; + $value = (string)$value; if ('' === $value) { return false; } diff --git a/app/Rules/IsTransferAccount.php b/app/Rules/IsTransferAccount.php index 27103b1c8d..7cf7f00e0d 100644 --- a/app/Rules/IsTransferAccount.php +++ b/app/Rules/IsTransferAccount.php @@ -41,14 +41,14 @@ class IsTransferAccount implements Rule */ public function message(): string { - return (string) trans('validation.not_transfer_account'); + return (string)trans('validation.not_transfer_account'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ @@ -60,15 +60,15 @@ class IsTransferAccount implements Rule $validator->setTransactionType(TransactionType::TRANSFER); $validator->setUser(auth()->user()); - $validAccount = $validator->validateSource(['name' => (string) $value,]); + $validAccount = $validator->validateSource(['name' => (string)$value,]); if (true === $validAccount) { Log::debug('Found account based on name. Return true.'); // found by name, use repos to return. return true; } - $validAccount = $validator->validateSource(['id' => (int) $value,]); - Log::debug(sprintf('Search by id (%d), result is %s.', (int) $value, var_export($validAccount, true))); + $validAccount = $validator->validateSource(['id' => (int)$value,]); + Log::debug(sprintf('Search by id (%d), result is %s.', (int)$value, var_export($validAccount, true))); return false !== $validAccount; } diff --git a/app/Rules/IsValidAttachmentModel.php b/app/Rules/IsValidAttachmentModel.php index 1b6ec0dd56..8de8a7205f 100644 --- a/app/Rules/IsValidAttachmentModel.php +++ b/app/Rules/IsValidAttachmentModel.php @@ -55,7 +55,7 @@ class IsValidAttachmentModel implements Rule * * @codeCoverageIgnore * - * @param string $model + * @param string $model */ public function __construct(string $model) { @@ -64,7 +64,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param string $model + * @param string $model * * @return string */ @@ -85,14 +85,14 @@ class IsValidAttachmentModel implements Rule */ public function message(): string { - return (string) trans('validation.model_id_invalid'); + return (string)trans('validation.model_id_invalid'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ @@ -118,11 +118,11 @@ class IsValidAttachmentModel implements Rule } $method = $methods[$this->model]; - return $this->$method((int) $value); + return $this->$method((int)$value); } /** - * @param int $value + * @param int $value * * @return bool */ @@ -136,7 +136,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -150,7 +150,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -164,7 +164,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -178,7 +178,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -191,7 +191,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -205,7 +205,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -219,7 +219,7 @@ class IsValidAttachmentModel implements Rule } /** - * @param int $value + * @param int $value * * @return bool */ @@ -229,6 +229,6 @@ class IsValidAttachmentModel implements Rule $repository = app(JournalAPIRepositoryInterface::class); $repository->setUser(auth()->user()); - return null !== $repository->findTransaction((int) $value); + return null !== $repository->findTransaction((int)$value); } } diff --git a/app/Rules/IsValidBulkClause.php b/app/Rules/IsValidBulkClause.php index 9b35893fb8..6211463fca 100644 --- a/app/Rules/IsValidBulkClause.php +++ b/app/Rules/IsValidBulkClause.php @@ -37,12 +37,12 @@ class IsValidBulkClause implements Rule private array $rules; /** - * @param string $type + * @param string $type */ public function __construct(string $type) { $this->rules = config(sprintf('bulk.%s', $type)); - $this->error = (string) trans('firefly.belongs_user'); + $this->error = (string)trans('firefly.belongs_user'); } /** @@ -54,14 +54,14 @@ class IsValidBulkClause implements Rule } /** - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ public function passes($attribute, $value): bool { - $result = $this->basicValidation((string) $value); + $result = $this->basicValidation((string)$value); if (false === $result) { return false; } @@ -72,7 +72,7 @@ class IsValidBulkClause implements Rule /** * Does basic rule based validation. * - * @param string $value + * @param string $value * * @return bool */ @@ -81,24 +81,24 @@ class IsValidBulkClause implements Rule try { $array = json_decode($value, true, 8, JSON_THROW_ON_ERROR); } catch (JsonException $e) { - $this->error = (string) trans('validation.json'); + $this->error = (string)trans('validation.json'); return false; } $clauses = ['where', 'update']; foreach ($clauses as $clause) { if (!array_key_exists($clause, $array)) { - $this->error = (string) trans(sprintf('validation.missing_%s', $clause)); + $this->error = (string)trans(sprintf('validation.missing_%s', $clause)); return false; } /** * @var string $arrayKey - * @var mixed $arrayValue + * @var mixed $arrayValue */ foreach ($array[$clause] as $arrayKey => $arrayValue) { if (!array_key_exists($arrayKey, $this->rules[$clause])) { - $this->error = (string) trans(sprintf('validation.invalid_%s_key', $clause)); + $this->error = (string)trans(sprintf('validation.invalid_%s_key', $clause)); return false; } diff --git a/app/Rules/LessThanPiggyTarget.php b/app/Rules/LessThanPiggyTarget.php index 9e4567ec55..8ac44f63f5 100644 --- a/app/Rules/LessThanPiggyTarget.php +++ b/app/Rules/LessThanPiggyTarget.php @@ -38,14 +38,14 @@ class LessThanPiggyTarget implements Rule */ public function message(): string { - return (string) trans('validation.current_target_amount'); + return (string)trans('validation.current_target_amount'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool */ diff --git a/app/Rules/UniqueAccountNumber.php b/app/Rules/UniqueAccountNumber.php index 32b5e80474..4bc92a4c44 100644 --- a/app/Rules/UniqueAccountNumber.php +++ b/app/Rules/UniqueAccountNumber.php @@ -42,8 +42,8 @@ class UniqueAccountNumber implements Rule * * @codeCoverageIgnore * - * @param Account|null $account - * @param string|null $expectedType + * @param Account|null $account + * @param string|null $expectedType */ public function __construct(?Account $account, ?string $expectedType) { @@ -72,14 +72,14 @@ class UniqueAccountNumber implements Rule */ public function message(): string { - return (string) trans('validation.unique_account_number_for_user'); + return (string)trans('validation.unique_account_number_for_user'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool * @@ -143,19 +143,19 @@ class UniqueAccountNumber implements Rule } /** - * @param string $type - * @param string $accountNumber + * @param string $type + * @param string $accountNumber * * @return int */ private function countHits(string $type, string $accountNumber): int { $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') - ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') - ->where('accounts.user_id', auth()->user()->id) - ->where('account_types.type', $type) - ->where('account_meta.name', '=', 'account_number') - ->where('account_meta.data', json_encode($accountNumber)); + ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') + ->where('accounts.user_id', auth()->user()->id) + ->where('account_types.type', $type) + ->where('account_meta.name', '=', 'account_number') + ->where('account_meta.data', json_encode($accountNumber)); if (null !== $this->account) { $query->where('accounts.id', '!=', $this->account->id); diff --git a/app/Rules/UniqueIban.php b/app/Rules/UniqueIban.php index 6b807e04b9..5edebb1199 100644 --- a/app/Rules/UniqueIban.php +++ b/app/Rules/UniqueIban.php @@ -41,8 +41,8 @@ class UniqueIban implements Rule * * @codeCoverageIgnore * - * @param Account|null $account - * @param string|null $expectedType + * @param Account|null $account + * @param string|null $expectedType */ public function __construct(?Account $account, ?string $expectedType) { @@ -69,14 +69,14 @@ class UniqueIban implements Rule */ public function message(): string { - return (string) trans('validation.unique_iban_for_user'); + return (string)trans('validation.unique_iban_for_user'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool * @@ -139,8 +139,8 @@ class UniqueIban implements Rule } /** - * @param string $type - * @param string $iban + * @param string $type + * @param string $iban * * @return int */ diff --git a/app/Rules/ValidJournals.php b/app/Rules/ValidJournals.php index e9575a4bc8..5618fbfe98 100644 --- a/app/Rules/ValidJournals.php +++ b/app/Rules/ValidJournals.php @@ -42,14 +42,14 @@ class ValidJournals implements Rule */ public function message(): string { - return (string) trans('validation.invalid_selection'); + return (string)trans('validation.invalid_selection'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool * diff --git a/app/Rules/ValidRecurrenceRepetitionType.php b/app/Rules/ValidRecurrenceRepetitionType.php index f8c1d0188f..74af36d979 100644 --- a/app/Rules/ValidRecurrenceRepetitionType.php +++ b/app/Rules/ValidRecurrenceRepetitionType.php @@ -39,21 +39,21 @@ class ValidRecurrenceRepetitionType implements Rule */ public function message(): string { - return (string) trans('validation.valid_recurrence_rep_type'); + return (string)trans('validation.valid_recurrence_rep_type'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool * */ public function passes($attribute, $value): bool { - $value = (string) $value; + $value = (string)$value; if ('daily' === $value) { return true; } diff --git a/app/Rules/ValidRecurrenceRepetitionValue.php b/app/Rules/ValidRecurrenceRepetitionValue.php index f9fd59b45f..8860d5a6d8 100644 --- a/app/Rules/ValidRecurrenceRepetitionValue.php +++ b/app/Rules/ValidRecurrenceRepetitionValue.php @@ -42,21 +42,21 @@ class ValidRecurrenceRepetitionValue implements Rule */ public function message(): string { - return (string) trans('validation.valid_recurrence_rep_type'); + return (string)trans('validation.valid_recurrence_rep_type'); } /** * Determine if the validation rule passes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param mixed $value * * @return bool * */ public function passes($attribute, $value): bool { - $value = (string) $value; + $value = (string)$value; if ('daily' === $value) { return true; @@ -86,19 +86,19 @@ class ValidRecurrenceRepetitionValue implements Rule } /** - * @param string $value + * @param string $value * * @return bool */ private function validateMonthly(string $value): bool { - $dayOfMonth = (int) substr($value, 8); + $dayOfMonth = (int)substr($value, 8); return $dayOfMonth > 0 && $dayOfMonth < 32; } /** - * @param string $value + * @param string $value * * @return bool * @@ -109,8 +109,8 @@ class ValidRecurrenceRepetitionValue implements Rule if (2 !== count($parameters)) { return false; } - $nthDay = (int) ($parameters[0] ?? 0.0); - $dayOfWeek = (int) ($parameters[1] ?? 0.0); + $nthDay = (int)($parameters[0] ?? 0.0); + $dayOfWeek = (int)($parameters[1] ?? 0.0); if ($nthDay < 1 || $nthDay > 5) { return false; } @@ -119,19 +119,19 @@ class ValidRecurrenceRepetitionValue implements Rule } /** - * @param string $value + * @param string $value * * @return bool */ private function validateWeekly(string $value): bool { - $dayOfWeek = (int) substr($value, 7); + $dayOfWeek = (int)substr($value, 7); return $dayOfWeek > 0 && $dayOfWeek < 8; } /** - * @param string $value + * @param string $value * * @return bool */ diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php index 9dd876f513..d8d5b24ebe 100644 --- a/app/Services/FireflyIIIOrg/Update/UpdateRequest.php +++ b/app/Services/FireflyIIIOrg/Update/UpdateRequest.php @@ -37,7 +37,7 @@ use Log; class UpdateRequest implements UpdateRequestInterface { /** - * @param string $channel + * @param string $channel * * @return array */ @@ -46,7 +46,7 @@ class UpdateRequest implements UpdateRequestInterface Log::debug(sprintf('Now in getUpdateInformation(%s)', $channel)); $information = [ 'level' => 'error', - 'message' => (string) trans('firefly.unknown_error'), + 'message' => (string)trans('firefly.unknown_error'), ]; // try get array from update server: @@ -64,7 +64,7 @@ class UpdateRequest implements UpdateRequestInterface } /** - * @param string $channel + * @param string $channel * * @return array */ @@ -76,7 +76,7 @@ class UpdateRequest implements UpdateRequestInterface 'version' => config('firefly.version'), 'date' => Carbon::today()->startOfDay(), 'level' => 'error', - 'message' => (string) trans('firefly.unknown_error'), + 'message' => (string)trans('firefly.unknown_error'), ]; $url = config('firefly.update_endpoint'); @@ -101,12 +101,12 @@ class UpdateRequest implements UpdateRequestInterface if (200 !== $res->getStatusCode()) { Log::error(sprintf('Response status from server is %d.', $res->getStatusCode())); - Log::error((string) $res->getBody()); + Log::error((string)$res->getBody()); $return['message'] = sprintf('Error: %d', $res->getStatusCode()); return $return; } - $body = (string) $res->getBody(); + $body = (string)$res->getBody(); try { $json = json_decode($body, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { @@ -134,7 +134,7 @@ class UpdateRequest implements UpdateRequestInterface } /** - * @param array $information + * @param array $information * * @return array */ @@ -143,7 +143,7 @@ class UpdateRequest implements UpdateRequestInterface Log::debug('Now in parseResult()', $information); $return = [ 'level' => 'error', - 'message' => (string) trans('firefly.unknown_error'), + 'message' => (string)trans('firefly.unknown_error'), ]; $current = config('firefly.version'); $latest = $information['version']; @@ -154,7 +154,7 @@ class UpdateRequest implements UpdateRequestInterface // -1: you're running a newer version: if (-1 === $compare) { $return['level'] = 'info'; - $return['message'] = (string) trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $latest]); + $return['message'] = (string)trans('firefly.update_newer_version_alert', ['your_version' => $current, 'new_version' => $latest]); Log::debug('User is running a newer version', $return); return $return; @@ -162,7 +162,7 @@ class UpdateRequest implements UpdateRequestInterface // running the current version: if (0 === $compare) { $return['level'] = 'info'; - $return['message'] = (string) trans('firefly.update_current_version_alert', ['version' => $current]); + $return['message'] = (string)trans('firefly.update_current_version_alert', ['version' => $current]); Log::debug('User is the current version.', $return); return $return; @@ -177,11 +177,12 @@ class UpdateRequest implements UpdateRequestInterface // it's still very fresh, and user wants a stable release: if ($diff <= $expectedDiff) { $return['level'] = 'info'; - $return['message'] = (string) trans( + $return['message'] = (string)trans( 'firefly.just_new_release', - ['version' => $latest, - 'date' => $released->isoFormat((string) trans('config.month_and_day_js')), - 'days' => $expectedDiff, + [ + 'version' => $latest, + 'date' => $released->isoFormat((string)trans('config.month_and_day_js')), + 'days' => $expectedDiff, ] ); Log::debug('Release is very fresh.', $return); @@ -191,12 +192,13 @@ class UpdateRequest implements UpdateRequestInterface // it's been around for a while: $return['level'] = 'success'; - $return['message'] = (string) trans( + $return['message'] = (string)trans( 'firefly.update_new_version_alert', [ 'your_version' => $current, 'new_version' => $latest, - 'date' => $released->isoFormat((string) trans('config.month_and_day_js'))] + 'date' => $released->isoFormat((string)trans('config.month_and_day_js')), + ] ); Log::debug('New release is old enough.'); diff --git a/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php b/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php index de0e8f294b..e616837222 100644 --- a/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php +++ b/app/Services/FireflyIIIOrg/Update/UpdateRequestInterface.php @@ -30,7 +30,7 @@ namespace FireflyIII\Services\FireflyIIIOrg\Update; interface UpdateRequestInterface { /** - * @param string $channel + * @param string $channel * * @return array */ diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php index 4a7b30f40b..52bf6d61eb 100644 --- a/app/Services/Internal/Destroy/AccountDestroyService.php +++ b/app/Services/Internal/Destroy/AccountDestroyService.php @@ -41,8 +41,8 @@ use stdClass; class AccountDestroyService { /** - * @param Account $account - * @param Account|null $moveTo + * @param Account $account + * @param Account|null $moveTo * * @return void */ @@ -76,7 +76,7 @@ class AccountDestroyService } /** - * @param Account $account + * @param Account $account */ private function destroyOpeningBalance(Account $account): void { @@ -87,13 +87,13 @@ class AccountDestroyService ->where('transaction_types.type', TransactionType::OPENING_BALANCE) ->get(['transactions.transaction_journal_id']); if ($set->count() > 0) { - $journalId = (int) $set->first()->transaction_journal_id; + $journalId = (int)$set->first()->transaction_journal_id; Log::debug(sprintf('Found opening balance journal with ID #%d', $journalId)); // get transactions with this journal (should be just one): $transactions = Transaction::where('transaction_journal_id', $journalId) - ->where('account_id', '!=', $account->id) - ->get(); + ->where('account_id', '!=', $account->id) + ->get(); /** @var Transaction $transaction */ foreach ($transactions as $transaction) { Log::debug(sprintf('Found transaction with ID #%d', $transaction->id)); @@ -112,8 +112,8 @@ class AccountDestroyService } /** - * @param Account $account - * @param Account $moveTo + * @param Account $account + * @param Account $moveTo */ public function moveTransactions(Account $account, Account $moveTo): void { @@ -132,8 +132,8 @@ class AccountDestroyService $user = $account->user; /** @var stdClass $row */ foreach ($collection as $row) { - if ((int) $row->the_count > 1) { - $journalId = (int) $row->transaction_journal_id; + if ((int)$row->the_count > 1) { + $journalId = (int)$row->transaction_journal_id; $journal = $user->transactionJournals()->find($journalId); if (null !== $journal) { Log::debug(sprintf('Deleted journal #%d because it has the same source as destination.', $journal->id)); @@ -144,8 +144,8 @@ class AccountDestroyService } /** - * @param Account $account - * @param Account $moveTo + * @param Account $account + * @param Account $moveTo */ private function updateRecurrences(Account $account, Account $moveTo): void { @@ -154,28 +154,28 @@ class AccountDestroyService } /** - * @param Account $account + * @param Account $account */ private function destroyJournals(Account $account): void { /** @var JournalDestroyService $service */ $service = app(JournalDestroyService::class); - Log::debug('Now trigger account delete response #' . $account->id); + Log::debug('Now trigger account delete response #'.$account->id); /** @var Transaction $transaction */ foreach ($account->transactions()->get() as $transaction) { - Log::debug('Now at transaction #' . $transaction->id); + Log::debug('Now at transaction #'.$transaction->id); /** @var TransactionJournal $journal */ $journal = $transaction->transactionJournal()->first(); if (null !== $journal) { - Log::debug('Call for deletion of journal #' . $journal->id); + Log::debug('Call for deletion of journal #'.$journal->id); $service->destroy($journal); } } } /** - * @param Account $account + * @param Account $account */ private function destroyRecurrences(Account $account): void { @@ -189,7 +189,7 @@ class AccountDestroyService /** @var RecurrenceDestroyService $destroyService */ $destroyService = app(RecurrenceDestroyService::class); foreach ($recurrences as $recurrenceId) { - $destroyService->destroyById((int) $recurrenceId); + $destroyService->destroyById((int)$recurrenceId); } } } diff --git a/app/Services/Internal/Destroy/BillDestroyService.php b/app/Services/Internal/Destroy/BillDestroyService.php index cd6f4d5d62..48e53f0b8b 100644 --- a/app/Services/Internal/Destroy/BillDestroyService.php +++ b/app/Services/Internal/Destroy/BillDestroyService.php @@ -33,7 +33,7 @@ use FireflyIII\Models\Bill; class BillDestroyService { /** - * @param Bill $bill + * @param Bill $bill */ public function destroy(Bill $bill): void { diff --git a/app/Services/Internal/Destroy/BudgetDestroyService.php b/app/Services/Internal/Destroy/BudgetDestroyService.php index 19595df179..df0b279b99 100644 --- a/app/Services/Internal/Destroy/BudgetDestroyService.php +++ b/app/Services/Internal/Destroy/BudgetDestroyService.php @@ -35,7 +35,7 @@ use FireflyIII\Models\Budget; class BudgetDestroyService { /** - * @param Budget $budget + * @param Budget $budget */ public function destroy(Budget $budget): void { @@ -51,10 +51,10 @@ class BudgetDestroyService } // also delete all relations between categories and transaction journals: - DB::table('budget_transaction_journal')->where('budget_id', (int) $budget->id)->delete(); + DB::table('budget_transaction_journal')->where('budget_id', (int)$budget->id)->delete(); // also delete all relations between categories and transactions: - DB::table('budget_transaction')->where('budget_id', (int) $budget->id)->delete(); + DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete(); // also delete all budget limits $budget->budgetlimits()->delete(); diff --git a/app/Services/Internal/Destroy/CategoryDestroyService.php b/app/Services/Internal/Destroy/CategoryDestroyService.php index 45facd1535..f79ec91050 100644 --- a/app/Services/Internal/Destroy/CategoryDestroyService.php +++ b/app/Services/Internal/Destroy/CategoryDestroyService.php @@ -35,7 +35,7 @@ use FireflyIII\Models\Category; class CategoryDestroyService { /** - * @param Category $category + * @param Category $category */ public function destroy(Category $category): void { @@ -46,9 +46,9 @@ class CategoryDestroyService } // also delete all relations between categories and transaction journals: - DB::table('category_transaction_journal')->where('category_id', (int) $category->id)->delete(); + DB::table('category_transaction_journal')->where('category_id', (int)$category->id)->delete(); // also delete all relations between categories and transactions: - DB::table('category_transaction')->where('category_id', (int) $category->id)->delete(); + DB::table('category_transaction')->where('category_id', (int)$category->id)->delete(); } } diff --git a/app/Services/Internal/Destroy/CurrencyDestroyService.php b/app/Services/Internal/Destroy/CurrencyDestroyService.php index 92cb738ba9..bbaab9d043 100644 --- a/app/Services/Internal/Destroy/CurrencyDestroyService.php +++ b/app/Services/Internal/Destroy/CurrencyDestroyService.php @@ -34,7 +34,7 @@ use FireflyIII\Models\TransactionCurrency; class CurrencyDestroyService { /** - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency */ public function destroy(TransactionCurrency $currency): void { diff --git a/app/Services/Internal/Destroy/JournalDestroyService.php b/app/Services/Internal/Destroy/JournalDestroyService.php index 65a4954d8c..3d52a1c108 100644 --- a/app/Services/Internal/Destroy/JournalDestroyService.php +++ b/app/Services/Internal/Destroy/JournalDestroyService.php @@ -39,7 +39,7 @@ use Log; class JournalDestroyService { /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal */ public function destroy(TransactionJournal $journal): void { diff --git a/app/Services/Internal/Destroy/RecurrenceDestroyService.php b/app/Services/Internal/Destroy/RecurrenceDestroyService.php index 8542cf64f2..d010737f1a 100644 --- a/app/Services/Internal/Destroy/RecurrenceDestroyService.php +++ b/app/Services/Internal/Destroy/RecurrenceDestroyService.php @@ -36,7 +36,7 @@ class RecurrenceDestroyService /** * Delete recurrence by ID * - * @param int $recurrenceId + * @param int $recurrenceId */ public function destroyById(int $recurrenceId): void { @@ -50,7 +50,7 @@ class RecurrenceDestroyService /** * Delete recurrence. * - * @param Recurrence $recurrence + * @param Recurrence $recurrence * */ public function destroy(Recurrence $recurrence): void diff --git a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php index 886118eeaf..cbd4bfcfa9 100644 --- a/app/Services/Internal/Destroy/TransactionGroupDestroyService.php +++ b/app/Services/Internal/Destroy/TransactionGroupDestroyService.php @@ -35,7 +35,7 @@ use FireflyIII\Models\TransactionGroup; class TransactionGroupDestroyService { /** - * @param TransactionGroup $transactionGroup + * @param TransactionGroup $transactionGroup */ public function destroy(TransactionGroup $transactionGroup): void { diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index ebc524b083..16a77f63e3 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 JsonException; use Log; use Validator; @@ -377,7 +378,7 @@ trait AccountServiceTrait * * @return TransactionCurrency * @throws FireflyException - * @throws \JsonException + * @throws JsonException */ protected function getCurrency(int $currencyId, string $currencyCode): TransactionCurrency { diff --git a/app/Services/Internal/Support/BillServiceTrait.php b/app/Services/Internal/Support/BillServiceTrait.php index 12c71baf00..98e17fe510 100644 --- a/app/Services/Internal/Support/BillServiceTrait.php +++ b/app/Services/Internal/Support/BillServiceTrait.php @@ -37,9 +37,9 @@ use Log; trait BillServiceTrait { /** - * @param Bill $bill - * @param string $oldName - * @param string $newName + * @param Bill $bill + * @param string $oldName + * @param string $newName */ public function updateBillActions(Bill $bill, string $oldName, string $newName): void { @@ -60,8 +60,8 @@ trait BillServiceTrait } /** - * @param Bill $bill - * @param string $note + * @param Bill $bill + * @param string $note * * @return bool */ diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 1936ef51b6..c37dbf181d 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -262,7 +262,9 @@ class CreditRecalculateService && 'credit' === $direction ) { $amount = bcadd($amount, app('steam')->positive($usedAmount)); - Log::debug(sprintf('Is withdrawal (%s) into credit liability #%d, will increase amount due to %s.', $transaction->account_id, $usedAmount, $amount)); + Log::debug( + sprintf('Is withdrawal (%s) into credit liability #%d, will increase amount due to %s.', $transaction->account_id, $usedAmount, $amount) + ); return $amount; } diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php index 9c93770831..dfddffd7ac 100644 --- a/app/Services/Internal/Support/JournalServiceTrait.php +++ b/app/Services/Internal/Support/JournalServiceTrait.php @@ -50,9 +50,9 @@ trait JournalServiceTrait private TagFactory $tagFactory; /** - * @param string $transactionType - * @param string $direction - * @param array $data + * @param string $transactionType + * @param string $direction + * @param array $data * * @return Account|null * @codeCoverageIgnore @@ -88,8 +88,8 @@ trait JournalServiceTrait } /** - * @param array $data - * @param array $types + * @param array $data + * @param array $types * * @return Account|null */ @@ -98,7 +98,7 @@ trait JournalServiceTrait $search = null; // first attempt, find by ID. if (null !== $data['id']) { - $search = $this->accountRepository->find((int) $data['id']); + $search = $this->accountRepository->find((int)$data['id']); if (null !== $search && in_array($search->accountType->type, $types, true)) { Log::debug( sprintf('Found "account_id" object: #%d, "%s" of type %s', $search->id, $search->name, $search->accountType->type) @@ -110,9 +110,9 @@ trait JournalServiceTrait } /** - * @param Account|null $account - * @param array $data - * @param array $types + * @param Account|null $account + * @param array $data + * @param array $types * * @return Account|null */ @@ -137,22 +137,22 @@ trait JournalServiceTrait } /** - * @param Account|null $account - * @param array $data - * @param array $types + * @param Account|null $account + * @param array $data + * @param array $types * * @return Account|null */ private function findAccountByNumber(?Account $account, array $data, array $types): ?Account { // third attempt, find by account number - if (null === $account && null !== $data['number'] && '' !== (string) $data['number']) { + if (null === $account && null !== $data['number'] && '' !== (string)$data['number']) { Log::debug(sprintf('Searching for account number "%s".', $data['number'])); // find by preferred type. - $source = $this->accountRepository->findByAccountNumber((string) $data['number'], [$types[0]]); + $source = $this->accountRepository->findByAccountNumber((string)$data['number'], [$types[0]]); // or any expected type. - $source = $source ?? $this->accountRepository->findByAccountNumber((string) $data['number'], $types); + $source = $source ?? $this->accountRepository->findByAccountNumber((string)$data['number'], $types); if (null !== $source) { Log::debug(sprintf('Found account: #%d, %s', $source->id, $source->name)); @@ -165,9 +165,9 @@ trait JournalServiceTrait } /** - * @param Account|null $account - * @param array $data - * @param array $types + * @param Account|null $account + * @param array $data + * @param array $types * * @return Account|null */ @@ -191,9 +191,9 @@ trait JournalServiceTrait } /** - * @param Account|null $account - * @param array $data - * @param string $preferredType + * @param Account|null $account + * @param array $data + * @param string $preferredType * * @return Account|null * @throws FireflyException @@ -218,12 +218,12 @@ trait JournalServiceTrait throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data))); } // fix name of account if only IBAN is given: - if ('' === (string) $data['name'] && '' !== (string) $data['iban']) { + if ('' === (string)$data['name'] && '' !== (string)$data['iban']) { Log::debug(sprintf('Account name is now IBAN ("%s")', $data['iban'])); $data['name'] = $data['iban']; } // fix name of account if only number is given: - if ('' === (string) $data['name'] && '' !== (string) $data['number']) { + if ('' === (string)$data['name'] && '' !== (string)$data['number']) { Log::debug(sprintf('Account name is now account number ("%s")', $data['number'])); $data['name'] = $data['number']; } @@ -264,16 +264,16 @@ trait JournalServiceTrait } /** - * @param Account|null $account - * @param array $data - * @param array $types + * @param Account|null $account + * @param array $data + * @param array $types * * @return Account|null */ private function getCashAccount(?Account $account, array $data, array $types): ?Account { // return cash account. - if (null === $account && '' === (string) $data['name'] + if (null === $account && '' === (string)$data['name'] && in_array(AccountType::CASH, $types, true)) { $account = $this->accountRepository->getCashAccount(); } @@ -282,7 +282,7 @@ trait JournalServiceTrait } /** - * @param string $amount + * @param string $amount * * @return string * @throws FireflyException @@ -302,7 +302,7 @@ trait JournalServiceTrait } /** - * @param string|null $amount + * @param string|null $amount * * @return string|null * @codeCoverageIgnore @@ -330,8 +330,8 @@ trait JournalServiceTrait } /** - * @param TransactionJournal $journal - * @param NullArrayObject $data + * @param TransactionJournal $journal + * @param NullArrayObject $data * * @codeCoverageIgnore */ @@ -354,8 +354,8 @@ trait JournalServiceTrait } /** - * @param TransactionJournal $journal - * @param NullArrayObject $data + * @param TransactionJournal $journal + * @param NullArrayObject $data * * @codeCoverageIgnore */ @@ -373,14 +373,14 @@ trait JournalServiceTrait } /** - * @param TransactionJournal $journal - * @param string|null $notes + * @param TransactionJournal $journal + * @param string|null $notes * * @codeCoverageIgnore */ protected function storeNotes(TransactionJournal $journal, ?string $notes): void { - $notes = (string) $notes; + $notes = (string)$notes; $note = $journal->notes()->first(); if ('' !== $notes) { if (null === $note) { @@ -406,8 +406,8 @@ trait JournalServiceTrait /** * Link tags to journal. * - * @param TransactionJournal $journal - * @param array|null $tags + * @param TransactionJournal $journal + * @param array|null $tags * * @codeCoverageIgnore */ @@ -423,7 +423,7 @@ trait JournalServiceTrait } Log::debug('Start of loop.'); foreach ($tags as $string) { - $string = (string) $string; + $string = (string)$string; Log::debug(sprintf('Now at tag "%s"', $string)); if ('' !== $string) { $tag = $this->tagFactory->findOrCreate($string); diff --git a/app/Services/Internal/Support/LocationServiceTrait.php b/app/Services/Internal/Support/LocationServiceTrait.php index c2e1766e68..4652928a2b 100644 --- a/app/Services/Internal/Support/LocationServiceTrait.php +++ b/app/Services/Internal/Support/LocationServiceTrait.php @@ -33,8 +33,8 @@ use Illuminate\Database\Eloquent\Model; trait LocationServiceTrait { /** - * @param Model $model - * @param array $data + * @param Model $model + * @param array $data * * @return Location|null */ diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index 93eedd04bc..c3b0665c23 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -41,6 +41,7 @@ use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransactionMeta; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Validation\AccountValidator; +use JsonException; use Log; /** @@ -50,8 +51,8 @@ use Log; trait RecurringTransactionTrait { /** - * @param Recurrence $recurrence - * @param string $note + * @param Recurrence $recurrence + * @param string $note * * @return bool */ @@ -81,8 +82,8 @@ trait RecurringTransactionTrait } /** - * @param Recurrence $recurrence - * @param array $repetitions + * @param Recurrence $recurrence + * @param array $repetitions */ protected function createRepetitions(Recurrence $recurrence, array $repetitions): void { @@ -103,11 +104,11 @@ trait RecurringTransactionTrait /** * Store transactions of a recurring transactions. It's complex but readable. * - * @param Recurrence $recurrence - * @param array $transactions + * @param Recurrence $recurrence + * @param array $transactions * * @throws FireflyException - * @throws \JsonException + * @throws JsonException */ protected function createTransactions(Recurrence $recurrence, array $transactions): void { @@ -144,7 +145,7 @@ trait RecurringTransactionTrait if (!$validator->validateDestination(['id' => $destination->id])) { throw new FireflyException(sprintf('Destination invalid: %s', $validator->destError)); } - if (array_key_exists('foreign_amount', $array) && '' === (string) $array['foreign_amount']) { + if (array_key_exists('foreign_amount', $array) && '' === (string)$array['foreign_amount']) { unset($array['foreign_amount']); } // TODO typeOverrule. The account validator may have a different opinion on the type of the transaction. @@ -156,25 +157,25 @@ trait RecurringTransactionTrait 'source_id' => $source->id, 'destination_id' => $destination->id, 'amount' => $array['amount'], - 'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string) $array['foreign_amount'] : null, + 'foreign_amount' => array_key_exists('foreign_amount', $array) ? (string)$array['foreign_amount'] : null, 'description' => $array['description'], ] ); $transaction->save(); if (array_key_exists('budget_id', $array)) { - $this->setBudget($transaction, (int) $array['budget_id']); + $this->setBudget($transaction, (int)$array['budget_id']); } if (array_key_exists('bill_id', $array)) { - $this->setBill($transaction, (int) $array['bill_id']); + $this->setBill($transaction, (int)$array['bill_id']); } if (array_key_exists('category_id', $array)) { - $this->setCategory($transaction, (int) $array['category_id']); + $this->setCategory($transaction, (int)$array['category_id']); } // same for piggy bank if (array_key_exists('piggy_bank_id', $array)) { - $this->updatePiggyBank($transaction, (int) $array['piggy_bank_id']); + $this->updatePiggyBank($transaction, (int)$array['piggy_bank_id']); } if (array_key_exists('tags', $array) && is_array($array['tags'])) { @@ -184,23 +185,23 @@ trait RecurringTransactionTrait } /** - * @param array $expectedTypes - * @param int|null $accountId - * @param string|null $accountName + * @param array $expectedTypes + * @param int|null $accountId + * @param string|null $accountName * * @return Account */ protected function findAccount(array $expectedTypes, ?int $accountId, ?string $accountName): Account { $result = null; - $accountId = (int) $accountId; - $accountName = (string) $accountName; + $accountId = (int)$accountId; + $accountName = (string)$accountName; /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $repository->setUser($this->user); // if user has submitted an account ID, search for it. - $result = $repository->find((int) $accountId); + $result = $repository->find((int)$accountId); if (null !== $result) { return $result; } @@ -234,8 +235,8 @@ trait RecurringTransactionTrait } /** - * @param RecurrenceTransaction $transaction - * @param int $budgetId + * @param RecurrenceTransaction $transaction + * @param int $budgetId */ private function setBudget(RecurrenceTransaction $transaction, int $budgetId): void { @@ -257,8 +258,8 @@ trait RecurringTransactionTrait } /** - * @param RecurrenceTransaction $transaction - * @param int $billId + * @param RecurrenceTransaction $transaction + * @param int $billId */ private function setBill(RecurrenceTransaction $transaction, int $billId): void { @@ -280,8 +281,8 @@ trait RecurringTransactionTrait } /** - * @param RecurrenceTransaction $transaction - * @param int $categoryId + * @param RecurrenceTransaction $transaction + * @param int $categoryId * * @throws FireflyException */ @@ -309,8 +310,8 @@ trait RecurringTransactionTrait } /** - * @param RecurrenceTransaction $transaction - * @param int $piggyId + * @param RecurrenceTransaction $transaction + * @param int $piggyId */ protected function updatePiggyBank(RecurrenceTransaction $transaction, int $piggyId): void { @@ -334,8 +335,8 @@ trait RecurringTransactionTrait } /** - * @param RecurrenceTransaction $transaction - * @param array $tags + * @param RecurrenceTransaction $transaction + * @param array $tags */ protected function updateTags(RecurrenceTransaction $transaction, array $tags): void { @@ -355,7 +356,7 @@ trait RecurringTransactionTrait } /** - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @codeCoverageIgnore */ @@ -365,7 +366,7 @@ trait RecurringTransactionTrait } /** - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @codeCoverageIgnore */ diff --git a/app/Services/Internal/Support/TransactionTypeTrait.php b/app/Services/Internal/Support/TransactionTypeTrait.php index b21f9f03dc..518f06a327 100644 --- a/app/Services/Internal/Support/TransactionTypeTrait.php +++ b/app/Services/Internal/Support/TransactionTypeTrait.php @@ -38,7 +38,7 @@ trait TransactionTypeTrait * Get the transaction type. Since this is mandatory, will throw an exception when nothing comes up. Will always * use TransactionType repository. * - * @param string $type + * @param string $type * * @return TransactionType * @throws FireflyException diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php index 57029d206e..8c177f7732 100644 --- a/app/Services/Internal/Update/AccountUpdateService.php +++ b/app/Services/Internal/Update/AccountUpdateService.php @@ -62,19 +62,11 @@ class AccountUpdateService $this->accountRepository = app(AccountRepositoryInterface::class); } - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } - /** * Update account data. * - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data * * @return Account * @throws FireflyException @@ -89,7 +81,7 @@ class AccountUpdateService // find currency, or use default currency instead. if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) { - $currency = $this->getCurrency((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null)); + $currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null)); unset($data['currency_code'], $data['currency_id']); $data['currency_id'] = $currency->id; } @@ -108,7 +100,7 @@ class AccountUpdateService // update note: if (array_key_exists('notes', $data) && null !== $data['notes']) { - $this->updateNote($account, (string) $data['notes']); + $this->updateNote($account, (string)$data['notes']); } // update preferences if inactive: @@ -120,8 +112,16 @@ class AccountUpdateService } /** - * @param Account $account - * @param array $data + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + + /** + * @param Account $account + * @param array $data * * @return Account */ @@ -135,19 +135,19 @@ class AccountUpdateService $account->active = $data['active']; } if (array_key_exists('iban', $data)) { - $account->iban = app('steam')->filterSpaces((string) $data['iban']); + $account->iban = app('steam')->filterSpaces((string)$data['iban']); } // set liability, but account must already be a liability. //$liabilityType = $data['liability_type'] ?? ''; if ($this->isLiability($account) && array_key_exists('liability_type', $data)) { - $type = $this->getAccountType($data['liability_type']); + $type = $this->getAccountType($data['liability_type']); $account->account_type_id = $type->id; } // set liability, alternative method used in v1 layout: if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) { - $type = AccountType::find((int) $data['account_type_id']); + $type = AccountType::find((int)$data['account_type_id']); if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) { $account->account_type_id = $type->id; @@ -165,7 +165,7 @@ class AccountUpdateService } /** - * @param Account $account + * @param Account $account * * @return bool */ @@ -177,7 +177,7 @@ class AccountUpdateService } /** - * @param string $type + * @param string $type * * @return AccountType */ @@ -187,8 +187,8 @@ class AccountUpdateService } /** - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data * * @return Account */ @@ -208,7 +208,7 @@ class AccountUpdateService return $account; } // get account type ID's because a join and an update is hard: - $oldOrder = (int) $account->order; + $oldOrder = (int)$account->order; $newOrder = $data['order']; Log::debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder)); $list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]); @@ -246,15 +246,15 @@ class AccountUpdateService foreach ($array as $type) { /** @var AccountType $type */ $type = AccountType::whereType($type)->first(); - $return[] = (int) $type->id; + $return[] = (int)$type->id; } return $return; } /** - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data */ private function updateLocation(Account $account, array $data): void { @@ -283,8 +283,8 @@ class AccountUpdateService } /** - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data * * @throws FireflyException */ @@ -308,8 +308,8 @@ class AccountUpdateService } /** - * @param Account $account - * @param array $data + * @param Account $account + * @param array $data * * @throws FireflyException */ @@ -338,7 +338,7 @@ class AccountUpdateService } /** - * @param Account $account + * @param Account $account * * @throws FireflyException */ @@ -355,12 +355,12 @@ class AccountUpdateService $array = $preference->data; Log::debug('Old array is: ', $array); Log::debug(sprintf('Must remove : %d', $account->id)); - $removeAccountId = (int) $account->id; + $removeAccountId = (int)$account->id; $new = []; foreach ($array as $value) { - if ((int) $value !== $removeAccountId) { + if ((int)$value !== $removeAccountId) { Log::debug(sprintf('Will include: %d', $value)); - $new[] = (int) $value; + $new[] = (int)$value; } } Log::debug('Final new array is', $new); diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php index eae4a4ad13..af0b98644c 100644 --- a/app/Services/Internal/Update/BillUpdateService.php +++ b/app/Services/Internal/Update/BillUpdateService.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Update; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionCurrencyFactory; use FireflyIII\Models\Bill; use FireflyIII\Models\Rule; @@ -32,6 +33,7 @@ use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups; use FireflyIII\Services\Internal\Support\BillServiceTrait; use FireflyIII\User; use Illuminate\Support\Collection; +use JsonException; use Log; /** @@ -46,12 +48,12 @@ class BillUpdateService protected User $user; /** - * @param Bill $bill - * @param array $data + * @param Bill $bill + * @param array $data * * @return Bill - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ public function update(Bill $bill, array $data): Bill { @@ -59,7 +61,7 @@ class BillUpdateService if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) { $factory = app(TransactionCurrencyFactory::class); - $currency = $factory->find((int) ($data['currency_id'] ?? null), $data['currency_code'] ?? null) ?? + $currency = $factory->find((int)($data['currency_id'] ?? null), $data['currency_code'] ?? null) ?? app('amount')->getDefaultCurrencyByUser($bill->user); // enable the currency if it isn't. @@ -81,14 +83,14 @@ class BillUpdateService ]; // update note: if (array_key_exists('notes', $data)) { - $this->updateNote($bill, (string) $data['notes']); + $this->updateNote($bill, (string)$data['notes']); } // update order. if (array_key_exists('order', $data)) { // update the order of the piggy bank: - $oldOrder = (int) $bill->order; - $newOrder = (int) ($data['order'] ?? $oldOrder); + $oldOrder = (int)$bill->order; + $newOrder = (int)($data['order'] ?? $oldOrder); if ($oldOrder !== $newOrder) { $this->updateOrder($bill, $oldOrder, $newOrder); } @@ -120,7 +122,7 @@ class BillUpdateService } if (array_key_exists('object_group_id', $data)) { // try also with ID: - $objectGroupId = (int) ($data['object_group_id'] ?? 0); + $objectGroupId = (int)($data['object_group_id'] ?? 0); if (0 !== $objectGroupId) { $objectGroup = $this->findObjectGroupById($objectGroupId); if (null !== $objectGroup) { @@ -140,27 +142,27 @@ class BillUpdateService } /** - * @param Bill $bill - * @param array $data + * @param Bill $bill + * @param array $data * * @return Bill */ private function updateBillProperties(Bill $bill, array $data): Bill { - if (array_key_exists('name', $data) && '' !== (string) $data['name']) { + if (array_key_exists('name', $data) && '' !== (string)$data['name']) { $bill->name = $data['name']; } - if (array_key_exists('amount_min', $data) && '' !== (string) $data['amount_min']) { + if (array_key_exists('amount_min', $data) && '' !== (string)$data['amount_min']) { $bill->amount_min = $data['amount_min']; } - if (array_key_exists('amount_max', $data) && '' !== (string) $data['amount_max']) { + if (array_key_exists('amount_max', $data) && '' !== (string)$data['amount_max']) { $bill->amount_max = $data['amount_max']; } - if (array_key_exists('date', $data) && '' !== (string) $data['date']) { + if (array_key_exists('date', $data) && '' !== (string)$data['date']) { $bill->date = $data['date']; } - if (array_key_exists('repeat_freq', $data) && '' !== (string) $data['repeat_freq']) { + if (array_key_exists('repeat_freq', $data) && '' !== (string)$data['repeat_freq']) { $bill->repeat_freq = $data['repeat_freq']; } if (array_key_exists('skip', $data)) { @@ -184,9 +186,9 @@ class BillUpdateService } /** - * @param Bill $bill - * @param int $oldOrder - * @param int $newOrder + * @param Bill $bill + * @param int $oldOrder + * @param int $newOrder */ private function updateOrder(Bill $bill, int $oldOrder, int $newOrder): void { @@ -207,9 +209,9 @@ class BillUpdateService } /** - * @param Bill $bill - * @param array $oldData - * @param array $newData + * @param Bill $bill + * @param array $oldData + * @param array $newData */ private function updateBillTriggers(Bill $bill, array $oldData, array $newData): void { @@ -228,7 +230,8 @@ class BillUpdateService 'name' => 'description_contains', 'amount_min' => 'amount_more', 'amount_max' => 'amount_less', - 'transaction_currency_name' => 'currency_is']; + 'transaction_currency_name' => 'currency_is', + ]; foreach ($fields as $field => $ruleTriggerKey) { if (!array_key_exists($field, $newData)) { continue; @@ -242,10 +245,10 @@ class BillUpdateService } /** - * @param Collection $rules - * @param string $key - * @param string $oldValue - * @param string $newValue + * @param Collection $rules + * @param string $key + * @param string $oldValue + * @param string $newValue */ private function updateRules(Collection $rules, string $key, string $oldValue, string $newValue): void { @@ -268,8 +271,8 @@ class BillUpdateService } /** - * @param Rule $rule - * @param string $key + * @param Rule $rule + * @param string $key * * @return RuleTrigger|null */ diff --git a/app/Services/Internal/Update/CategoryUpdateService.php b/app/Services/Internal/Update/CategoryUpdateService.php index 369e4fd7cf..e50e2c24be 100644 --- a/app/Services/Internal/Update/CategoryUpdateService.php +++ b/app/Services/Internal/Update/CategoryUpdateService.php @@ -51,7 +51,7 @@ class CategoryUpdateService } /** - * @param mixed $user + * @param mixed $user */ public function setUser($user): void { @@ -59,8 +59,8 @@ class CategoryUpdateService } /** - * @param Category $category - * @param array $data + * @param Category $category + * @param array $data * * @return Category * @throws Exception @@ -83,8 +83,8 @@ class CategoryUpdateService } /** - * @param string $oldName - * @param string $newName + * @param string $oldName + * @param string $newName */ private function updateRuleTriggers(string $oldName, string $newName): void { @@ -104,8 +104,8 @@ class CategoryUpdateService } /** - * @param string $oldName - * @param string $newName + * @param string $oldName + * @param string $newName */ private function updateRuleActions(string $oldName, string $newName): void { @@ -125,22 +125,22 @@ class CategoryUpdateService } /** - * @param string $oldName - * @param string $newName + * @param string $oldName + * @param string $newName */ private function updateRecurrences(string $oldName, string $newName): void { RecurrenceTransactionMeta::leftJoin('recurrences_transactions', 'rt_meta.rt_id', '=', 'recurrences_transactions.id') - ->leftJoin('recurrences', 'recurrences.id', '=', 'recurrences_transactions.recurrence_id') - ->where('recurrences.user_id', $this->user->id) - ->where('rt_meta.name', 'category_name') - ->where('rt_meta.value', $oldName) - ->update(['rt_meta.value' => $newName]); + ->leftJoin('recurrences', 'recurrences.id', '=', 'recurrences_transactions.recurrence_id') + ->where('recurrences.user_id', $this->user->id) + ->where('rt_meta.name', 'category_name') + ->where('rt_meta.value', $oldName) + ->update(['rt_meta.value' => $newName]); } /** - * @param Category $category - * @param array $data + * @param Category $category + * @param array $data * * @throws Exception */ diff --git a/app/Services/Internal/Update/CurrencyUpdateService.php b/app/Services/Internal/Update/CurrencyUpdateService.php index 07e678d810..bc8372a744 100644 --- a/app/Services/Internal/Update/CurrencyUpdateService.php +++ b/app/Services/Internal/Update/CurrencyUpdateService.php @@ -33,22 +33,22 @@ use FireflyIII\Models\TransactionCurrency; class CurrencyUpdateService { /** - * @param TransactionCurrency $currency - * @param array $data + * @param TransactionCurrency $currency + * @param array $data * * @return TransactionCurrency */ public function update(TransactionCurrency $currency, array $data): TransactionCurrency { - if (array_key_exists('code', $data) && '' !== (string) $data['code']) { + if (array_key_exists('code', $data) && '' !== (string)$data['code']) { $currency->code = $data['code']; } - if (array_key_exists('symbol', $data) && '' !== (string) $data['symbol']) { + if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) { $currency->symbol = $data['symbol']; } - if (array_key_exists('name', $data) && '' !== (string) $data['name']) { + if (array_key_exists('name', $data) && '' !== (string)$data['name']) { $currency->name = $data['name']; } diff --git a/app/Services/Internal/Update/GroupCloneService.php b/app/Services/Internal/Update/GroupCloneService.php index bb2fcab22d..3957164e92 100644 --- a/app/Services/Internal/Update/GroupCloneService.php +++ b/app/Services/Internal/Update/GroupCloneService.php @@ -41,7 +41,7 @@ use FireflyIII\Models\TransactionJournalMeta; class GroupCloneService { /** - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return TransactionGroup */ @@ -50,16 +50,16 @@ class GroupCloneService $newGroup = $group->replicate(); $newGroup->save(); foreach ($group->transactionJournals as $journal) { - $this->cloneJournal($journal, $newGroup, (int) $group->id); + $this->cloneJournal($journal, $newGroup, (int)$group->id); } return $newGroup; } /** - * @param TransactionJournal $journal - * @param TransactionGroup $newGroup - * @param int $originalGroup + * @param TransactionJournal $journal + * @param TransactionGroup $newGroup + * @param int $originalGroup */ private function cloneJournal(TransactionJournal $journal, TransactionGroup $newGroup, int $originalGroup): void { @@ -107,17 +107,17 @@ class GroupCloneService // add relation. // TODO clone ALL linked piggy banks /** @var PiggyBankEvent $event */ - $event = $journal->piggyBankEvents()->first(); + $event = $journal->piggyBankEvents()->first(); if (null !== $event) { $piggyBank = $event->piggyBank; - $factory = app(PiggyBankEventFactory::class); + $factory = app(PiggyBankEventFactory::class); $factory->create($newJournal, $piggyBank); } } /** - * @param Transaction $transaction - * @param TransactionJournal $newJournal + * @param Transaction $transaction + * @param TransactionJournal $newJournal */ private function cloneTransaction(Transaction $transaction, TransactionJournal $newJournal): void { @@ -128,9 +128,9 @@ class GroupCloneService } /** - * @param Note $note - * @param TransactionJournal $newJournal - * @param int $oldGroupId + * @param Note $note + * @param TransactionJournal $newJournal + * @param int $oldGroupId */ private function cloneNote(Note $note, TransactionJournal $newJournal, int $oldGroupId): void { @@ -144,8 +144,8 @@ class GroupCloneService } /** - * @param TransactionJournalMeta $meta - * @param TransactionJournal $newJournal + * @param TransactionJournalMeta $meta + * @param TransactionJournal $newJournal */ private function cloneMeta(TransactionJournalMeta $meta, TransactionJournal $newJournal): void { diff --git a/app/Services/Internal/Update/GroupUpdateService.php b/app/Services/Internal/Update/GroupUpdateService.php index 2817cf8ab4..7eeb574321 100644 --- a/app/Services/Internal/Update/GroupUpdateService.php +++ b/app/Services/Internal/Update/GroupUpdateService.php @@ -29,6 +29,7 @@ use FireflyIII\Factory\TransactionJournalFactory; use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Services\Internal\Destroy\JournalDestroyService; +use JsonException; use Log; /** @@ -39,8 +40,8 @@ class GroupUpdateService /** * Update a transaction group. * - * @param TransactionGroup $transactionGroup - * @param array $data + * @param TransactionGroup $transactionGroup + * @param array $data * * @return TransactionGroup * @throws DuplicateTransactionException @@ -96,7 +97,7 @@ class GroupUpdateService /** @var string $deletedId */ foreach ($result as $deletedId) { /** @var TransactionJournal $journal */ - $journal = $transactionGroup->transactionJournals()->find((int) $deletedId); + $journal = $transactionGroup->transactionJournals()->find((int)$deletedId); /** @var JournalDestroyService $service */ $service = app(JournalDestroyService::class); $service->destroy($journal); @@ -112,9 +113,9 @@ class GroupUpdateService /** * Update single journal. * - * @param TransactionGroup $transactionGroup - * @param TransactionJournal $journal - * @param array $data + * @param TransactionGroup $transactionGroup + * @param TransactionJournal $journal + * @param array $data */ private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void { @@ -134,8 +135,8 @@ class GroupUpdateService } /** - * @param TransactionGroup $transactionGroup - * @param array $transactions + * @param TransactionGroup $transactionGroup + * @param array $transactions * * @return array * @throws DuplicateTransactionException @@ -147,12 +148,12 @@ class GroupUpdateService // updated or created transaction journals: $updated = []; /** - * @var int $index + * @var int $index * @var array $transaction */ foreach ($transactions as $index => $transaction) { Log::debug(sprintf('Now at #%d of %d', ($index + 1), count($transactions)), $transaction); - $journalId = (int) ($transaction['transaction_journal_id'] ?? 0); + $journalId = (int)($transaction['transaction_journal_id'] ?? 0); /** @var TransactionJournal|null $journal */ $journal = $transactionGroup->transactionJournals()->find($journalId); if (null === $journal) { @@ -190,14 +191,14 @@ class GroupUpdateService } /** - * @param TransactionGroup $transactionGroup - * @param array $data + * @param TransactionGroup $transactionGroup + * @param array $data * * @return TransactionJournal|null * * @throws DuplicateTransactionException * @throws FireflyException - * @throws \JsonException + * @throws JsonException */ private function createTransactionJournal(TransactionGroup $transactionGroup, array $data): ?TransactionJournal { diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.php index 27c09eb44c..b670ebdbdd 100644 --- a/app/Services/Internal/Update/JournalUpdateService.php +++ b/app/Services/Internal/Update/JournalUpdateService.php @@ -82,14 +82,26 @@ class JournalUpdateService $this->tagFactory = app(TagFactory::class); $this->accountRepository = app(AccountRepositoryInterface::class); $this->currencyRepository = app(CurrencyRepositoryInterface::class); - $this->metaString = ['sepa_cc', 'sepa_ct_op', 'sepa_ct_id', 'sepa_db', 'sepa_country', 'sepa_ep', 'sepa_ci', 'sepa_batch_id', - 'recurrence_id', - 'internal_reference', 'bunq_payment_id', 'external_id', 'external_url']; + $this->metaString = [ + 'sepa_cc', + 'sepa_ct_op', + 'sepa_ct_id', + 'sepa_db', + 'sepa_country', + 'sepa_ep', + 'sepa_ci', + 'sepa_batch_id', + 'recurrence_id', + 'internal_reference', + 'bunq_payment_id', + 'external_id', + 'external_url', + ]; $this->metaDate = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date',]; } /** - * @param array $data + * @param array $data */ public function setData(array $data): void { @@ -97,7 +109,7 @@ class JournalUpdateService } /** - * @param TransactionGroup $transactionGroup + * @param TransactionGroup $transactionGroup */ public function setTransactionGroup(TransactionGroup $transactionGroup): void { @@ -114,7 +126,7 @@ class JournalUpdateService } /** - * @param TransactionJournal $transactionJournal + * @param TransactionJournal $transactionJournal */ public function setTransactionJournal(TransactionJournal $transactionJournal): void { @@ -226,7 +238,7 @@ class JournalUpdateService } /** - * @param array $fields + * @param array $fields * * @return bool */ @@ -360,7 +372,7 @@ class JournalUpdateService } $sourceInfo = [ - 'id' => (int) ($this->data['source_id'] ?? null), + 'id' => (int)($this->data['source_id'] ?? null), 'name' => $this->data['source_name'] ?? null, 'iban' => $this->data['source_iban'] ?? null, 'number' => $this->data['source_number'] ?? null, @@ -425,7 +437,7 @@ class JournalUpdateService } $destInfo = [ - 'id' => (int) ($this->data['destination_id'] ?? null), + 'id' => (int)($this->data['destination_id'] ?? null), 'name' => $this->data['destination_name'] ?? null, 'iban' => $this->data['destination_iban'] ?? null, 'number' => $this->data['destination_number'] ?? null, @@ -490,8 +502,8 @@ class JournalUpdateService ) && TransactionType::WITHDRAWAL === $type ) { - $billId = (int) ($this->data['bill_id'] ?? 0); - $billName = (string) ($this->data['bill_name'] ?? ''); + $billId = (int)($this->data['bill_id'] ?? 0); + $billName = (string)($this->data['bill_name'] ?? ''); $bill = $this->billRepository->findBill($billId, $billName); $this->transactionJournal->bill_id = $bill?->id; Log::debug('Updated bill ID'); @@ -501,11 +513,11 @@ class JournalUpdateService /** * Update journal generic field. Cannot be set to NULL. * - * @param string $fieldName + * @param string $fieldName */ private function updateField(string $fieldName): void { - if (array_key_exists($fieldName, $this->data) && '' !== (string) $this->data[$fieldName]) { + if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) { $value = $this->data[$fieldName]; if ('date' === $fieldName) { @@ -582,7 +594,7 @@ class JournalUpdateService { // update notes. if ($this->hasFields(['notes'])) { - $notes = '' === (string) $this->data['notes'] ? null : $this->data['notes']; + $notes = '' === (string)$this->data['notes'] ? null : $this->data['notes']; $this->storeNotes($this->transactionJournal, $notes); } } @@ -639,7 +651,7 @@ class JournalUpdateService foreach ($this->metaDate as $field) { if ($this->hasFields([$field])) { try { - $value = '' === (string) $this->data[$field] ? null : new Carbon($this->data[$field]); + $value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]); } catch (Exception $e) { Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage())); diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index 60327bc94f..329eff9886 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -52,8 +52,8 @@ class RecurrenceUpdateService * * TODO if the user updates the type, the accounts must be validated again. * - * @param Recurrence $recurrence - * @param array $data + * @param Recurrence $recurrence + * @param array $data * * @return Recurrence * @throws FireflyException @@ -79,7 +79,7 @@ class RecurrenceUpdateService $recurrence->repetitions = 0; } if (array_key_exists('nr_of_repetitions', $info)) { - if (0 !== (int) $info['nr_of_repetitions']) { + if (0 !== (int)$info['nr_of_repetitions']) { $recurrence->repeat_until = null; } $recurrence->repetitions = $info['nr_of_repetitions']; @@ -115,8 +115,8 @@ class RecurrenceUpdateService } /** - * @param Recurrence $recurrence - * @param string $text + * @param Recurrence $recurrence + * @param string $text */ private function setNoteText(Recurrence $recurrence, string $text): void { @@ -142,8 +142,8 @@ class RecurrenceUpdateService /** * - * @param Recurrence $recurrence - * @param array $repetitions + * @param Recurrence $recurrence + * @param array $repetitions * * @throws FireflyException */ @@ -187,8 +187,8 @@ class RecurrenceUpdateService } /** - * @param Recurrence $recurrence - * @param array $data + * @param Recurrence $recurrence + * @param array $data * * @return RecurrenceRepetition|null */ @@ -201,11 +201,12 @@ class RecurrenceUpdateService return $recurrence->recurrenceRepetitions()->first(); } // find it: - $fields = ['id' => 'id', - 'type' => 'repetition_type', - 'moment' => 'repetition_moment', - 'skip' => 'repetition_skip', - 'weekend' => 'weekend', + $fields = [ + 'id' => 'id', + 'type' => 'repetition_type', + 'moment' => 'repetition_moment', + 'skip' => 'repetition_skip', + 'weekend' => 'weekend', ]; $query = $recurrence->recurrenceRepetitions(); foreach ($fields as $field => $column) { @@ -220,8 +221,8 @@ class RecurrenceUpdateService /** * TODO this method is very complex. * - * @param Recurrence $recurrence - * @param array $transactions + * @param Recurrence $recurrence + * @param array $transactions * * @throws FireflyException */ @@ -258,7 +259,7 @@ class RecurrenceUpdateService unset($current['currency_id'], $current['currency_code']); } if (null !== $currency) { - $current['currency_id'] = (int) $currency->id; + $current['currency_id'] = (int)$currency->id; } if (array_key_exists('foreign_currency_id', $current) || array_key_exists('foreign_currency_code', $current)) { $foreignCurrency = $currencyFactory->find($current['foreign_currency_id'] ?? null, $currency['foreign_currency_code'] ?? null); @@ -267,7 +268,7 @@ class RecurrenceUpdateService unset($current['foreign_currency_id'], $currency['foreign_currency_code']); } if (null !== $foreignCurrency) { - $current['foreign_currency_id'] = (int) $foreignCurrency->id; + $current['foreign_currency_id'] = (int)$foreignCurrency->id; } // update fields @@ -288,35 +289,35 @@ class RecurrenceUpdateService } // update meta data if (array_key_exists('budget_id', $current)) { - $this->setBudget($match, (int) $current['budget_id']); + $this->setBudget($match, (int)$current['budget_id']); } if (array_key_exists('bill_id', $current)) { - $this->setBill($match, (int) $current['bill_id']); + $this->setBill($match, (int)$current['bill_id']); } // reset category if name is set but empty: // can be removed when v1 is retired. - if (array_key_exists('category_name', $current) && '' === (string) $current['category_name']) { + if (array_key_exists('category_name', $current) && '' === (string)$current['category_name']) { $current['category_name'] = null; $current['category_id'] = 0; } if (array_key_exists('category_id', $current)) { - $this->setCategory($match, (int) $current['category_id']); + $this->setCategory($match, (int)$current['category_id']); } if (array_key_exists('tags', $current) && is_array($current['tags'])) { $this->updateTags($match, $current['tags']); } if (array_key_exists('piggy_bank_id', $current)) { - $this->updatePiggyBank($match, (int) $current['piggy_bank_id']); + $this->updatePiggyBank($match, (int)$current['piggy_bank_id']); } } } } /** - * @param Recurrence $recurrence - * @param array $data + * @param Recurrence $recurrence + * @param array $data * * @return RecurrenceTransaction|null */ diff --git a/app/Services/Password/PwndVerifierV2.php b/app/Services/Password/PwndVerifierV2.php index 7e40580e07..39bee2ca32 100644 --- a/app/Services/Password/PwndVerifierV2.php +++ b/app/Services/Password/PwndVerifierV2.php @@ -1,4 +1,5 @@ sprintf('Firefly III v%s', config('firefly.version')), 'Add-Padding' => 'true', ], - 'timeout' => 3.1415]; + 'timeout' => 3.1415, + ]; Log::debug(sprintf('hash prefix is %s', $prefix)); Log::debug(sprintf('rest is %s', $rest)); diff --git a/app/Services/Password/Verifier.php b/app/Services/Password/Verifier.php index 0883aeaf64..ac688d7d6d 100644 --- a/app/Services/Password/Verifier.php +++ b/app/Services/Password/Verifier.php @@ -1,4 +1,5 @@ server($header) ?? apache_request_headers()[$header] ?? null); + $emailAddress = (string)(request()->server($header) ?? apache_request_headers()[$header] ?? null); $preference = app('preferences')->getForUser($retrievedUser, 'remote_guard_alt_email'); if ('' !== $emailAddress && null === $preference && $emailAddress !== $userID) { diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.php index 2034ba5f2d..4d2c2b9e43 100644 --- a/app/Support/Binder/AccountList.php +++ b/app/Support/Binder/AccountList.php @@ -1,4 +1,5 @@ all(); // check for static token - if ($value === config('firefly.static_cron_token') && 32 === strlen((string) config('firefly.static_cron_token'))) { + if ($value === config('firefly.static_cron_token') && 32 === strlen((string)config('firefly.static_cron_token'))) { return $value; } diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php index f01677ada5..e37c23b8a0 100644 --- a/app/Support/Binder/CategoryList.php +++ b/app/Support/Binder/CategoryList.php @@ -1,4 +1,5 @@ tag), $list, true)) { return true; } - if (in_array((string) $tag->id, $list, true)) { + if (in_array((string)$tag->id, $list, true)) { return true; } diff --git a/app/Support/Binder/TagOrId.php b/app/Support/Binder/TagOrId.php index 72ab7fb31a..12ecd26c0f 100644 --- a/app/Support/Binder/TagOrId.php +++ b/app/Support/Binder/TagOrId.php @@ -1,4 +1,5 @@ findByTag($value); if (null === $result) { - $result = $repository->find((int) $value); + $result = $repository->find((int)$value); } if (null !== $result) { return $result; diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 865a786bb2..df7adf5809 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -1,4 +1,5 @@ hash = substr(hash('sha256', $content), 0, 16); } /** - * @param mixed $data + * @param mixed $data */ public function store($data): void { diff --git a/app/Support/Chart/Budget/FrontpageChartGenerator.php b/app/Support/Chart/Budget/FrontpageChartGenerator.php index 0163a4b30d..633b339ddf 100644 --- a/app/Support/Chart/Budget/FrontpageChartGenerator.php +++ b/app/Support/Chart/Budget/FrontpageChartGenerator.php @@ -1,4 +1,5 @@ budgetRepository->getActiveBudgets(); $data = [ - ['label' => (string) trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'], - ['label' => (string) trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'], - ['label' => (string) trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'], + ['label' => (string)trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'], + ['label' => (string)trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'], + ['label' => (string)trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'], ]; // loop al budgets: @@ -83,8 +85,8 @@ class FrontpageChartGenerator * When no limits are present, the time range is used to collect information on money spent. * If limits are present, each limit is processed individually. * - * @param array $data - * @param Budget $budget + * @param array $data + * @param Budget $budget * * @return array */ @@ -105,8 +107,8 @@ class FrontpageChartGenerator * When no limits are present, the expenses of the whole period are collected and grouped. * This is grouped per currency. Because there is no limit set, "left to spend" and "overspent" are empty. * - * @param array $data - * @param Budget $budget + * @param array $data + * @param Budget $budget * * @return array */ @@ -127,9 +129,9 @@ class FrontpageChartGenerator /** * If a budget has budget limit, each limit is processed individually. * - * @param array $data - * @param Budget $budget - * @param Collection $limits + * @param array $data + * @param Budget $budget + * @param Collection $limits * * @return array */ @@ -146,9 +148,9 @@ class FrontpageChartGenerator /** * For each limit, the expenses from the time range of the limit are collected. Each row from the result is processed individually. * - * @param array $data - * @param Budget $budget - * @param BudgetLimit $limit + * @param array $data + * @param Budget $budget + * @param BudgetLimit $limit * * @return array */ @@ -158,7 +160,7 @@ class FrontpageChartGenerator /** @var array $entry */ foreach ($spent as $entry) { // only spent the entry where the entry's currency matches the budget limit's currency - if ($entry['currency_id'] === (int) $limit->transaction_currency_id) { + if ($entry['currency_id'] === (int)$limit->transaction_currency_id) { $data = $this->processRow($data, $budget, $limit, $entry); } } @@ -172,10 +174,10 @@ class FrontpageChartGenerator * Each one is added to the $data array. If the limit's date range is different from the global $start and $end dates, * for example when a limit only partially falls into this month, the title is expanded to clarify. * - * @param array $data - * @param Budget $budget - * @param BudgetLimit $limit - * @param array $entry + * @param array $data + * @param Budget $budget + * @param BudgetLimit $limit + * @param array $entry * * @return array */ @@ -201,7 +203,7 @@ class FrontpageChartGenerator } /** - * @param Carbon $end + * @param Carbon $end */ public function setEnd(Carbon $end): void { @@ -209,7 +211,7 @@ class FrontpageChartGenerator } /** - * @param Carbon $start + * @param Carbon $start */ public function setStart(Carbon $start): void { @@ -219,8 +221,8 @@ class FrontpageChartGenerator /** * A basic setter for the user. Also updates the repositories with the right user. * - * @param User $user - * @throws \FireflyIII\Exceptions\FireflyException + * @param User $user + * @throws FireflyException */ public function setUser(User $user): void { @@ -230,6 +232,6 @@ class FrontpageChartGenerator $this->opsRepository->setUser($user); $locale = app('steam')->getLocale(); - $this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale); + $this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale); } } diff --git a/app/Support/Chart/Category/FrontpageChartGenerator.php b/app/Support/Chart/Category/FrontpageChartGenerator.php index b251399455..ab1a9985f9 100644 --- a/app/Support/Chart/Category/FrontpageChartGenerator.php +++ b/app/Support/Chart/Category/FrontpageChartGenerator.php @@ -52,8 +52,8 @@ class FrontpageChartGenerator /** * FrontpageChartGenerator constructor. * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end */ public function __construct(Carbon $start, Carbon $end) { @@ -99,8 +99,8 @@ class FrontpageChartGenerator } /** - * @param Category $category - * @param Collection $accounts + * @param Category $category + * @param Collection $accounts * * @return array */ @@ -113,8 +113,8 @@ class FrontpageChartGenerator $tempData[] = [ 'name' => $category->name, 'sum' => $currency['sum'], - 'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places']), - 'currency_id' => (int) $currency['currency_id'], + 'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places']), + 'currency_id' => (int)$currency['currency_id'], ]; } @@ -122,23 +122,23 @@ class FrontpageChartGenerator } /** - * @param array $currency + * @param array $currency */ private function addCurrency(array $currency): void { - $currencyId = (int) $currency['currency_id']; + $currencyId = (int)$currency['currency_id']; $this->currencies[$currencyId] = $this->currencies[$currencyId] ?? [ - 'currency_id' => $currencyId, - 'currency_name' => $currency['currency_name'], - 'currency_symbol' => $currency['currency_symbol'], - 'currency_code' => $currency['currency_code'], - 'currency_decimal_places' => $currency['currency_decimal_places'], - ]; + 'currency_id' => $currencyId, + 'currency_name' => $currency['currency_name'], + 'currency_symbol' => $currency['currency_symbol'], + 'currency_code' => $currency['currency_code'], + 'currency_decimal_places' => $currency['currency_decimal_places'], + ]; } /** - * @param Collection $accounts + * @param Collection $accounts * * @return array */ @@ -151,8 +151,8 @@ class FrontpageChartGenerator $tempData[] = [ 'name' => trans('firefly.no_category'), 'sum' => $currency['sum'], - 'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float - 'currency_id' => (int) $currency['currency_id'], + 'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float + 'currency_id' => (int)$currency['currency_id'], ]; } @@ -160,7 +160,7 @@ class FrontpageChartGenerator } /** - * @param array $data + * @param array $data * * @return array */ @@ -174,7 +174,7 @@ class FrontpageChartGenerator foreach ($this->currencies as $currencyId => $currency) { $key = sprintf('spent-%d', $currencyId); $return[$key] = [ - 'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currency['currency_name']), + 'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currency['currency_name']), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], 'entries' => $names, @@ -185,8 +185,8 @@ class FrontpageChartGenerator } /** - * @param array $currencyData - * @param array $monetaryData + * @param array $currencyData + * @param array $monetaryData * * @return array */ diff --git a/app/Support/Chart/Category/WholePeriodChartGenerator.php b/app/Support/Chart/Category/WholePeriodChartGenerator.php index b4bac1df0a..4b4e500b52 100644 --- a/app/Support/Chart/Category/WholePeriodChartGenerator.php +++ b/app/Support/Chart/Category/WholePeriodChartGenerator.php @@ -36,9 +36,9 @@ use Illuminate\Support\Collection; class WholePeriodChartGenerator { /** - * @param Category $category - * @param Carbon $start - * @param Carbon $end + * @param Category $category + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -77,14 +77,14 @@ class WholePeriodChartGenerator $code = $currency['currency_code']; $name = $currency['currency_name']; $chartData[sprintf('spent-in-%s', $code)] = [ - 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $name]), + 'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $name]), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red ]; $chartData[sprintf('earned-in-%s', $code)] = [ - 'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $name]), + 'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $name]), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green @@ -117,8 +117,8 @@ class WholePeriodChartGenerator /** * TODO this method is duplicated * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -143,7 +143,7 @@ class WholePeriodChartGenerator * Loop array of spent/earned info, and extract which currencies are present. * Key is the currency ID. * - * @param array $array + * @param array $array * * @return array */ @@ -153,12 +153,12 @@ class WholePeriodChartGenerator foreach ($array as $block) { foreach ($block as $currencyId => $currencyRow) { $return[$currencyId] = $return[$currencyId] ?? [ - 'currency_id' => $currencyId, - 'currency_name' => $currencyRow['currency_name'], - 'currency_symbol' => $currencyRow['currency_symbol'], - 'currency_code' => $currencyRow['currency_code'], - 'currency_decimal_places' => $currencyRow['currency_decimal_places'], - ]; + 'currency_id' => $currencyId, + 'currency_name' => $currencyRow['currency_name'], + 'currency_symbol' => $currencyRow['currency_symbol'], + 'currency_code' => $currencyRow['currency_code'], + 'currency_decimal_places' => $currencyRow['currency_decimal_places'], + ]; } } diff --git a/app/Support/ChartColour.php b/app/Support/ChartColour.php index 2969a496d3..82dbb2d238 100644 --- a/app/Support/ChartColour.php +++ b/app/Support/ChartColour.php @@ -1,4 +1,5 @@ get('last_ab_job', 0); - $lastTime = (int) $config->data; + $lastTime = (int)$config->data; $diff = time() - $lastTime; $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); if (0 === $lastTime) { @@ -88,7 +88,7 @@ class AutoBudgetCronjob extends AbstractCronjob $this->jobSucceeded = true; $this->message = 'Auto-budget cron job fired successfully.'; - app('fireflyconfig')->set('last_ab_job', (int) $this->date->format('U')); + app('fireflyconfig')->set('last_ab_job', (int)$this->date->format('U')); Log::info('Done with auto budget cron job task.'); } } diff --git a/app/Support/Cronjobs/BillWarningCronjob.php b/app/Support/Cronjobs/BillWarningCronjob.php index 79ce30f5af..70c84c0bcf 100644 --- a/app/Support/Cronjobs/BillWarningCronjob.php +++ b/app/Support/Cronjobs/BillWarningCronjob.php @@ -28,6 +28,8 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Jobs\WarnAboutBills; use FireflyIII\Models\Configuration; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class BillWarningCronjob @@ -36,15 +38,15 @@ class BillWarningCronjob extends AbstractCronjob { /** * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function fire(): void { Log::debug(sprintf('Now in %s', __METHOD__)); /** @var Configuration $config */ $config = app('fireflyconfig')->get('last_bw_job', 0); - $lastTime = (int) $config->data; + $lastTime = (int)$config->data; $diff = time() - $lastTime; $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); @@ -97,8 +99,8 @@ class BillWarningCronjob extends AbstractCronjob $this->jobSucceeded = true; $this->message = 'Bill warning cron job fired successfully.'; - app('fireflyconfig')->set('last_bw_job', (int) $this->date->format('U')); - Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int) $this->date->format('U'))); + app('fireflyconfig')->set('last_bw_job', (int)$this->date->format('U')); + Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int)$this->date->format('U'))); Log::info('Done with bill warning cron job task.'); } } diff --git a/app/Support/Cronjobs/ExchangeRatesCronjob.php b/app/Support/Cronjobs/ExchangeRatesCronjob.php index 379d2483de..91a946b806 100644 --- a/app/Support/Cronjobs/ExchangeRatesCronjob.php +++ b/app/Support/Cronjobs/ExchangeRatesCronjob.php @@ -41,7 +41,7 @@ class ExchangeRatesCronjob extends AbstractCronjob { /** @var Configuration $config */ $config = app('fireflyconfig')->get('last_cer_job', 0); - $lastTime = (int) $config->data; + $lastTime = (int)$config->data; $diff = time() - $lastTime; $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); if (0 === $lastTime) { @@ -88,7 +88,7 @@ class ExchangeRatesCronjob extends AbstractCronjob $this->jobSucceeded = true; $this->message = 'Exchange rates cron job fired successfully.'; - app('fireflyconfig')->set('last_cer_job', (int) $this->date->format('U')); + app('fireflyconfig')->set('last_cer_job', (int)$this->date->format('U')); Log::info('Done with exchange rates job task.'); } } diff --git a/app/Support/Cronjobs/RecurringCronjob.php b/app/Support/Cronjobs/RecurringCronjob.php index b71bdf4f3d..cba3e594cb 100644 --- a/app/Support/Cronjobs/RecurringCronjob.php +++ b/app/Support/Cronjobs/RecurringCronjob.php @@ -28,6 +28,8 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Jobs\CreateRecurringTransactions; use FireflyIII\Models\Configuration; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class RecurringCronjob @@ -36,15 +38,15 @@ class RecurringCronjob extends AbstractCronjob { /** * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function fire(): void { Log::debug(sprintf('Now in %s', __METHOD__)); /** @var Configuration $config */ $config = app('fireflyconfig')->get('last_rt_job', 0); - $lastTime = (int) $config->data; + $lastTime = (int)$config->data; $diff = time() - $lastTime; $diffForHumans = Carbon::now()->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); @@ -97,8 +99,8 @@ class RecurringCronjob extends AbstractCronjob $this->jobSucceeded = true; $this->message = 'Recurring transactions cron job fired successfully.'; - app('fireflyconfig')->set('last_rt_job', (int) $this->date->format('U')); - Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int) $this->date->format('U'))); + app('fireflyconfig')->set('last_rt_job', (int)$this->date->format('U')); + Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int)$this->date->format('U'))); Log::info('Done with recurring cron job task.'); } } diff --git a/app/Support/Domain.php b/app/Support/Domain.php index ced5cd7ae7..6422919533 100644 --- a/app/Support/Domain.php +++ b/app/Support/Domain.php @@ -1,4 +1,5 @@ id; + $entryId = (int)$entry->id; $current = $entry->toArray(); $title = null; foreach ($fields as $field) { @@ -236,9 +237,9 @@ class ExpandedForm } /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -268,9 +269,9 @@ class ExpandedForm } /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -294,8 +295,8 @@ class ExpandedForm } /** - * @param null $value - * @param array|null $options + * @param null $value + * @param array|null $options * * @return string */ @@ -324,8 +325,8 @@ class ExpandedForm } /** - * @param string $type - * @param string $name + * @param string $type + * @param string $name * * @return string * @@ -344,8 +345,8 @@ class ExpandedForm } /** - * @param string $name - * @param array|null $options + * @param string $name + * @param array|null $options * * @return string */ @@ -368,9 +369,9 @@ class ExpandedForm /** * Function to render a percentage. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -394,9 +395,9 @@ class ExpandedForm } /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -417,9 +418,9 @@ class ExpandedForm } /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -441,9 +442,9 @@ class ExpandedForm } /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ diff --git a/app/Support/Export/ExportDataGenerator.php b/app/Support/Export/ExportDataGenerator.php index 669ba0e016..23ca937c53 100644 --- a/app/Support/Export/ExportDataGenerator.php +++ b/app/Support/Export/ExportDataGenerator.php @@ -56,6 +56,8 @@ use Illuminate\Support\Collection; use League\Csv\CannotInsertRecord; use League\Csv\Exception; use League\Csv\Writer; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class ExportDataGenerator @@ -141,8 +143,25 @@ class ExportDataGenerator */ private function exportAccounts(): string { - $header = ['user_id', 'account_id', 'created_at', 'updated_at', 'type', 'name', 'virtual_balance', 'iban', 'number', 'active', 'currency_code', 'role', - 'cc_type', 'cc_payment_date', 'in_net_worth', 'interest', 'interest_period',]; + $header = [ + 'user_id', + 'account_id', + 'created_at', + 'updated_at', + 'type', + 'name', + 'virtual_balance', + 'iban', + 'number', + 'active', + 'currency_code', + 'role', + 'cc_type', + 'cc_payment_date', + 'in_net_worth', + 'interest', + 'interest_period', + ]; /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $repository->setUser($this->user); @@ -194,6 +213,14 @@ class ExportDataGenerator return $string; } + /** + * @param User $user + */ + public function setUser(User $user): void + { + $this->user = $user; + } + /** * @return string * @throws FireflyException @@ -204,8 +231,20 @@ class ExportDataGenerator $repository = app(BillRepositoryInterface::class); $repository->setUser($this->user); $bills = $repository->getBills(); - $header = ['user_id', 'bill_id', 'created_at', 'updated_at', 'currency_code', 'name', 'amount_min', 'amount_max', 'date', 'repeat_freq', 'skip', - 'active',]; + $header = [ + 'user_id', + 'bill_id', + 'created_at', + 'updated_at', + 'currency_code', + 'name', + 'amount_min', + 'amount_max', + 'date', + 'repeat_freq', + 'skip', + 'active', + ]; $records = []; /** @var Bill $bill */ @@ -374,9 +413,22 @@ class ExportDataGenerator $accountRepos = app(AccountRepositoryInterface::class); $accountRepos->setUser($this->user); - $header = ['user_id', 'piggy_bank_id', 'created_at', 'updated_at', 'account_name', 'account_type', 'name', - 'currency_code', 'target_amount', 'current_amount', 'start_date', 'target_date', 'order', - 'active']; + $header = [ + 'user_id', + 'piggy_bank_id', + 'created_at', + 'updated_at', + 'account_name', + 'account_type', + 'name', + 'currency_code', + 'target_amount', + 'current_amount', + 'start_date', + 'target_date', + 'order', + 'active', + ]; $records = []; $piggies = $piggyRepos->getPiggyBanks(); @@ -435,14 +487,39 @@ class ExportDataGenerator $recurringRepos->setUser($this->user); $header = [ // recurrence: - 'user_id', 'recurrence_id', 'row_contains', 'created_at', 'updated_at', 'type', 'title', 'description', 'first_date', 'repeat_until', - 'latest_date', 'repetitions', 'apply_rules', 'active', + 'user_id', + 'recurrence_id', + 'row_contains', + 'created_at', + 'updated_at', + 'type', + 'title', + 'description', + 'first_date', + 'repeat_until', + 'latest_date', + 'repetitions', + 'apply_rules', + 'active', // repetition info: - 'type', 'moment', 'skip', 'weekend', + 'type', + 'moment', + 'skip', + 'weekend', // transactions + meta: - 'currency_code', 'foreign_currency_code', 'source_name', 'source_type', 'destination_name', 'destination_type', 'amount', 'foreign_amount', - 'category', 'budget', 'piggy_bank', 'tags', + 'currency_code', + 'foreign_currency_code', + 'source_name', + 'source_type', + 'destination_name', + 'destination_type', + 'amount', + 'foreign_amount', + 'category', + 'budget', + 'piggy_bank', + 'tags', ]; $records = []; $recurrences = $recurringRepos->getAll(); @@ -471,10 +548,25 @@ class ExportDataGenerator $records[] = [ // recurrence $this->user->id, - $recurrence->id, 'repetition', null, null, null, null, null, null, null, null, null, null, null, + $recurrence->id, + 'repetition', + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, // repetition: - $repetition->repetition_type, $repetition->repetition_moment, $repetition->repetition_skip, $repetition->weekend, + $repetition->repetition_type, + $repetition->repetition_moment, + $repetition->repetition_skip, + $repetition->weekend, ]; } /** @var RecurrenceTransaction $transaction */ @@ -487,16 +579,39 @@ class ExportDataGenerator $records[] = [ // recurrence $this->user->id, - $recurrence->id, 'transaction', null, null, null, null, null, null, null, null, null, null, null, + $recurrence->id, + 'transaction', + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, // repetition: - null, null, null, null, + null, + null, + null, + null, // transaction: - $transaction->transactionCurrency->code, $transaction->foreignCurrency?->code, - $transaction->sourceAccount->name, $transaction->sourceAccount->accountType->type, $transaction->destinationAccount->name, - $transaction->destinationAccount->accountType->type, $transaction->amount, $transaction->foreign_amount, - $categoryName, $budgetId, $piggyBankId, implode(',', $tags), + $transaction->transactionCurrency->code, + $transaction->foreignCurrency?->code, + $transaction->sourceAccount->name, + $transaction->sourceAccount->accountType->type, + $transaction->destinationAccount->name, + $transaction->destinationAccount->accountType->type, + $transaction->amount, + $transaction->foreign_amount, + $categoryName, + $budgetId, + $piggyBankId, + implode(',', $tags), ]; } } @@ -528,9 +643,31 @@ class ExportDataGenerator */ private function exportRules(): string { - $header = ['user_id', 'rule_id', 'row_contains', 'created_at', 'updated_at', 'group_id', 'group_name', 'title', 'description', 'order', 'active', - 'stop_processing', 'strict', 'trigger_type', 'trigger_value', 'trigger_order', 'trigger_active', 'trigger_stop_processing', 'action_type', - 'action_value', 'action_order', 'action_active', 'action_stop_processing',]; + $header = [ + 'user_id', + 'rule_id', + 'row_contains', + 'created_at', + 'updated_at', + 'group_id', + 'group_name', + 'title', + 'description', + 'order', + 'active', + 'stop_processing', + 'strict', + 'trigger_type', + 'trigger_value', + 'trigger_order', + 'trigger_active', + 'trigger_stop_processing', + 'action_type', + 'action_value', + 'action_order', + 'action_active', + 'action_stop_processing', + ]; $ruleRepos = app(RuleRepositoryInterface::class); $ruleRepos->setUser($this->user); $rules = $ruleRepos->getAll(); @@ -538,31 +675,70 @@ class ExportDataGenerator /** @var Rule $rule */ foreach ($rules as $rule) { $records[] = [ - $this->user->id, $rule->id, 'rule', - $rule->created_at->toAtomString(), $rule->updated_at->toAtomString(), - $rule->ruleGroup->id, $rule->ruleGroup->title, - $rule->title, $rule->description, $rule->order, $rule->active, $rule->stop_processing, $rule->strict, + $this->user->id, + $rule->id, + 'rule', + $rule->created_at->toAtomString(), + $rule->updated_at->toAtomString(), + $rule->ruleGroup->id, + $rule->ruleGroup->title, + $rule->title, + $rule->description, + $rule->order, + $rule->active, + $rule->stop_processing, + $rule->strict, ]; /** @var RuleTrigger $trigger */ foreach ($rule->ruleTriggers as $trigger) { $records[] = [ - $this->user->id, $rule->id, 'trigger', - null, null, - null, null, - null, null, null, null, null, null, - $trigger->trigger_type, $trigger->trigger_value, $trigger->order, $trigger->active, $trigger->stop_processing, + $this->user->id, + $rule->id, + 'trigger', + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + $trigger->trigger_type, + $trigger->trigger_value, + $trigger->order, + $trigger->active, + $trigger->stop_processing, ]; } /** @var RuleAction $action */ foreach ($rule->ruleActions as $action) { $records[] = [ - $this->user->id, $rule->id, 'action', - null, null, - null, null, - null, null, null, null, null, null, - null, null, null, null, null, - $action->action_type, $action->action_value, $action->order, $action->active, $action->stop_processing, + $this->user->id, + $rule->id, + 'action', + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + $action->action_type, + $action->action_value, + $action->order, + $action->active, + $action->stop_processing, ]; } } @@ -592,8 +768,8 @@ class ExportDataGenerator /** * @return string * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ private function exportTags(): string { @@ -648,10 +824,33 @@ class ExportDataGenerator private function exportTransactions(): string { // TODO better place for keys? - $header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'amount', 'foreign_amount', 'currency_code', - 'foreign_currency_code', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', - 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes', - // all optional meta fields: + $header = [ + 'user_id', + 'group_id', + 'journal_id', + 'created_at', + 'updated_at', + 'group_title', + 'type', + 'amount', + 'foreign_amount', + 'currency_code', + 'foreign_currency_code', + 'description', + 'date', + 'source_name', + 'source_iban', + 'source_type', + 'destination_name', + 'destination_iban', + 'destination_type', + 'reconciled', + 'category', + 'budget', + 'bill', + 'tags', + 'notes', + // all optional meta fields: ]; $metaFields = config('firefly.journal_meta_fields'); @@ -761,7 +960,15 @@ class ExportDataGenerator } /** - * @param array $tags + * @param Collection $accounts + */ + public function setAccounts(Collection $accounts): void + { + $this->accounts = $accounts; + } + + /** + * @param array $tags * * @return string */ @@ -779,15 +986,7 @@ class ExportDataGenerator } /** - * @param Collection $accounts - */ - public function setAccounts(Collection $accounts): void - { - $this->accounts = $accounts; - } - - /** - * @param Carbon $end + * @param Carbon $end */ public function setEnd(Carbon $end): void { @@ -795,7 +994,7 @@ class ExportDataGenerator } /** - * @param bool $exportAccounts + * @param bool $exportAccounts */ public function setExportAccounts(bool $exportAccounts): void { @@ -803,7 +1002,7 @@ class ExportDataGenerator } /** - * @param bool $exportBills + * @param bool $exportBills */ public function setExportBills(bool $exportBills): void { @@ -811,7 +1010,7 @@ class ExportDataGenerator } /** - * @param bool $exportBudgets + * @param bool $exportBudgets */ public function setExportBudgets(bool $exportBudgets): void { @@ -819,7 +1018,7 @@ class ExportDataGenerator } /** - * @param bool $exportCategories + * @param bool $exportCategories */ public function setExportCategories(bool $exportCategories): void { @@ -827,7 +1026,7 @@ class ExportDataGenerator } /** - * @param bool $exportPiggies + * @param bool $exportPiggies */ public function setExportPiggies(bool $exportPiggies): void { @@ -835,7 +1034,7 @@ class ExportDataGenerator } /** - * @param bool $exportRecurring + * @param bool $exportRecurring */ public function setExportRecurring(bool $exportRecurring): void { @@ -843,7 +1042,7 @@ class ExportDataGenerator } /** - * @param bool $exportRules + * @param bool $exportRules */ public function setExportRules(bool $exportRules): void { @@ -851,7 +1050,7 @@ class ExportDataGenerator } /** - * @param bool $exportTags + * @param bool $exportTags */ public function setExportTags(bool $exportTags): void { @@ -859,7 +1058,7 @@ class ExportDataGenerator } /** - * @param bool $exportTransactions + * @param bool $exportTransactions */ public function setExportTransactions(bool $exportTransactions): void { @@ -867,18 +1066,10 @@ class ExportDataGenerator } /** - * @param Carbon $start + * @param Carbon $start */ public function setStart(Carbon $start): void { $this->start = $start; } - - /** - * @param User $user - */ - public function setUser(User $user): void - { - $this->user = $user; - } } diff --git a/app/Support/Facades/AccountForm.php b/app/Support/Facades/AccountForm.php index 06d4f2da11..86c7046c07 100644 --- a/app/Support/Facades/AccountForm.php +++ b/app/Support/Facades/AccountForm.php @@ -1,4 +1,5 @@ count() === 1; + } + + /** + * @param string $name + * @param bool|string|int|null $default * * @return Configuration|null * @throws FireflyException */ public function get(string $name, $default = null): ?Configuration { - $fullName = 'ff-config-' . $name; + $fullName = 'ff-config-'.$name; if (Cache::has($fullName)) { return Cache::get($fullName); } @@ -86,8 +97,8 @@ class FireflyConfig } /** - * @param string $name - * @param mixed $value + * @param string $name + * @param mixed $value * * @return Configuration */ @@ -108,20 +119,20 @@ class FireflyConfig $item->name = $name; $item->data = $value; $item->save(); - Cache::forget('ff-config-' . $name); + Cache::forget('ff-config-'.$name); return $item; } $config->data = $value; $config->save(); - Cache::forget('ff-config-' . $name); + Cache::forget('ff-config-'.$name); return $config; } /** - * @param string $name - * @param mixed $default + * @param string $name + * @param mixed $default * * @return Configuration|null */ @@ -140,18 +151,8 @@ class FireflyConfig } /** - * @param string $name - * - * @return bool - */ - public function has(string $name): bool - { - return Configuration::where('name', $name)->count() === 1; - } - - /** - * @param string $name - * @param mixed $value + * @param string $name + * @param mixed $value * * @return Configuration */ diff --git a/app/Support/Form/AccountForm.php b/app/Support/Form/AccountForm.php index e1253809e7..31b02dcb93 100644 --- a/app/Support/Form/AccountForm.php +++ b/app/Support/Form/AccountForm.php @@ -45,9 +45,9 @@ class AccountForm /** * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -57,8 +57,8 @@ class AccountForm $repository = $this->getAccountRepository(); $grouped = $this->getAccountsGrouped($types, $repository); $cash = $repository->getCashAccount(); - $key = (string) trans('firefly.cash_account_type'); - $grouped[$key][$cash->id] = sprintf('(%s)', (string) trans('firefly.cash')); + $key = (string)trans('firefly.cash_account_type'); + $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash')); return $this->select($name, $grouped, $value, $options); } @@ -74,7 +74,7 @@ class AccountForm /** @var Account $account */ foreach ($accountList as $account) { - $role = (string) $repository->getMetaValue($account, 'account_role'); + $role = (string)$repository->getMetaValue($account, 'account_role'); if (in_array($account->accountType->type, $liabilityTypes, true)) { $role = sprintf('l_%s', $account->accountType->type); } elseif ('' === $role) { @@ -86,7 +86,7 @@ class AccountForm $role = 'no_account_type'; } } - $key = (string) trans(sprintf('firefly.opt_group_%s', $role)); + $key = (string)trans(sprintf('firefly.opt_group_%s', $role)); $grouped[$key][$account->id] = $account->name; } @@ -96,9 +96,9 @@ class AccountForm /** * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -109,8 +109,8 @@ class AccountForm $grouped = $this->getAccountsGrouped($types, $repository); $cash = $repository->getCashAccount(); - $key = (string) trans('firefly.cash_account_type'); - $grouped[$key][$cash->id] = sprintf('(%s)', (string) trans('firefly.cash')); + $key = (string)trans('firefly.cash_account_type'); + $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash')); return $this->select($name, $grouped, $value, $options); } @@ -118,8 +118,8 @@ class AccountForm /** * Check list of asset accounts. * - * @param string $name - * @param array|null $options + * @param string $name + * @param array|null $options * * @return string */ @@ -150,9 +150,9 @@ class AccountForm /** * Basic list of asset accounts. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -167,9 +167,9 @@ class AccountForm /** * Same list but all liabilities as well. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php index 1294e140d4..6f07c77fd5 100644 --- a/app/Support/Form/CurrencyForm.php +++ b/app/Support/Form/CurrencyForm.php @@ -41,9 +41,9 @@ class CurrencyForm use FormSupport; /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -53,10 +53,10 @@ class CurrencyForm } /** - * @param string $name - * @param string $view - * @param mixed $value - * @param array|null $options + * @param string $name + * @param string $view + * @param mixed $value + * @param array|null $options * * @return string */ @@ -77,8 +77,8 @@ class CurrencyForm if (!is_array($preFilled)) { $preFilled = []; } - $key = 'amount_currency_id_' . $name; - $sentCurrencyId = array_key_exists($key, $preFilled) ? (int) $preFilled[$key] : $defaultCurrency->id; + $key = 'amount_currency_id_'.$name; + $sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id; Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId)); @@ -96,7 +96,7 @@ class CurrencyForm $value = app('steam')->bcround($value, $defaultCurrency->decimal_places); } try { - $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); + $html = view('form.'.$view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); } catch (Throwable $e) { Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage())); $html = 'Could not render currencyField.'; @@ -109,9 +109,9 @@ class CurrencyForm /** * TODO describe and cleanup. * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -123,10 +123,10 @@ class CurrencyForm /** * TODO describe and cleanup * - * @param string $name - * @param string $view - * @param mixed $value - * @param array|null $options + * @param string $name + * @param string $view + * @param mixed $value + * @param array|null $options * * @return string */ @@ -147,8 +147,8 @@ class CurrencyForm if (!is_array($preFilled)) { $preFilled = []; } - $key = 'amount_currency_id_' . $name; - $sentCurrencyId = array_key_exists($key, $preFilled) ? (int) $preFilled[$key] : $defaultCurrency->id; + $key = 'amount_currency_id_'.$name; + $sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $defaultCurrency->id; Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId)); @@ -166,7 +166,7 @@ class CurrencyForm $value = app('steam')->bcround($value, $defaultCurrency->decimal_places); } try { - $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); + $html = view('form.'.$view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render(); } catch (Throwable $e) { Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage())); $html = 'Could not render currencyField.'; @@ -179,9 +179,9 @@ class CurrencyForm /** * TODO cleanup and describe * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -195,7 +195,7 @@ class CurrencyForm $array = []; /** @var TransactionCurrency $currency */ foreach ($list as $currency) { - $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')'; + $array[$currency->id] = $currency->name.' ('.$currency->symbol.')'; } return $this->select($name, $array, $value, $options); @@ -204,9 +204,9 @@ class CurrencyForm /** * TODO cleanup and describe * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -218,11 +218,11 @@ class CurrencyForm // get all currencies: $list = $currencyRepos->get(); $array = [ - 0 => (string) trans('firefly.no_currency'), + 0 => (string)trans('firefly.no_currency'), ]; /** @var TransactionCurrency $currency */ foreach ($list as $currency) { - $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')'; + $array[$currency->id] = $currency->name.' ('.$currency->symbol.')'; } return $this->select($name, $array, $value, $options); diff --git a/app/Support/Form/FormSupport.php b/app/Support/Form/FormSupport.php index 509a3d4dd9..80b9390d1c 100644 --- a/app/Support/Form/FormSupport.php +++ b/app/Support/Form/FormSupport.php @@ -37,10 +37,10 @@ use Throwable; trait FormSupport { /** - * @param string $name - * @param array|null $list - * @param mixed $selected - * @param array|null $options + * @param string $name + * @param array|null $list + * @param mixed $selected + * @param array|null $options * * @return string */ @@ -63,8 +63,8 @@ trait FormSupport } /** - * @param string $name - * @param array|null $options + * @param string $name + * @param array|null $options * * @return string */ @@ -76,13 +76,13 @@ trait FormSupport } $name = str_replace('[]', '', $name); - return (string) trans('form.' . $name); + return (string)trans('form.'.$name); } /** - * @param string $name - * @param mixed $label - * @param array|null $options + * @param string $name + * @param mixed $label + * @param array|null $options * * @return array */ @@ -91,7 +91,7 @@ trait FormSupport $options = $options ?? []; $name = str_replace('[]', '', $name); $options['class'] = 'form-control'; - $options['id'] = 'ffInput_' . $name; + $options['id'] = 'ffInput_'.$name; $options['autocomplete'] = 'off'; $options['placeholder'] = ucfirst($label); @@ -99,7 +99,7 @@ trait FormSupport } /** - * @param string $name + * @param string $name * * @return string */ @@ -118,8 +118,8 @@ trait FormSupport } /** - * @param string $name - * @param mixed|null $value + * @param string $name + * @param mixed|null $value * * @return mixed */ diff --git a/app/Support/Form/PiggyBankForm.php b/app/Support/Form/PiggyBankForm.php index 493505924c..c9391d375a 100644 --- a/app/Support/Form/PiggyBankForm.php +++ b/app/Support/Form/PiggyBankForm.php @@ -38,9 +38,9 @@ class PiggyBankForm /** * TODO cleanup and describe * - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -50,7 +50,7 @@ class PiggyBankForm /** @var PiggyBankRepositoryInterface $repository */ $repository = app(PiggyBankRepositoryInterface::class); $piggyBanks = $repository->getPiggyBanksWithAmount(); - $title = (string) trans('firefly.default_group_title_name'); + $title = (string)trans('firefly.default_group_title_name'); $array = []; $subList = [ 0 => [ @@ -58,7 +58,7 @@ class PiggyBankForm 'title' => $title, ], 'piggies' => [ - (string) trans('firefly.none_in_select_list'), + (string)trans('firefly.none_in_select_list'), ], ], ]; @@ -72,11 +72,11 @@ class PiggyBankForm $groupOrder = $group->order; } $subList[$groupOrder] = $subList[$groupOrder] ?? [ - 'group' => [ - 'title' => $groupTitle, - ], - 'piggies' => [], - ]; + 'group' => [ + 'title' => $groupTitle, + ], + 'piggies' => [], + ]; $subList[$groupOrder]['piggies'][$piggy->id] = $piggy->name; } ksort($subList); diff --git a/app/Support/Form/RuleForm.php b/app/Support/Form/RuleForm.php index 6b30dd269a..c20d8e49ce 100644 --- a/app/Support/Form/RuleForm.php +++ b/app/Support/Form/RuleForm.php @@ -37,9 +37,9 @@ class RuleForm use FormSupport; /** - * @param string $name - * @param mixed $value - * @param array|null $options + * @param string $name + * @param mixed $value + * @param array|null $options * * @return string */ @@ -60,9 +60,9 @@ class RuleForm } /** - * @param string $name - * @param null $value - * @param array|null $options + * @param string $name + * @param null $value + * @param array|null $options * * @return HtmlString */ @@ -76,11 +76,11 @@ class RuleForm // get all currencies: $list = $groupRepos->get(); $array = [ - 0 => (string) trans('firefly.none_in_select_list'), + 0 => (string)trans('firefly.none_in_select_list'), ]; /** @var RuleGroup $group */ foreach ($list as $group) { - if (array_key_exists('hidden', $options) && (int) $options['hidden'] !== $group->id) { + if (array_key_exists('hidden', $options) && (int)$options['hidden'] !== $group->id) { $array[$group->id] = $group->title; } } diff --git a/app/Support/Http/Api/AccountFilter.php b/app/Support/Http/Api/AccountFilter.php index 8624181e5d..1204164501 100644 --- a/app/Support/Http/Api/AccountFilter.php +++ b/app/Support/Http/Api/AccountFilter.php @@ -35,17 +35,27 @@ trait AccountFilter /** * All the available types. * - * @param string $type + * @param string $type * * @return array */ protected function mapAccountTypes(string $type): array { $types = [ - 'all' => [AccountType::DEFAULT, AccountType::CASH, - AccountType::ASSET, AccountType::EXPENSE, AccountType::REVENUE, - AccountType::INITIAL_BALANCE, AccountType::BENEFICIARY, AccountType::IMPORT, AccountType::RECONCILIATION, - AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], + 'all' => [ + AccountType::DEFAULT, + AccountType::CASH, + AccountType::ASSET, + AccountType::EXPENSE, + AccountType::REVENUE, + AccountType::INITIAL_BALANCE, + AccountType::BENEFICIARY, + AccountType::IMPORT, + AccountType::RECONCILIATION, + AccountType::LOAN, + AccountType::DEBT, + AccountType::MORTGAGE, + ], 'asset' => [AccountType::DEFAULT, AccountType::ASSET,], 'cash' => [AccountType::CASH,], 'expense' => [AccountType::EXPENSE, AccountType::BENEFICIARY,], diff --git a/app/Support/Http/Api/ApiSupport.php b/app/Support/Http/Api/ApiSupport.php index afe8de3b9e..342c8eb51d 100644 --- a/app/Support/Http/Api/ApiSupport.php +++ b/app/Support/Http/Api/ApiSupport.php @@ -36,7 +36,7 @@ trait ApiSupport /** * Small helper function for the revenue and expense account charts. * - * @param array $names + * @param array $names * * @return array */ @@ -53,7 +53,7 @@ trait ApiSupport /** * Small helper function for the revenue and expense account charts. * - * @param Collection $accounts + * @param Collection $accounts * * @return array */ diff --git a/app/Support/Http/Api/ConvertsExchangeRates.php b/app/Support/Http/Api/ConvertsExchangeRates.php index ac022c6908..e3e567fcba 100644 --- a/app/Support/Http/Api/ConvertsExchangeRates.php +++ b/app/Support/Http/Api/ConvertsExchangeRates.php @@ -37,10 +37,47 @@ trait ConvertsExchangeRates { private ?bool $enabled = null; + /** + * @param array $set + * @return array + */ + public function cerChartSet(array $set): array + { + if (null === $this->enabled) { + $this->getPreference(); + } + + // if not enabled, return the same array but without conversion: + if (false === $this->enabled) { + $set['converted'] = false; + return $set; + } + + $set['converted'] = true; + /** @var TransactionCurrency $native */ + $native = app('amount')->getDefaultCurrency(); + $currency = $this->getCurrency((int)$set['currency_id']); + if ($native->id === $currency->id) { + $set['native_id'] = (string)$currency->id; + $set['native_code'] = $currency->code; + $set['native_symbol'] = $currency->symbol; + $set['native_decimal_places'] = $currency->decimal_places; + return $set; + } + foreach ($set['entries'] as $date => $entry) { + $carbon = Carbon::createFromFormat(DateTimeInterface::ATOM, $date); + $rate = $this->getRate($currency, $native, $carbon); + $rate = '0' === $rate ? '1' : $rate; + Log::debug(sprintf('bcmul("%s", "%s")', (string)$entry, $rate)); + $set['entries'][$date] = (float)bcmul((string)$entry, $rate); + } + return $set; + } + /** * For a sum of entries, get the exchange rate to the native currency of * the user. - * @param array $entries + * @param array $entries * @return array */ public function cerSum(array $entries): array @@ -66,12 +103,12 @@ trait ConvertsExchangeRates $return = []; /** @var array $entry */ foreach ($entries as $entry) { - $currency = $this->getCurrency((int) $entry['id']); + $currency = $this->getCurrency((int)$entry['id']); if ($currency->id !== $native->id) { $amount = $this->convertAmount($entry['sum'], $currency, $native); $entry['converted'] = true; $entry['native_sum'] = $amount; - $entry['native_id'] = (string) $native->id; + $entry['native_id'] = (string)$native->id; $entry['native_name'] = $native->name; $entry['native_symbol'] = $native->symbol; $entry['native_code'] = $native->code; @@ -80,7 +117,7 @@ trait ConvertsExchangeRates if ($currency->id === $native->id) { $entry['converted'] = false; $entry['native_sum'] = $entry['sum']; - $entry['native_id'] = (string) $native->id; + $entry['native_id'] = (string)$native->id; $entry['native_name'] = $native->name; $entry['native_symbol'] = $native->symbol; $entry['native_code'] = $native->code; @@ -92,44 +129,15 @@ trait ConvertsExchangeRates } /** - * @param array $set - * @return array + * @return void */ - public function cerChartSet(array $set): array + private function getPreference(): void { - if (null === $this->enabled) { - $this->getPreference(); - } - - // if not enabled, return the same array but without conversion: - if (false === $this->enabled) { - $set['converted'] = false; - return $set; - } - - $set['converted'] = true; - /** @var TransactionCurrency $native */ - $native = app('amount')->getDefaultCurrency(); - $currency = $this->getCurrency((int) $set['currency_id']); - if ($native->id === $currency->id) { - $set['native_id'] = (string) $currency->id; - $set['native_code'] = $currency->code; - $set['native_symbol'] = $currency->symbol; - $set['native_decimal_places'] = $currency->decimal_places; - return $set; - } - foreach ($set['entries'] as $date => $entry) { - $carbon = Carbon::createFromFormat(DateTimeInterface::ATOM, $date); - $rate = $this->getRate($currency, $native, $carbon); - $rate = '0' === $rate ? '1' : $rate; - Log::debug(sprintf('bcmul("%s", "%s")', (string) $entry, $rate)); - $set['entries'][$date] = (float) bcmul((string) $entry, $rate); - } - return $set; + $this->enabled = true; } /** - * @param int $currencyId + * @param int $currencyId * @return TransactionCurrency */ private function getCurrency(int $currencyId): TransactionCurrency @@ -142,9 +150,9 @@ trait ConvertsExchangeRates } /** - * @param string $amount - * @param TransactionCurrency $from - * @param TransactionCurrency $to + * @param string $amount + * @param TransactionCurrency $from + * @param TransactionCurrency $to * @return string */ private function convertAmount(string $amount, TransactionCurrency $from, TransactionCurrency $to, ?Carbon $date = null): string @@ -157,9 +165,9 @@ trait ConvertsExchangeRates } /** - * @param TransactionCurrency $from - * @param TransactionCurrency $to - * @param Carbon $date + * @param TransactionCurrency $from + * @param TransactionCurrency $to + * @param Carbon $date * @return string */ private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string @@ -174,7 +182,7 @@ trait ConvertsExchangeRates ->orderBy('date', 'DESC') ->first(); if (null !== $result) { - $rate = (string) $result->rate; + $rate = (string)$result->rate; Log::debug(sprintf('Rate is %s', $rate)); return $rate; } @@ -188,7 +196,7 @@ trait ConvertsExchangeRates ->orderBy('date', 'DESC') ->first(); if (null !== $result) { - $rate = bcdiv('1', (string) $result->rate); + $rate = bcdiv('1', (string)$result->rate); Log::debug(sprintf('Reversed rate is %s', $rate)); return $rate; } @@ -213,8 +221,8 @@ trait ConvertsExchangeRates } /** - * @param TransactionCurrency $currency - * @param Carbon $date + * @param TransactionCurrency $currency + * @param Carbon $date * @return string */ private function getEuroRate(TransactionCurrency $currency, Carbon $date): string @@ -236,7 +244,7 @@ trait ConvertsExchangeRates ->orderBy('date', 'DESC') ->first(); if (null !== $result) { - $rate = (string) $result->rate; + $rate = (string)$result->rate; Log::debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate)); return $rate; } @@ -250,7 +258,7 @@ trait ConvertsExchangeRates ->orderBy('date', 'DESC') ->first(); if (null !== $result) { - $rate = bcdiv('1', (string) $result->rate); + $rate = bcdiv('1', (string)$result->rate); Log::debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate)); return $rate; } @@ -258,12 +266,4 @@ trait ConvertsExchangeRates Log::debug(sprintf('No rate for %s to EUR.', $currency->code)); return '0'; } - - /** - * @return void - */ - private function getPreference(): void - { - $this->enabled = true; - } } diff --git a/app/Support/Http/Api/TransactionFilter.php b/app/Support/Http/Api/TransactionFilter.php index f0e703860d..b5b4376df0 100644 --- a/app/Support/Http/Api/TransactionFilter.php +++ b/app/Support/Http/Api/TransactionFilter.php @@ -35,15 +35,20 @@ trait TransactionFilter /** * All the types you can request. * - * @param string $type + * @param string $type * * @return array */ protected function mapTransactionTypes(string $type): array { $types = [ - 'all' => [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE, - TransactionType::RECONCILIATION,], + 'all' => [ + TransactionType::WITHDRAWAL, + TransactionType::DEPOSIT, + TransactionType::TRANSFER, + TransactionType::OPENING_BALANCE, + TransactionType::RECONCILIATION, + ], 'withdrawal' => [TransactionType::WITHDRAWAL,], 'withdrawals' => [TransactionType::WITHDRAWAL,], 'expense' => [TransactionType::WITHDRAWAL,], diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.php index 954cc77a65..1db9fb5f8f 100644 --- a/app/Support/Http/Controllers/AugumentData.php +++ b/app/Support/Http/Controllers/AugumentData.php @@ -37,7 +37,6 @@ use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; -use JsonException; /** * Trait AugumentData @@ -48,7 +47,7 @@ trait AugumentData /** * Searches for the opposing account. * - * @param Collection $accounts + * @param Collection $accounts * * @return array */ @@ -75,7 +74,7 @@ trait AugumentData /** * Small helper function for the revenue and expense account charts. * - * @param array $names + * @param array $names * * @return array */ @@ -92,7 +91,7 @@ trait AugumentData /** * Small helper function for the revenue and expense account charts. * - * @param Collection $accounts + * @param Collection $accounts * * @return array */ @@ -110,7 +109,7 @@ trait AugumentData /** * Get the account names belonging to a bunch of account ID's. * - * @param array $accountIds + * @param array $accountIds * * @return array */ @@ -123,7 +122,7 @@ trait AugumentData $return = []; foreach ($accountIds as $combinedId) { $parts = explode('-', $combinedId); - $accountId = (int) $parts[0]; + $accountId = (int)$parts[0]; if (array_key_exists($accountId, $grouped)) { $return[$accountId] = $grouped[$accountId][0]['name']; } @@ -136,7 +135,7 @@ trait AugumentData /** * Get the budget names from a set of budget ID's. * - * @param array $budgetIds + * @param array $budgetIds * * @return array */ @@ -152,7 +151,7 @@ trait AugumentData $return[$budgetId] = $grouped[$budgetId][0]['name']; } } - $return[0] = (string) trans('firefly.no_budget'); + $return[0] = (string)trans('firefly.no_budget'); return $return; } @@ -160,7 +159,7 @@ trait AugumentData /** * Get the category names from a set of category ID's. Small helper function for some of the charts. * - * @param array $categoryIds + * @param array $categoryIds * * @return array */ @@ -173,12 +172,12 @@ trait AugumentData $return = []; foreach ($categoryIds as $combinedId) { $parts = explode('-', $combinedId); - $categoryId = (int) $parts[0]; + $categoryId = (int)$parts[0]; if (array_key_exists($categoryId, $grouped)) { $return[$categoryId] = $grouped[$categoryId][0]['name']; } } - $return[0] = (string) trans('firefly.no_category'); + $return[0] = (string)trans('firefly.no_category'); return $return; } @@ -186,9 +185,9 @@ trait AugumentData /** * Gets all budget limits for a budget. * - * @param Budget $budget - * @param Carbon $start - * @param Carbon $end + * @param Budget $budget + * @param Carbon $start + * @param Carbon $end * * @return Collection */ @@ -221,7 +220,7 @@ trait AugumentData $currentStart = clone $entry->start_date; $currentEnd = clone $entry->end_date; $expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency); - $spent = $expenses[(int) $currency->id]['sum'] ?? '0'; + $spent = $expenses[(int)$currency->id]['sum'] ?? '0'; $entry->spent = $spent; $limits->push($entry); @@ -234,7 +233,7 @@ trait AugumentData /** * Group set of transactions by name of opposing account. * - * @param array $array + * @param array $array * * @return array */ @@ -262,10 +261,10 @@ trait AugumentData /** * Spent in a period. * - * @param Collection $assets - * @param Collection $opposing - * @param Carbon $start - * @param Carbon $end + * @param Collection $assets + * @param Collection $opposing + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -283,7 +282,7 @@ trait AugumentData ]; // loop to support multi currency foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; // if not set, set to zero: if (!array_key_exists($currencyId, $sum['per_currency'])) { diff --git a/app/Support/Http/Controllers/BasicDataSupport.php b/app/Support/Http/Controllers/BasicDataSupport.php index 360634330b..d0bc600038 100644 --- a/app/Support/Http/Controllers/BasicDataSupport.php +++ b/app/Support/Http/Controllers/BasicDataSupport.php @@ -34,8 +34,8 @@ trait BasicDataSupport /** * Find the ID in a given array. Return '0' if not there (amount). * - * @param array $array - * @param int $entryId + * @param array $array + * @param int $entryId * * @return null|mixed */ @@ -47,8 +47,8 @@ trait BasicDataSupport /** * Find the ID in a given array. Return null if not there (amount). * - * @param array $array - * @param int $entryId + * @param array $array + * @param int $entryId * * @return null|Carbon */ diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php index 7ccdbe8a73..ce5518e8d3 100644 --- a/app/Support/Http/Controllers/ChartGeneration.php +++ b/app/Support/Http/Controllers/ChartGeneration.php @@ -42,9 +42,9 @@ trait ChartGeneration /** * Shows an overview of the account balances for a set of accounts. * - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException @@ -76,7 +76,7 @@ trait ChartGeneration /** @var Account $account */ foreach ($accounts as $account) { // TODO we can use getAccountCurrency instead. - $currency = $repository->find((int) $accountRepos->getMetaValue($account, 'currency_id')); + $currency = $repository->find((int)$accountRepos->getMetaValue($account, 'currency_id')); if (null === $currency) { $currency = $default; } @@ -91,7 +91,7 @@ trait ChartGeneration $previous = array_values($range)[0]; while ($currentStart <= $end) { $format = $currentStart->format('Y-m-d'); - $label = trim($currentStart->isoFormat((string) trans('config.month_and_day_js', [], $locale))); + $label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale))); $balance = $range[$format] ?? $previous; $previous = $balance; $currentStart->addDay(); diff --git a/app/Support/Http/Controllers/CreateStuff.php b/app/Support/Http/Controllers/CreateStuff.php index 690d652915..368b57ea1e 100644 --- a/app/Support/Http/Controllers/CreateStuff.php +++ b/app/Support/Http/Controllers/CreateStuff.php @@ -42,8 +42,8 @@ trait CreateStuff /** * Creates an asset account. * - * @param NewUserFormRequest $request - * @param TransactionCurrency $currency + * @param NewUserFormRequest $request + * @param TransactionCurrency $currency * * @return bool */ @@ -72,8 +72,8 @@ trait CreateStuff /** * Creates a cash wallet. * - * @param TransactionCurrency $currency - * @param string $language + * @param TransactionCurrency $currency + * @param string $language * * @return bool */ @@ -82,7 +82,7 @@ trait CreateStuff /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $assetAccount = [ - 'name' => (string) trans('firefly.cash_wallet', [], $language), + 'name' => (string)trans('firefly.cash_wallet', [], $language), 'iban' => null, 'account_type_name' => 'asset', 'virtual_balance' => 0, @@ -138,9 +138,9 @@ trait CreateStuff /** * Create a savings account. * - * @param NewUserFormRequest $request - * @param TransactionCurrency $currency - * @param string $language + * @param NewUserFormRequest $request + * @param TransactionCurrency $currency + * @param string $language * * @return bool */ @@ -149,7 +149,7 @@ trait CreateStuff /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $savingsAccount = [ - 'name' => (string) trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language), + 'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language), 'iban' => null, 'account_type_name' => 'asset', 'account_type_id' => null, @@ -168,7 +168,7 @@ trait CreateStuff /** * Create a new user instance after a valid registration. * - * @param array $data + * @param array $data * * @return User */ diff --git a/app/Support/Http/Controllers/CronRunner.php b/app/Support/Http/Controllers/CronRunner.php index 58ca2826d9..db119cab87 100644 --- a/app/Support/Http/Controllers/CronRunner.php +++ b/app/Support/Http/Controllers/CronRunner.php @@ -34,8 +34,8 @@ use FireflyIII\Support\Cronjobs\RecurringCronjob; trait CronRunner { /** - * @param bool $force - * @param Carbon $date + * @param bool $force + * @param Carbon $date * * @return array */ @@ -65,8 +65,8 @@ trait CronRunner } /** - * @param bool $force - * @param Carbon $date + * @param bool $force + * @param Carbon $date * * @return array */ diff --git a/app/Support/Http/Controllers/DateCalculation.php b/app/Support/Http/Controllers/DateCalculation.php index 9c92f971ac..563146f321 100644 --- a/app/Support/Http/Controllers/DateCalculation.php +++ b/app/Support/Http/Controllers/DateCalculation.php @@ -37,8 +37,8 @@ trait DateCalculation * * If both are in the past OR both are in the future, simply return the number of days in the period with a minimum of 1 * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return int */ @@ -59,8 +59,8 @@ trait DateCalculation * * If both are in the past OR both are in the future, simply return the period between them with a minimum of 1 * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return int */ @@ -77,8 +77,8 @@ trait DateCalculation } /** - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -103,8 +103,8 @@ trait DateCalculation * Get a list of the periods that will occur after this date. For example, * March 2018, April 2018, etc. * - * @param Carbon $date - * @param string $range + * @param Carbon $date + * @param string $range * * @return array */ @@ -139,8 +139,8 @@ trait DateCalculation * Get a list of the periods that occurred before the start date. For example, * March 2018, February 2018, etc. * - * @param Carbon $date - * @param string $range + * @param Carbon $date + * @param string $range * * @return array */ diff --git a/app/Support/Http/Controllers/GetConfigurationData.php b/app/Support/Http/Controllers/GetConfigurationData.php index b465743356..7b5561d3a2 100644 --- a/app/Support/Http/Controllers/GetConfigurationData.php +++ b/app/Support/Http/Controllers/GetConfigurationData.php @@ -26,6 +26,8 @@ namespace FireflyIII\Support\Http\Controllers; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Trait GetConfigurationData @@ -36,7 +38,7 @@ trait GetConfigurationData /** * Some common combinations. * - * @param int $value + * @param int $value * * @return string */ @@ -52,13 +54,13 @@ trait GetConfigurationData E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR => 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR', ]; - return $array[$value] ?? (string) $value; + return $array[$value] ?? (string)$value; } /** * Get the basic steps from config. * - * @param string $route + * @param string $route * * @return array */ @@ -72,7 +74,7 @@ trait GetConfigurationData $currentStep = $options; // get the text: - $currentStep['intro'] = (string) trans('intro.' . $route . '_' . $key); + $currentStep['intro'] = (string)trans('intro.'.$route.'_'.$key); // save in array: $steps[] = $currentStep; @@ -88,12 +90,12 @@ trait GetConfigurationData * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getDateRangeConfig(): array // get configuration + get preferences. { - $viewRange = (string) app('preferences')->get('viewRange', '1M')->data; + $viewRange = (string)app('preferences')->get('viewRange', '1M')->data; /** @var Carbon $start */ $start = session('start'); /** @var Carbon $end */ @@ -134,41 +136,41 @@ trait GetConfigurationData /** @var Carbon $todayEnd */ $todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange); if ($todayStart->ne($start) || $todayEnd->ne($end)) { - $ranges[ucfirst((string) trans('firefly.today'))] = [$todayStart, $todayEnd]; + $ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd]; } // last seven days: $seven = Carbon::now()->subDays(7); - $index = (string) trans('firefly.last_seven_days'); + $index = (string)trans('firefly.last_seven_days'); $ranges[$index] = [$seven, new Carbon()]; // last 30 days: $thirty = Carbon::now()->subDays(30); - $index = (string) trans('firefly.last_thirty_days'); + $index = (string)trans('firefly.last_thirty_days'); $ranges[$index] = [$thirty, new Carbon()]; // month to date: $monthBegin = Carbon::now()->startOfMonth(); - $index = (string) trans('firefly.month_to_date'); + $index = (string)trans('firefly.month_to_date'); $ranges[$index] = [$monthBegin, new Carbon()]; // year to date: $yearBegin = Carbon::now()->startOfYear(); - $index = (string) trans('firefly.year_to_date'); + $index = (string)trans('firefly.year_to_date'); $ranges[$index] = [$yearBegin, new Carbon()]; // everything - $index = (string) trans('firefly.everything'); + $index = (string)trans('firefly.everything'); $ranges[$index] = [$first, new Carbon()]; return [ 'title' => $title, 'configuration' => [ - 'apply' => (string) trans('firefly.apply'), - 'cancel' => (string) trans('firefly.cancel'), - 'from' => (string) trans('firefly.from'), - 'to' => (string) trans('firefly.to'), - 'customRange' => (string) trans('firefly.customRange'), + 'apply' => (string)trans('firefly.apply'), + 'cancel' => (string)trans('firefly.cancel'), + 'from' => (string)trans('firefly.from'), + 'to' => (string)trans('firefly.to'), + 'customRange' => (string)trans('firefly.customRange'), 'start' => $start->format('Y-m-d'), 'end' => $end->format('Y-m-d'), 'ranges' => $ranges, @@ -179,8 +181,8 @@ trait GetConfigurationData /** * Get specific info for special routes. * - * @param string $route - * @param string $specificPage + * @param string $route + * @param string $specificPage * * @return array * @@ -193,13 +195,13 @@ trait GetConfigurationData // user is on page with specific instructions: if ('' !== $specificPage) { $routeKey = str_replace('.', '_', $route); - $elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage)); + $elements = config(sprintf('intro.%s', $routeKey.'_'.$specificPage)); if (is_array($elements) && count($elements) > 0) { foreach ($elements as $key => $options) { $currentStep = $options; // get the text: - $currentStep['intro'] = (string) trans('intro.' . $route . '_' . $specificPage . '_' . $key); + $currentStep['intro'] = (string)trans('intro.'.$route.'_'.$specificPage.'_'.$key); // save in array: $steps[] = $currentStep; @@ -217,7 +219,7 @@ trait GetConfigurationData protected function verifyRecurringCronJob(): void { $config = app('fireflyconfig')->get('last_rt_job', 0); - $lastTime = (int) $config->data; + $lastTime = (int)$config->data; $now = time(); Log::debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config->data, $now)); if (0 === $lastTime) { diff --git a/app/Support/Http/Controllers/ModelInformation.php b/app/Support/Http/Controllers/ModelInformation.php index 7581e2b871..957549e1cd 100644 --- a/app/Support/Http/Controllers/ModelInformation.php +++ b/app/Support/Http/Controllers/ModelInformation.php @@ -42,7 +42,7 @@ trait ModelInformation /** * Get actions based on a bill. * - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -80,13 +80,13 @@ trait ModelInformation /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); // types of liability: - $debt = $repository->getAccountTypeByType(AccountType::DEBT); - $loan = $repository->getAccountTypeByType(AccountType::LOAN); - $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); + $debt = $repository->getAccountTypeByType(AccountType::DEBT); + $loan = $repository->getAccountTypeByType(AccountType::LOAN); + $mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); $liabilityTypes = [ - $debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::DEBT)), - $loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::LOAN)), - $mortgage->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)), + $debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)), + $loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)), + $mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)), ]; asort($liabilityTypes); @@ -101,7 +101,7 @@ trait ModelInformation { $roles = []; foreach (config('firefly.accountRoles') as $role) { - $roles[$role] = (string) trans(sprintf('firefly.account_role_%s', $role)); + $roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role)); } return $roles; @@ -110,7 +110,7 @@ trait ModelInformation /** * Create fake triggers to match the bill's properties * - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -121,7 +121,7 @@ trait ModelInformation $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); @@ -161,7 +161,7 @@ trait ModelInformation } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return array */ @@ -172,7 +172,7 @@ trait ModelInformation $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index f851d0b59c..99e98c590b 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -33,8 +33,9 @@ use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Support\Collection; -use JsonException; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Trait PeriodOverview. @@ -73,14 +74,14 @@ trait PeriodOverview * and for each period, the amount of money spent and earned. This is a complex operation which is cached for * performance reasons. * - * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Account $account + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array { @@ -152,9 +153,9 @@ trait PeriodOverview /** * Filter a list of journals by a set of dates, and then group them by currency. * - * @param array $array - * @param Carbon $start - * @param Carbon $end + * @param array $array + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -174,8 +175,8 @@ trait PeriodOverview /** * Return only transactions where $account is the source. * - * @param Account $account - * @param array $journals + * @param Account $account + * @param array $journals * * @return array */ @@ -184,7 +185,7 @@ trait PeriodOverview $return = []; /** @var array $journal */ foreach ($journals as $journal) { - if ($account->id === (int) $journal['source_account_id']) { + if ($account->id === (int)$journal['source_account_id']) { $return[] = $journal; } } @@ -195,8 +196,8 @@ trait PeriodOverview /** * Return only transactions where $account is the source. * - * @param Account $account - * @param array $journals + * @param Account $account + * @param array $journals * * @return array * @codeCoverageIgnore @@ -206,7 +207,7 @@ trait PeriodOverview $return = []; /** @var array $journal */ foreach ($journals as $journal) { - if ($account->id === (int) $journal['destination_account_id']) { + if ($account->id === (int)$journal['destination_account_id']) { $return[] = $journal; } } @@ -215,7 +216,7 @@ trait PeriodOverview } /** - * @param array $journals + * @param array $journals * * @return array * @codeCoverageIgnore @@ -225,7 +226,7 @@ trait PeriodOverview $return = []; /** @var array $journal */ foreach ($journals as $journal) { - $currencyId = (int) $journal['currency_id']; + $currencyId = (int)$journal['currency_id']; $foreignCurrencyId = $journal['foreign_currency_id']; if (!array_key_exists($currencyId, $return)) { $return[$currencyId] = [ @@ -246,7 +247,7 @@ trait PeriodOverview $return[$foreignCurrencyId] = [ 'amount' => '0', 'count' => 0, - 'currency_id' => (int) $foreignCurrencyId, + 'currency_id' => (int)$foreignCurrencyId, 'currency_name' => $journal['foreign_currency_name'], 'currency_code' => $journal['foreign_currency_code'], 'currency_symbol' => $journal['foreign_currency_symbol'], @@ -264,14 +265,14 @@ trait PeriodOverview /** * Overview for single category. Has been refactored recently. * - * @param Category $category - * @param Carbon $start - * @param Carbon $end + * @param Category $category + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array { @@ -345,13 +346,13 @@ trait PeriodOverview * * This method has been refactored recently. * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array { @@ -401,12 +402,12 @@ trait PeriodOverview * * Show period overview for no category view. * - * @param Carbon $theDate + * @param Carbon $theDate * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getNoCategoryPeriodOverview(Carbon $theDate): array { @@ -471,14 +472,14 @@ trait PeriodOverview /** * This shows a period overview for a tag. It goes back in time and lists all relevant transactions and sums. * - * @param Tag $tag - * @param Carbon $start - * @param Carbon $end + * @param Tag $tag + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags. { @@ -546,14 +547,14 @@ trait PeriodOverview } /** - * @param string $transactionType - * @param Carbon $start - * @param Carbon $end + * @param string $transactionType + * @param Carbon $start + * @param Carbon $end * * @return array * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array { diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php index 19817ba2f7..026bffd204 100644 --- a/app/Support/Http/Controllers/RenderPartialViews.php +++ b/app/Support/Http/Controllers/RenderPartialViews.php @@ -48,7 +48,7 @@ trait RenderPartialViews /** * View for transactions in a budget for an account. * - * @param array $attributes + * @param array $attributes * * @return string */ @@ -59,10 +59,10 @@ trait RenderPartialViews /** @var BudgetRepositoryInterface $budgetRepository */ $budgetRepository = app(BudgetRepositoryInterface::class); - $budget = $budgetRepository->find((int) $attributes['budgetId']); + $budget = $budgetRepository->find((int)$attributes['budgetId']); $accountRepos = app(AccountRepositoryInterface::class); - $account = $accountRepos->find((int) $attributes['accountId']); + $account = $accountRepos->find((int)$attributes['accountId']); $journals = $popupHelper->balanceForBudget($budget, $account, $attributes); @@ -102,7 +102,7 @@ trait RenderPartialViews /** * View for spent in a single budget. * - * @param array $attributes + * @param array $attributes * * @return string */ @@ -114,7 +114,7 @@ trait RenderPartialViews /** @var PopupReportInterface $popupHelper */ $popupHelper = app(PopupReportInterface::class); - $budget = $budgetRepository->find((int) $attributes['budgetId']); + $budget = $budgetRepository->find((int)$attributes['budgetId']); if (null === $budget) { $budget = new Budget(); } @@ -134,7 +134,7 @@ trait RenderPartialViews /** * View for transactions in a category. * - * @param array $attributes + * @param array $attributes * * @return string */ @@ -145,7 +145,7 @@ trait RenderPartialViews /** @var CategoryRepositoryInterface $categoryRepository */ $categoryRepository = app(CategoryRepositoryInterface::class); - $category = $categoryRepository->find((int) $attributes['categoryId']); + $category = $categoryRepository->find((int)$attributes['categoryId']); $journals = $popupHelper->byCategory($category, $attributes); try { @@ -226,7 +226,7 @@ trait RenderPartialViews /** * Returns all the expenses that went to the given expense account. * - * @param array $attributes + * @param array $attributes * * @return string */ @@ -238,7 +238,7 @@ trait RenderPartialViews /** @var PopupReportInterface $popupHelper */ $popupHelper = app(PopupReportInterface::class); - $account = $accountRepository->find((int) $attributes['accountId']); + $account = $accountRepository->find((int)$attributes['accountId']); if (null === $account) { return 'This is an unknown account. Apologies.'; @@ -260,7 +260,7 @@ trait RenderPartialViews /** * Get current (from system) rule actions. * - * @param Rule $rule + * @param Rule $rule * * @return array */ @@ -298,7 +298,7 @@ trait RenderPartialViews /** * Get current (from DB) rule triggers. * - * @param Rule $rule + * @param Rule $rule * * @return array * @@ -310,7 +310,7 @@ trait RenderPartialViews $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); @@ -354,7 +354,7 @@ trait RenderPartialViews /** * Returns all the incomes that went to the given asset account. * - * @param array $attributes + * @param array $attributes * * @return string */ @@ -365,7 +365,7 @@ trait RenderPartialViews /** @var PopupReportInterface $popupHelper */ $popupHelper = app(PopupReportInterface::class); - $account = $accountRepository->find((int) $attributes['accountId']); + $account = $accountRepository->find((int)$attributes['accountId']); if (null === $account) { return 'This is an unknown category. Apologies.'; diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php index f0d9ca2d73..e85afb2e81 100644 --- a/app/Support/Http/Controllers/RequestInformation.php +++ b/app/Support/Http/Controllers/RequestInformation.php @@ -37,6 +37,8 @@ use Illuminate\Routing\Route; use Illuminate\Support\Facades\Validator; use InvalidArgumentException; use Log; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Route as RouteFacade; /** @@ -88,8 +90,8 @@ trait RequestInformation * * @return bool * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ final protected function hasSeenDemo(): bool // get request info + get preference { diff --git a/app/Support/Http/Controllers/RuleManagement.php b/app/Support/Http/Controllers/RuleManagement.php index 7803c2edb8..a839b01018 100644 --- a/app/Support/Http/Controllers/RuleManagement.php +++ b/app/Support/Http/Controllers/RuleManagement.php @@ -37,7 +37,7 @@ use Throwable; trait RuleManagement { /** - * @param Request $request + * @param Request $request * * @return array * @codeCoverageIgnore @@ -55,7 +55,7 @@ trait RuleManagement [ 'oldAction' => $oldAction['type'], 'oldValue' => $oldAction['value'], - 'oldChecked' => 1 === (int) ($oldAction['stop_processing'] ?? '0'), + 'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'), 'count' => $index + 1, ] )->render(); @@ -72,7 +72,7 @@ trait RuleManagement } /** - * @param Request $request + * @param Request $request * * @return array * @codeCoverageIgnore @@ -84,7 +84,7 @@ trait RuleManagement $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); @@ -100,8 +100,8 @@ trait RuleManagement [ 'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']), 'oldValue' => $oldTrigger['value'], - 'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'), - 'oldProhibited' => 1 === (int) ($oldTrigger['prohibited'] ?? '0'), + 'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'), + 'oldProhibited' => 1 === (int)($oldTrigger['prohibited'] ?? '0'), 'count' => $index + 1, 'triggers' => $triggers, ] @@ -119,7 +119,7 @@ trait RuleManagement } /** - * @param array $submittedOperators + * @param array $submittedOperators * * @return array */ @@ -131,7 +131,7 @@ trait RuleManagement $triggers = []; foreach ($operators as $key => $operator) { if ('user_action' !== $key && false === $operator['alias']) { - $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key)); + $triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); } } asort($triggers); @@ -169,8 +169,8 @@ trait RuleManagement $repository = app(RuleGroupRepositoryInterface::class); if (0 === $repository->count()) { $data = [ - 'title' => (string) trans('firefly.default_rule_group_name'), - 'description' => (string) trans('firefly.default_rule_group_description'), + 'title' => (string)trans('firefly.default_rule_group_name'), + 'description' => (string)trans('firefly.default_rule_group_description'), 'active' => true, ]; diff --git a/app/Support/Http/Controllers/TransactionCalculation.php b/app/Support/Http/Controllers/TransactionCalculation.php index c17c26a7a5..5d8ac77d9d 100644 --- a/app/Support/Http/Controllers/TransactionCalculation.php +++ b/app/Support/Http/Controllers/TransactionCalculation.php @@ -37,10 +37,10 @@ trait TransactionCalculation /** * Get all expenses for a set of accounts. * - * @param Collection $accounts - * @param Collection $opposing - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $opposing + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -61,10 +61,10 @@ trait TransactionCalculation /** * Get all expenses by tags. * - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return array * @@ -83,10 +83,10 @@ trait TransactionCalculation /** * Helper function that collects expenses for the given budgets. * - * @param Collection $accounts - * @param Collection $budgets - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $budgets + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -103,10 +103,10 @@ trait TransactionCalculation /** * Get all expenses in a period for categories. * - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -127,10 +127,10 @@ trait TransactionCalculation /** * Get all income for a period and a bunch of categories. * - * @param Collection $accounts - * @param Collection $categories - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $categories + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -147,10 +147,10 @@ trait TransactionCalculation /** * Get the income for a set of accounts. * - * @param Collection $accounts - * @param Collection $opposing - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $opposing + * @param Carbon $start + * @param Carbon $end * * @return array */ @@ -167,10 +167,10 @@ trait TransactionCalculation /** * Get all income by tag. * - * @param Collection $accounts - * @param Collection $tags - * @param Carbon $start - * @param Carbon $end + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end * * @return array */ diff --git a/app/Support/Http/Controllers/UserNavigation.php b/app/Support/Http/Controllers/UserNavigation.php index 328501a1e1..84cf46b458 100644 --- a/app/Support/Http/Controllers/UserNavigation.php +++ b/app/Support/Http/Controllers/UserNavigation.php @@ -46,14 +46,14 @@ trait UserNavigation * will be returned. * - If the remembered url contains "jscript/" the remembered url will not be returned but instead the index (/) will be returned. * - * @param string $identifier + * @param string $identifier * * @return string */ final protected function getPreviousUrl(string $identifier): string { Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier)); - $url = (string) session($identifier); + $url = (string)session($identifier); Log::debug(sprintf('The URL is %s', $url)); return app('steam')->getSafeUrl($url, route('index')); @@ -62,7 +62,7 @@ trait UserNavigation /** * Will return false if you cant edit this account type. * - * @param Account $account + * @param Account $account * * @return bool */ @@ -75,7 +75,7 @@ trait UserNavigation } /** - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return bool */ @@ -93,7 +93,7 @@ trait UserNavigation } /** - * @param Account $account + * @param Account $account * * @return RedirectResponse|Redirector */ @@ -128,7 +128,7 @@ trait UserNavigation } /** - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return RedirectResponse|Redirector */ @@ -156,7 +156,7 @@ trait UserNavigation } /** - * @param string $identifier + * @param string $identifier * * @return string|null */ diff --git a/app/Support/Logging/AuditLogger.php b/app/Support/Logging/AuditLogger.php index 73a805ace2..d08542122d 100644 --- a/app/Support/Logging/AuditLogger.php +++ b/app/Support/Logging/AuditLogger.php @@ -38,7 +38,7 @@ class AuditLogger /** * Customize the given logger instance. * - * @param Logger $logger + * @param Logger $logger * * @return void */ diff --git a/app/Support/Logging/AuditProcessor.php b/app/Support/Logging/AuditProcessor.php index a233be4118..acc4cc1e33 100644 --- a/app/Support/Logging/AuditProcessor.php +++ b/app/Support/Logging/AuditProcessor.php @@ -32,7 +32,7 @@ namespace FireflyIII\Support\Logging; class AuditProcessor { /** - * @param array $record + * @param array $record * * @return array */ diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 900c9c9767..26ac764273 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -1,4 +1,5 @@ preferredCarbonFormat($start, $end); - $displayFormat = (string) trans('config.month_and_day_js', [], $locale); + $displayFormat = (string)trans('config.month_and_day_js', [], $locale); // increment by month (for year) if ($start->diffInMonths($end) > 1) { $increment = 'addMonth'; - $displayFormat = (string) trans('config.month_js'); + $displayFormat = (string)trans('config.month_js'); } // increment by year (for multi year) if ($start->diffInMonths($end) > 12) { $increment = 'addYear'; - $displayFormat = (string) trans('config.year_js'); + $displayFormat = (string)trans('config.year_js'); } $begin = clone $start; $entries = []; @@ -368,8 +369,8 @@ class Navigation * If the date difference between start and end is less than a month, method returns "Y-m-d". If the difference is less than a year, * method returns "Y-m". If the date difference is larger, method returns "Y". * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -388,8 +389,8 @@ class Navigation } /** - * @param Carbon $theDate - * @param string $repeatFrequency + * @param Carbon $theDate + * @param string $repeatFrequency * * @return string */ @@ -397,23 +398,23 @@ class Navigation { $date = clone $theDate; $formatMap = [ - '1D' => (string) trans('config.specific_day_js'), - 'daily' => (string) trans('config.specific_day_js'), - 'custom' => (string) trans('config.specific_day_js'), - '1W' => (string) trans('config.week_in_year_js'), - 'week' => (string) trans('config.week_in_year_js'), - 'weekly' => (string) trans('config.week_in_year_js'), - '1M' => (string) trans('config.month_js'), - 'month' => (string) trans('config.month_js'), - 'monthly' => (string) trans('config.month_js'), - '1Y' => (string) trans('config.year_js'), - 'year' => (string) trans('config.year_js'), - 'yearly' => (string) trans('config.year_js'), - '6M' => (string) trans('config.half_year_js'), + '1D' => (string)trans('config.specific_day_js'), + 'daily' => (string)trans('config.specific_day_js'), + 'custom' => (string)trans('config.specific_day_js'), + '1W' => (string)trans('config.week_in_year_js'), + 'week' => (string)trans('config.week_in_year_js'), + 'weekly' => (string)trans('config.week_in_year_js'), + '1M' => (string)trans('config.month_js'), + 'month' => (string)trans('config.month_js'), + 'monthly' => (string)trans('config.month_js'), + '1Y' => (string)trans('config.year_js'), + 'year' => (string)trans('config.year_js'), + 'yearly' => (string)trans('config.year_js'), + '6M' => (string)trans('config.half_year_js'), ]; if (array_key_exists($repeatFrequency, $formatMap)) { - return $date->isoFormat((string) $formatMap[$repeatFrequency]); + return $date->isoFormat((string)$formatMap[$repeatFrequency]); } if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) { $quarter = ceil($theDate->month / 3); @@ -431,8 +432,8 @@ class Navigation * If the date difference between start and end is less than a month, method returns trans(config.month_and_day). If the difference is less than a year, * method returns "config.month". If the date difference is larger, method returns "config.year". * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string * @throws FireflyException @@ -440,13 +441,13 @@ class Navigation public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string { $locale = app('steam')->getLocale(); - $format = (string) trans('config.month_and_day_js', [], $locale); + $format = (string)trans('config.month_and_day_js', [], $locale); if ($start->diffInMonths($end) > 1) { - $format = (string) trans('config.month_js', [], $locale); + $format = (string)trans('config.month_js', [], $locale); } if ($start->diffInMonths($end) > 12) { - $format = (string) trans('config.year_js', [], $locale); + $format = (string)trans('config.year_js', [], $locale); } return $format; @@ -456,8 +457,8 @@ class Navigation * If the date difference between start and end is less than a month, method returns "endOfDay". If the difference is less than a year, * method returns "endOfMonth". If the date difference is larger, method returns "endOfYear". * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -479,8 +480,8 @@ class Navigation * If the date difference between start and end is less than a month, method returns "1D". If the difference is less than a year, * method returns "1M". If the date difference is larger, method returns "1Y". * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -502,8 +503,8 @@ class Navigation * If the date difference between start and end is less than a month, method returns "%Y-%m-%d". If the difference is less than a year, * method returns "%Y-%m". If the date difference is larger, method returns "%Y". * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return string */ @@ -522,9 +523,9 @@ class Navigation } /** - * @param Carbon $theDate - * @param string $repeatFreq - * @param int|null $subtract + * @param Carbon $theDate + * @param string $repeatFreq + * @param int|null $subtract * * @return Carbon * @@ -611,8 +612,8 @@ class Navigation } /** - * @param string $range - * @param Carbon $start + * @param string $range + * @param Carbon $start * * @return Carbon * @@ -670,8 +671,8 @@ class Navigation } /** - * @param string $range - * @param Carbon $start + * @param string $range + * @param Carbon $start * * @return Carbon * diff --git a/app/Support/NullArrayObject.php b/app/Support/NullArrayObject.php index 60d20319db..061bceba6b 100644 --- a/app/Support/NullArrayObject.php +++ b/app/Support/NullArrayObject.php @@ -37,8 +37,8 @@ class NullArrayObject extends ArrayObject /** * NullArrayObject constructor. * - * @param array $array - * @param null $default + * @param array $array + * @param null $default */ public function __construct(array $array, $default = null) { @@ -47,7 +47,7 @@ class NullArrayObject extends ArrayObject } /** - * @param mixed $key + * @param mixed $key * * @return mixed|null */ diff --git a/app/Support/ParseDateString.php b/app/Support/ParseDateString.php index fe2ef36bcb..2b6255c7fc 100644 --- a/app/Support/ParseDateString.php +++ b/app/Support/ParseDateString.php @@ -49,7 +49,7 @@ class ParseDateString ]; /** - * @param string $date + * @param string $date * * @return bool */ @@ -73,7 +73,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return Carbon * @throws FireflyException @@ -114,7 +114,7 @@ class ParseDateString return new Carbon('1984-09-17'); } // maybe a year, nothing else? - if (4 === strlen($date) && is_numeric($date) && (int) $date > 1000 && (int) $date <= 3000) { + if (4 === strlen($date) && is_numeric($date) && (int)$date > 1000 && (int)$date <= 3000) { return new Carbon(sprintf('%d-01-01', $date)); } @@ -122,7 +122,7 @@ class ParseDateString } /** - * @param string $keyword + * @param string $keyword * * @return Carbon */ @@ -146,7 +146,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return Carbon */ @@ -156,7 +156,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return Carbon */ @@ -172,7 +172,8 @@ class ParseDateString 'm' => 'subMonths', 'q' => 'subQuarters', 'y' => 'subYears', - ], [ + ], + [ 'd' => 'addDays', 'w' => 'addWeeks', 'm' => 'addMonths', @@ -194,7 +195,7 @@ class ParseDateString } $direction = str_starts_with($part, '+') ? 1 : 0; $period = $part[strlen($part) - 1]; - $number = (int) substr($part, 1, -1); + $number = (int)substr($part, 1, -1); if (!array_key_exists($period, $functions[$direction])) { Log::error(sprintf('No method for direction %d and period "%s".', $direction, $period)); continue; @@ -209,7 +210,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return array */ @@ -246,7 +247,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -267,7 +268,7 @@ class ParseDateString /** * format of string is xxxx-xx-DD * - * @param string $date + * @param string $date * * @return array */ @@ -281,7 +282,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -302,7 +303,7 @@ class ParseDateString /** * format of string is xxxx-MM-xx * - * @param string $date + * @param string $date * * @return array */ @@ -317,7 +318,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -338,7 +339,7 @@ class ParseDateString /** * format of string is YYYY-xx-xx * - * @param string $date + * @param string $date * * @return array */ @@ -353,7 +354,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -374,7 +375,7 @@ class ParseDateString /** * format of string is xxxx-MM-DD * - * @param string $date + * @param string $date * * @return array */ @@ -390,7 +391,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -411,7 +412,7 @@ class ParseDateString /** * format of string is YYYY-xx-DD * - * @param string $date + * @param string $date * * @return array */ @@ -427,7 +428,7 @@ class ParseDateString } /** - * @param string $date + * @param string $date * * @return bool */ @@ -448,7 +449,7 @@ class ParseDateString /** * format of string is YYYY-MM-xx * - * @param string $date + * @param string $date * * @return array */ diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 336a547791..78c7dfedfd 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -1,4 +1,5 @@ id)->where('name', 'LIKE', $search . '%')->get(); - } - - /** - * @param string $name - * - * @return bool - * @throws FireflyException - */ - public function delete(string $name): bool - { - $fullName = sprintf('preference%s%s', auth()->user()->id, $name); - if (Cache::has($fullName)) { - Cache::forget($fullName); - } - try { - Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); - } catch (Exception $e) { - throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); - } - - return true; - } - - /** - * @param string $name - * - * @return Collection - */ - public function findByName(string $name): Collection - { - return Preference::where('name', $name)->get(); - } - - /** - * @param User $user - * @param string $name - */ - public function forget(User $user, string $name): void - { - $key = sprintf('preference%s%s', $user->id, $name); - Cache::forget($key); - Cache::put($key, '', 5); - } - - /** - * @param User $user - * @param array $list - * - * @return array - */ - public function getArrayForUser(User $user, array $list): array - { - $result = []; - $preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']); - /** @var Preference $preference */ - foreach ($preferences as $preference) { - $result[$preference->name] = $preference->data; - } - foreach ($list as $name) { - if (!array_key_exists($name, $result)) { - $result[$name] = null; - } - } - - return $result; - } - - /** - * @param string $name - * @param mixed $default + * @param string $name + * @param mixed $default * * @return Preference|null * @throws FireflyException */ - public function getFresh(string $name, $default = null): ?Preference + public function get(string $name, $default = null): ?Preference { /** @var User|null $user */ $user = auth()->user(); @@ -145,27 +70,13 @@ class Preferences return $preference; } - return $this->getFreshForUser($user, $name, $default); - } - - /** - * @param User $user - * @param string $name - * @param null $default - * - * @return Preference|null - * TODO remove me. - * @throws FireflyException - */ - public function getFreshForUser(User $user, string $name, $default = null): ?Preference - { return $this->getForUser($user, $name, $default); } /** - * @param User $user - * @param string $name - * @param null|string|int $default + * @param User $user + * @param string $name + * @param null|string|int $default * * @return Preference|null * @throws FireflyException @@ -195,9 +106,41 @@ class Preferences } /** - * @param User $user - * @param string $name - * @param mixed $value + * @param string $name + * + * @return bool + * @throws FireflyException + */ + public function delete(string $name): bool + { + $fullName = sprintf('preference%s%s', auth()->user()->id, $name); + if (Cache::has($fullName)) { + Cache::forget($fullName); + } + try { + Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); + } catch (Exception $e) { + throw new FireflyException(sprintf('Could not delete preference: %s', $e->getMessage()), 0, $e); + } + + return true; + } + + /** + * @param User $user + * @param string $name + */ + public function forget(User $user, string $name): void + { + $key = sprintf('preference%s%s', $user->id, $name); + Cache::forget($key); + Cache::put($key, '', 5); + } + + /** + * @param User $user + * @param string $name + * @param mixed $value * * @return Preference * @throws FireflyException @@ -237,6 +180,85 @@ class Preferences return $pref; } + /** + * @param User $user + * @param string $search + * + * @return Collection + */ + public function beginsWith(User $user, string $search): Collection + { + return Preference::where('user_id', $user->id)->where('name', 'LIKE', $search.'%')->get(); + } + + /** + * @param string $name + * + * @return Collection + */ + public function findByName(string $name): Collection + { + return Preference::where('name', $name)->get(); + } + + /** + * @param User $user + * @param array $list + * + * @return array + */ + public function getArrayForUser(User $user, array $list): array + { + $result = []; + $preferences = Preference::where('user_id', $user->id)->whereIn('name', $list)->get(['id', 'name', 'data']); + /** @var Preference $preference */ + foreach ($preferences as $preference) { + $result[$preference->name] = $preference->data; + } + foreach ($list as $name) { + if (!array_key_exists($name, $result)) { + $result[$name] = null; + } + } + + return $result; + } + + /** + * @param string $name + * @param mixed $default + * + * @return Preference|null + * @throws FireflyException + */ + public function getFresh(string $name, $default = null): ?Preference + { + /** @var User|null $user */ + $user = auth()->user(); + if (null === $user) { + $preference = new Preference(); + $preference->data = $default; + + return $preference; + } + + return $this->getFreshForUser($user, $name, $default); + } + + /** + * @param User $user + * @param string $name + * @param null $default + * + * @return Preference|null + * TODO remove me. + * @throws FireflyException + */ + public function getFreshForUser(User $user, string $name, $default = null): ?Preference + { + return $this->getForUser($user, $name, $default); + } + /** * @return string * @throws FireflyException @@ -256,27 +278,6 @@ class Preferences return hash('sha256', $lastActivity); } - /** - * @param string $name - * @param mixed $default - * - * @return Preference|null - * @throws FireflyException - */ - public function get(string $name, $default = null): ?Preference - { - /** @var User|null $user */ - $user = auth()->user(); - if (null === $user) { - $preference = new Preference(); - $preference->data = $default; - - return $preference; - } - - return $this->getForUser($user, $name, $default); - } - /** * */ @@ -287,8 +288,8 @@ class Preferences } /** - * @param string $name - * @param mixed $value + * @param string $name + * @param mixed $value * * @return Preference * @throws FireflyException diff --git a/app/Support/Report/Budget/BudgetReportGenerator.php b/app/Support/Report/Budget/BudgetReportGenerator.php index bc40dab0d4..8c79b5faa8 100644 --- a/app/Support/Report/Budget/BudgetReportGenerator.php +++ b/app/Support/Report/Budget/BudgetReportGenerator.php @@ -1,4 +1,5 @@ accounts as $account) { $accountId = $account->id; $this->report[$accountId] = $this->report[$accountId] ?? [ - 'name' => $account->name, - 'id' => $account->id, - 'iban' => $account->iban, - 'currencies' => [], - ]; + 'name' => $account->name, + 'id' => $account->id, + 'iban' => $account->iban, + 'currencies' => [], + ]; } // loop expenses. @@ -91,7 +94,7 @@ class BudgetReportGenerator /** * Process each row of expenses collected for the "Account per budget" partial * - * @param array $expenses + * @param array $expenses */ private function processExpenses(array $expenses): void { @@ -103,24 +106,24 @@ class BudgetReportGenerator /** * Process each set of transactions for each row of expenses. * - * @param array $expenses - * @param array $budget + * @param array $expenses + * @param array $budget */ private function processBudgetExpenses(array $expenses, array $budget): void { - $budgetId = (int) $budget['id']; - $currencyId = (int) $expenses['currency_id']; + $budgetId = (int)$budget['id']; + $currencyId = (int)$expenses['currency_id']; foreach ($budget['transaction_journals'] as $journal) { $sourceAccountId = $journal['source_account_id']; $this->report[$sourceAccountId]['currencies'][$currencyId] = $this->report[$sourceAccountId]['currencies'][$currencyId] ?? [ - 'currency_id' => $expenses['currency_id'], - 'currency_symbol' => $expenses['currency_symbol'], - 'currency_name' => $expenses['currency_name'], - 'currency_decimal_places' => $expenses['currency_decimal_places'], - 'budgets' => [], - ]; + 'currency_id' => $expenses['currency_id'], + 'currency_symbol' => $expenses['currency_symbol'], + 'currency_name' => $expenses['currency_name'], + 'currency_decimal_places' => $expenses['currency_decimal_places'], + 'budgets' => [], + ]; $this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId] = $this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId] ?? '0'; @@ -161,17 +164,17 @@ class BudgetReportGenerator /** * Process expenses etc. for a single budget for the budgets block on the default report. * - * @param Budget $budget + * @param Budget $budget */ private function processBudget(Budget $budget): void { - $budgetId = (int) $budget->id; + $budgetId = (int)$budget->id; $this->report['budgets'][$budgetId] = $this->report['budgets'][$budgetId] ?? [ - 'budget_id' => $budgetId, - 'budget_name' => $budget->name, - 'no_budget' => false, - 'budget_limits' => [], - ]; + 'budget_id' => $budgetId, + 'budget_name' => $budget->name, + 'no_budget' => false, + 'budget_limits' => [], + ]; // get all budget limits for budget in period: $limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end); @@ -184,50 +187,50 @@ class BudgetReportGenerator /** * Process a single budget limit for the budgets block on the default report. * - * @param Budget $budget - * @param BudgetLimit $limit + * @param Budget $budget + * @param BudgetLimit $limit */ private function processLimit(Budget $budget, BudgetLimit $limit): void { - $budgetId = (int) $budget->id; - $limitId = (int) $limit->id; + $budgetId = (int)$budget->id; + $limitId = (int)$limit->id; $limitCurrency = $limit->transactionCurrency ?? $this->currency; - $currencyId = (int) $limitCurrency->id; + $currencyId = (int)$limitCurrency->id; $expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget])); $spent = $expenses[$currencyId]['sum'] ?? '0'; $left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent); $overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0'; $this->report['budgets'][$budgetId]['budget_limits'][$limitId] = $this->report['budgets'][$budgetId]['budget_limits'][$limitId] ?? [ - 'budget_limit_id' => $limitId, - 'start_date' => $limit->start_date, - 'end_date' => $limit->end_date, - 'budgeted' => $limit->amount, - 'budgeted_pct' => '0', - 'spent' => $spent, - 'spent_pct' => '0', - 'left' => $left, - 'overspent' => $overspent, - 'currency_id' => $currencyId, - 'currency_code' => $limitCurrency->code, - 'currency_name' => $limitCurrency->name, - 'currency_symbol' => $limitCurrency->symbol, - 'currency_decimal_places' => $limitCurrency->decimal_places, - ]; + 'budget_limit_id' => $limitId, + 'start_date' => $limit->start_date, + 'end_date' => $limit->end_date, + 'budgeted' => $limit->amount, + 'budgeted_pct' => '0', + 'spent' => $spent, + 'spent_pct' => '0', + 'left' => $left, + 'overspent' => $overspent, + 'currency_id' => $currencyId, + 'currency_code' => $limitCurrency->code, + 'currency_name' => $limitCurrency->name, + 'currency_symbol' => $limitCurrency->symbol, + 'currency_decimal_places' => $limitCurrency->decimal_places, + ]; // make sum information: $this->report['sums'][$currencyId] = $this->report['sums'][$currencyId] ?? [ - 'budgeted' => '0', - 'spent' => '0', - 'left' => '0', - 'overspent' => '0', - 'currency_id' => $currencyId, - 'currency_code' => $limitCurrency->code, - 'currency_name' => $limitCurrency->name, - 'currency_symbol' => $limitCurrency->symbol, - 'currency_decimal_places' => $limitCurrency->decimal_places, - ]; + 'budgeted' => '0', + 'spent' => '0', + 'left' => '0', + 'overspent' => '0', + 'currency_id' => $currencyId, + 'currency_code' => $limitCurrency->code, + 'currency_name' => $limitCurrency->name, + 'currency_symbol' => $limitCurrency->symbol, + 'currency_decimal_places' => $limitCurrency->decimal_places, + ]; $this->report['sums'][$currencyId]['budgeted'] = bcadd($this->report['sums'][$currencyId]['budgeted'], $limit->amount); $this->report['sums'][$currencyId]['spent'] = bcadd($this->report['sums'][$currencyId]['spent'], $spent); $this->report['sums'][$currencyId]['left'] = bcadd($this->report['sums'][$currencyId]['left'], bcadd($limit->amount, $spent)); @@ -250,7 +253,7 @@ class BudgetReportGenerator $noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts); foreach ($noBudget as $noBudgetEntry) { // currency information: - $nbCurrencyId = (int) ($noBudgetEntry['currency_id'] ?? $this->currency->id); + $nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id); $nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code; $nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name; $nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol; @@ -295,9 +298,9 @@ class BudgetReportGenerator // make percentages based on total amount. foreach ($this->report['budgets'] as $budgetId => $data) { foreach ($data['budget_limits'] as $limitId => $entry) { - $budgetId = (int) $budgetId; - $limitId = (int) $limitId; - $currencyId = (int) $entry['currency_id']; + $budgetId = (int)$budgetId; + $limitId = (int)$limitId; + $currencyId = (int)$entry['currency_id']; $spent = $entry['spent']; $totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0'; $spentPct = '0'; @@ -306,10 +309,10 @@ class BudgetReportGenerator $budgetedPct = '0'; if (0 !== bccomp($spent, '0') && 0 !== bccomp($totalSpent, '0')) { - $spentPct = round((float) bcmul(bcdiv($spent, $totalSpent), '100')); + $spentPct = round((float)bcmul(bcdiv($spent, $totalSpent), '100')); } if (0 !== bccomp($budgeted, '0') && 0 !== bccomp($totalBudgeted, '0')) { - $budgetedPct = round((float) bcmul(bcdiv($budgeted, $totalBudgeted), '100')); + $budgetedPct = round((float)bcmul(bcdiv($budgeted, $totalBudgeted), '100')); } $this->report['sums'][$currencyId]['budgeted'] = $this->report['sums'][$currencyId]['budgeted'] ?? '0'; $this->report['budgets'][$budgetId]['budget_limits'][$limitId]['spent_pct'] = $spentPct; @@ -327,7 +330,7 @@ class BudgetReportGenerator } /** - * @param Collection $accounts + * @param Collection $accounts */ public function setAccounts(Collection $accounts): void { @@ -335,7 +338,7 @@ class BudgetReportGenerator } /** - * @param Collection $budgets + * @param Collection $budgets */ public function setBudgets(Collection $budgets): void { @@ -343,7 +346,7 @@ class BudgetReportGenerator } /** - * @param Carbon $end + * @param Carbon $end */ public function setEnd(Carbon $end): void { @@ -351,7 +354,7 @@ class BudgetReportGenerator } /** - * @param Carbon $start + * @param Carbon $start */ public function setStart(Carbon $start): void { @@ -359,9 +362,9 @@ class BudgetReportGenerator } /** - * @param User $user - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @param User $user + * @throws FireflyException + * @throws JsonException */ public function setUser(User $user): void { diff --git a/app/Support/Report/Category/CategoryReportGenerator.php b/app/Support/Report/Category/CategoryReportGenerator.php index 564a160935..93097dd029 100644 --- a/app/Support/Report/Category/CategoryReportGenerator.php +++ b/app/Support/Report/Category/CategoryReportGenerator.php @@ -88,12 +88,12 @@ class CategoryReportGenerator /** * Process one of the spent arrays from the operations method. * - * @param array $data + * @param array $data */ private function processOpsArray(array $data): void { /** - * @var int $currencyId + * @var int $currencyId * @var array $currencyRow */ foreach ($data as $currencyId => $currencyRow) { @@ -102,24 +102,24 @@ class CategoryReportGenerator } /** - * @param int $currencyId - * @param array $currencyRow + * @param int $currencyId + * @param array $currencyRow */ private function processCurrencyArray(int $currencyId, array $currencyRow): void { $this->report['sums'][$currencyId] = $this->report['sums'][$currencyId] ?? [ - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - 'currency_id' => $currencyRow['currency_id'], - 'currency_symbol' => $currencyRow['currency_symbol'], - 'currency_name' => $currencyRow['currency_name'], - 'currency_code' => $currencyRow['currency_code'], - 'currency_decimal_places' => $currencyRow['currency_decimal_places'], - ]; + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + 'currency_id' => $currencyRow['currency_id'], + 'currency_symbol' => $currencyRow['currency_symbol'], + 'currency_name' => $currencyRow['currency_name'], + 'currency_code' => $currencyRow['currency_code'], + 'currency_decimal_places' => $currencyRow['currency_decimal_places'], + ]; /** - * @var int $categoryId + * @var int $categoryId * @var array $categoryRow */ foreach ($currencyRow['categories'] as $categoryId => $categoryRow) { @@ -128,26 +128,26 @@ class CategoryReportGenerator } /** - * @param int $currencyId - * @param array $currencyRow - * @param int $categoryId - * @param array $categoryRow + * @param int $currencyId + * @param array $currencyRow + * @param int $categoryId + * @param array $categoryRow */ private function processCategoryRow(int $currencyId, array $currencyRow, int $categoryId, array $categoryRow): void { $key = sprintf('%s-%s', $currencyId, $categoryId); $this->report['categories'][$key] = $this->report['categories'][$key] ?? [ - 'id' => $categoryId, - 'title' => $categoryRow['name'], - 'currency_id' => $currencyRow['currency_id'], - 'currency_symbol' => $currencyRow['currency_symbol'], - 'currency_name' => $currencyRow['currency_name'], - 'currency_code' => $currencyRow['currency_code'], - 'currency_decimal_places' => $currencyRow['currency_decimal_places'], - 'spent' => '0', - 'earned' => '0', - 'sum' => '0', - ]; + 'id' => $categoryId, + 'title' => $categoryRow['name'], + 'currency_id' => $currencyRow['currency_id'], + 'currency_symbol' => $currencyRow['currency_symbol'], + 'currency_name' => $currencyRow['currency_name'], + 'currency_code' => $currencyRow['currency_code'], + 'currency_decimal_places' => $currencyRow['currency_decimal_places'], + 'spent' => '0', + 'earned' => '0', + 'sum' => '0', + ]; // loop journals: foreach ($categoryRow['transaction_journals'] as $journal) { // sum of sums @@ -179,7 +179,7 @@ class CategoryReportGenerator } /** - * @param Collection $accounts + * @param Collection $accounts */ public function setAccounts(Collection $accounts): void { @@ -187,7 +187,7 @@ class CategoryReportGenerator } /** - * @param Carbon $end + * @param Carbon $end */ public function setEnd(Carbon $end): void { @@ -195,7 +195,7 @@ class CategoryReportGenerator } /** - * @param Carbon $start + * @param Carbon $start */ public function setStart(Carbon $start): void { @@ -203,7 +203,7 @@ class CategoryReportGenerator } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { diff --git a/app/Support/Repositories/Recurring/CalculateRangeOccurrences.php b/app/Support/Repositories/Recurring/CalculateRangeOccurrences.php index 680f1af0d3..cccdb12026 100644 --- a/app/Support/Repositories/Recurring/CalculateRangeOccurrences.php +++ b/app/Support/Repositories/Recurring/CalculateRangeOccurrences.php @@ -35,9 +35,9 @@ trait CalculateRangeOccurrences /** * Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences. * - * @param Carbon $start - * @param Carbon $end - * @param int $skipMod + * @param Carbon $start + * @param Carbon $end + * @param int $skipMod * * @return array */ @@ -59,10 +59,10 @@ trait CalculateRangeOccurrences /** * Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences. * - * @param Carbon $start - * @param Carbon $end - * @param int $skipMod - * @param string $moment + * @param Carbon $start + * @param Carbon $end + * @param int $skipMod + * @param string $moment * * @return array * @@ -71,7 +71,7 @@ trait CalculateRangeOccurrences { $return = []; $attempts = 0; - $dayOfMonth = (int) $moment; + $dayOfMonth = (int)$moment; if ($start->day > $dayOfMonth) { // day has passed already, add a month. $start->addMonth(); @@ -92,10 +92,10 @@ trait CalculateRangeOccurrences /** * Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences. * - * @param Carbon $start - * @param Carbon $end - * @param int $skipMod - * @param string $moment + * @param Carbon $start + * @param Carbon $end + * @param int $skipMod + * @param string $moment * * @return array */ @@ -124,10 +124,10 @@ trait CalculateRangeOccurrences /** * Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences. * - * @param Carbon $start - * @param Carbon $end - * @param int $skipMod - * @param string $moment + * @param Carbon $start + * @param Carbon $end + * @param int $skipMod + * @param string $moment * * @return array * @@ -139,7 +139,7 @@ trait CalculateRangeOccurrences Log::debug('Rep is weekly.'); // monday = 1 // sunday = 7 - $dayOfWeek = (int) $moment; + $dayOfWeek = (int)$moment; Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso)); if ($start->dayOfWeekIso > $dayOfWeek) { // day has already passed this week, add one week: @@ -168,10 +168,10 @@ trait CalculateRangeOccurrences /** * Get the number of daily occurrences for a recurring transaction until date $end is reached. Will skip every $skipMod-1 occurrences. * - * @param Carbon $start - * @param Carbon $end - * @param int $skipMod - * @param string $moment + * @param Carbon $start + * @param Carbon $end + * @param int $skipMod + * @param string $moment * * @return array * diff --git a/app/Support/Repositories/Recurring/CalculateXOccurrences.php b/app/Support/Repositories/Recurring/CalculateXOccurrences.php index 4cd955fbd3..59e7ea2861 100644 --- a/app/Support/Repositories/Recurring/CalculateXOccurrences.php +++ b/app/Support/Repositories/Recurring/CalculateXOccurrences.php @@ -35,9 +35,9 @@ trait CalculateXOccurrences * Calculates the number of daily occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param int $count - * @param int $skipMod + * @param Carbon $date + * @param int $count + * @param int $skipMod * * @return array */ @@ -63,10 +63,10 @@ trait CalculateXOccurrences * Calculates the number of monthly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -76,7 +76,7 @@ trait CalculateXOccurrences $mutator = clone $date; $total = 0; $attempts = 0; - $dayOfMonth = (int) $moment; + $dayOfMonth = (int)$moment; if ($mutator->day > $dayOfMonth) { // day has passed already, add a month. $mutator->addMonth(); @@ -100,10 +100,10 @@ trait CalculateXOccurrences * Calculates the number of NDOM occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -138,10 +138,10 @@ trait CalculateXOccurrences * Calculates the number of weekly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -154,7 +154,7 @@ trait CalculateXOccurrences // monday = 1 // sunday = 7 $mutator->addDay(); // always assume today has passed. - $dayOfWeek = (int) $moment; + $dayOfWeek = (int)$moment; if ($mutator->dayOfWeekIso > $dayOfWeek) { // day has already passed this week, add one week: $mutator->addWeek(); @@ -180,10 +180,10 @@ trait CalculateXOccurrences * Calculates the number of yearly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ diff --git a/app/Support/Repositories/Recurring/CalculateXOccurrencesSince.php b/app/Support/Repositories/Recurring/CalculateXOccurrencesSince.php index 5a12ce7a0f..c9b505c25a 100644 --- a/app/Support/Repositories/Recurring/CalculateXOccurrencesSince.php +++ b/app/Support/Repositories/Recurring/CalculateXOccurrencesSince.php @@ -36,10 +36,10 @@ trait CalculateXOccurrencesSince * Calculates the number of daily occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param Carbon $afterDate - * @param int $count - * @param int $skipMod + * @param Carbon $date + * @param Carbon $afterDate + * @param int $count + * @param int $skipMod * * @return array */ @@ -66,11 +66,11 @@ trait CalculateXOccurrencesSince * Calculates the number of monthly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param Carbon $afterDate - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param Carbon $afterDate + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -81,7 +81,7 @@ trait CalculateXOccurrencesSince $mutator = clone $date; $total = 0; $attempts = 0; - $dayOfMonth = (int) $moment; + $dayOfMonth = (int)$moment; $dayOfMonth = 0 === $dayOfMonth ? 1 : $dayOfMonth; if ($mutator->day > $dayOfMonth) { Log::debug(sprintf('%d is after %d, add a month. Mutator is now', $mutator->day, $dayOfMonth)); @@ -109,11 +109,11 @@ trait CalculateXOccurrencesSince * Calculates the number of NDOM occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param Carbon $afterDate - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param Carbon $afterDate + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -149,11 +149,11 @@ trait CalculateXOccurrencesSince * Calculates the number of weekly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param Carbon $afterDate - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param Carbon $afterDate + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ @@ -168,7 +168,7 @@ trait CalculateXOccurrencesSince // sunday = 7 // Removed assumption today has passed, see issue https://github.com/firefly-iii/firefly-iii/issues/4798 //$mutator->addDay(); // always assume today has passed. - $dayOfWeek = (int) $moment; + $dayOfWeek = (int)$moment; if ($mutator->dayOfWeekIso > $dayOfWeek) { // day has already passed this week, add one week: $mutator->addWeek(); @@ -194,11 +194,11 @@ trait CalculateXOccurrencesSince * Calculates the number of yearly occurrences for a recurring transaction, starting at the date, until $count is reached. It will skip * over $skipMod -1 recurrences. * - * @param Carbon $date - * @param Carbon $afterDate - * @param int $count - * @param int $skipMod - * @param string $moment + * @param Carbon $date + * @param Carbon $afterDate + * @param int $count + * @param int $skipMod + * @param string $moment * * @return array */ diff --git a/app/Support/Repositories/Recurring/FiltersWeekends.php b/app/Support/Repositories/Recurring/FiltersWeekends.php index 8d2f04fa78..a86be7a4fc 100644 --- a/app/Support/Repositories/Recurring/FiltersWeekends.php +++ b/app/Support/Repositories/Recurring/FiltersWeekends.php @@ -37,8 +37,8 @@ trait FiltersWeekends /** * Filters out all weekend entries, if necessary. * - * @param RecurrenceRepetition $repetition - * @param array $dates + * @param RecurrenceRepetition $repetition + * @param array $dates * * @return array * @@ -46,7 +46,7 @@ trait FiltersWeekends protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array { Log::debug(sprintf('Now in %s', __METHOD__)); - if ((int) $repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) { + if ((int)$repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) { Log::debug('Repetition will not be filtered on weekend days.'); return $dates; diff --git a/app/Support/Request/AppendsLocationData.php b/app/Support/Request/AppendsLocationData.php index 77a3e8e081..0bd76b8143 100644 --- a/app/Support/Request/AppendsLocationData.php +++ b/app/Support/Request/AppendsLocationData.php @@ -42,9 +42,9 @@ trait AppendsLocationData /** * Read the submitted Request data and add new or updated Location data to the array. * - * @param array $data + * @param array $data * - * @param string|null $prefix + * @param string|null $prefix * * @return array */ @@ -100,8 +100,8 @@ trait AppendsLocationData } /** - * @param string|null $prefix - * @param string $key + * @param string|null $prefix + * @param string $key * * @return string */ @@ -115,7 +115,7 @@ trait AppendsLocationData } /** - * @param string|null $prefix + * @param string|null $prefix * * @return bool */ @@ -167,7 +167,7 @@ trait AppendsLocationData /** * Abstract method. * - * @param mixed ...$patterns + * @param mixed ...$patterns * * @return mixed */ @@ -176,15 +176,15 @@ trait AppendsLocationData /** * Abstract method stolen from "InteractsWithInput". * - * @param null $key - * @param bool $default + * @param null $key + * @param bool $default * * @return mixed */ abstract public function boolean($key = null, $default = false); /** - * @param string|null $prefix + * @param string|null $prefix * * @return bool */ @@ -229,7 +229,7 @@ trait AppendsLocationData } /** - * @param string|null $prefix + * @param string|null $prefix * * @return bool */ @@ -245,7 +245,7 @@ trait AppendsLocationData && null === $this->get($zoomLevelKey)) && ( 'PUT' === $this->method() - || ('POST' === $this->method() && $this->routeIs('*.update')) + || ('POST' === $this->method() && $this->routeIs('*.update')) ); } } diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php index f98d172c10..e91c4bbc4d 100644 --- a/app/Support/Request/ConvertsDataTypes.php +++ b/app/Support/Request/ConvertsDataTypes.php @@ -35,30 +35,30 @@ trait ConvertsDataTypes /** * Return integer value. * - * @param string $field + * @param string $field * * @return int */ public function convertInteger(string $field): int { - return (int) $this->get($field); + return (int)$this->get($field); } /** * Return string value. * - * @param string $field + * @param string $field * * @return string */ public function convertString(string $field): string { - return $this->clearString((string) ($this->get($field) ?? ''), false); + return $this->clearString((string)($this->get($field) ?? ''), false); } /** - * @param string|null $string - * @param bool $keepNewlines + * @param string|null $string + * @param bool $keepNewlines * * @return string|null */ @@ -131,17 +131,17 @@ trait ConvertsDataTypes /** * Return string value with newlines. * - * @param string $field + * @param string $field * * @return string */ public function stringWithNewlines(string $field): string { - return $this->clearString((string) ($this->get($field) ?? '')); + return $this->clearString((string)($this->get($field) ?? '')); } /** - * @param mixed $array + * @param mixed $array * * @return array|null */ @@ -161,7 +161,7 @@ trait ConvertsDataTypes } /** - * @param string|null $value + * @param string|null $value * * @return bool */ @@ -187,7 +187,24 @@ trait ConvertsDataTypes } /** - * @param string|null $string + * Return floating value. + * + * @param string $field + * + * @return float|null + */ + protected function convertFloat(string $field): ?float + { + $res = $this->get($field); + if (null === $res) { + return null; + } + + return (float)$res; + } + + /** + * @param string|null $string * * @return Carbon|null */ @@ -215,28 +232,11 @@ trait ConvertsDataTypes return $carbon; } - /** - * Return floating value. - * - * @param string $field - * - * @return float|null - */ - protected function convertFloat(string $field): ?float - { - $res = $this->get($field); - if (null === $res) { - return null; - } - - return (float) $res; - } - /** * Returns all data in the request, or omits the field if not set, * according to the config from the request. This is the way. * - * @param array $fields + * @param array $fields * * @return array */ @@ -256,7 +256,7 @@ trait ConvertsDataTypes /** * Return date or NULL. * - * @param string $field + * @param string $field * * @return Carbon|null */ @@ -278,7 +278,7 @@ trait ConvertsDataTypes /** * Parse to integer * - * @param string|null $string + * @param string|null $string * * @return int|null */ @@ -291,13 +291,13 @@ trait ConvertsDataTypes return null; } - return (int) $string; + return (int)$string; } /** * Return integer value, or NULL when it's not set. * - * @param string $field + * @param string $field * * @return int|null */ @@ -307,11 +307,11 @@ trait ConvertsDataTypes return null; } - $value = (string) $this->get($field); + $value = (string)$this->get($field); if ('' === $value) { return null; } - return (int) $value; + return (int)$value; } } diff --git a/app/Support/Request/GetRecurrenceData.php b/app/Support/Request/GetRecurrenceData.php index 3fa48d8aaa..661823ac60 100644 --- a/app/Support/Request/GetRecurrenceData.php +++ b/app/Support/Request/GetRecurrenceData.php @@ -29,7 +29,7 @@ namespace FireflyIII\Support\Request; trait GetRecurrenceData { /** - * @param array $transaction + * @param array $transaction * * @return array */ @@ -42,7 +42,7 @@ trait GetRecurrenceData $return['amount'] = $transaction['amount']; } if (array_key_exists('currency_id', $transaction)) { - $return['currency_id'] = (int) $transaction['currency_id']; + $return['currency_id'] = (int)$transaction['currency_id']; } if (array_key_exists('currency_code', $transaction)) { $return['currency_code'] = $transaction['currency_code']; @@ -53,17 +53,17 @@ trait GetRecurrenceData $return['foreign_amount'] = $transaction['foreign_amount']; } if (array_key_exists('foreign_currency_id', $transaction)) { - $return['foreign_currency_id'] = (int) $transaction['foreign_currency_id']; + $return['foreign_currency_id'] = (int)$transaction['foreign_currency_id']; } if (array_key_exists('foreign_currency_code', $transaction)) { $return['foreign_currency_code'] = $transaction['foreign_currency_code']; } // source + dest if (array_key_exists('source_id', $transaction)) { - $return['source_id'] = (int) $transaction['source_id']; + $return['source_id'] = (int)$transaction['source_id']; } if (array_key_exists('destination_id', $transaction)) { - $return['destination_id'] = (int) $transaction['destination_id']; + $return['destination_id'] = (int)$transaction['destination_id']; } // description if (array_key_exists('description', $transaction)) { @@ -71,17 +71,17 @@ trait GetRecurrenceData } if (array_key_exists('piggy_bank_id', $transaction)) { - $return['piggy_bank_id'] = (int) $transaction['piggy_bank_id']; + $return['piggy_bank_id'] = (int)$transaction['piggy_bank_id']; } if (array_key_exists('tags', $transaction)) { $return['tags'] = $transaction['tags']; } if (array_key_exists('budget_id', $transaction)) { - $return['budget_id'] = (int) $transaction['budget_id']; + $return['budget_id'] = (int)$transaction['budget_id']; } if (array_key_exists('category_id', $transaction)) { - $return['category_id'] = (int) $transaction['category_id']; + $return['category_id'] = (int)$transaction['category_id']; } return $return; diff --git a/app/Support/Search/AccountSearch.php b/app/Support/Search/AccountSearch.php index a6decf6392..1a8cd8e002 100644 --- a/app/Support/Search/AccountSearch.php +++ b/app/Support/Search/AccountSearch.php @@ -27,7 +27,6 @@ namespace FireflyIII\Support\Search; use FireflyIII\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; -use JsonException; /** * Class AccountSearch @@ -85,7 +84,7 @@ class AccountSearch implements GenericSearchInterface ); break; case self::SEARCH_ID: - $searchQuery->where('accounts.id', '=', (int) $originalQuery); + $searchQuery->where('accounts.id', '=', (int)$originalQuery); break; case self::SEARCH_NAME: $searchQuery->where('accounts.name', 'LIKE', $like); @@ -109,7 +108,7 @@ class AccountSearch implements GenericSearchInterface } /** - * @param string $field + * @param string $field */ public function setField(string $field): void { @@ -117,7 +116,7 @@ class AccountSearch implements GenericSearchInterface } /** - * @param string $query + * @param string $query */ public function setQuery(string $query): void { @@ -125,7 +124,7 @@ class AccountSearch implements GenericSearchInterface } /** - * @param array $types + * @param array $types */ public function setTypes(array $types): void { @@ -133,7 +132,7 @@ class AccountSearch implements GenericSearchInterface } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index d512848bd2..77ae90d4f8 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -74,11 +74,11 @@ class OperatorQuerySearch implements SearchInterface private int $limit; private Collection $operators; private int $page; + private array $prohibitedWords; private float $startTime; private TagRepositoryInterface $tagRepository; private array $validOperators; private array $words; - private array $prohibitedWords; /** * OperatorQuerySearch constructor. @@ -175,7 +175,7 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param Node $searchNode + * @param Node $searchNode * * @throws FireflyException */ @@ -202,7 +202,7 @@ class OperatorQuerySearch implements SearchInterface case Emoticon::class: case Emoji::class: case Mention::class: - $allWords = (string) $searchNode->getValue(); + $allWords = (string)$searchNode->getValue(); Log::debug(sprintf('Add words "%s" to search string, because Node class is "%s"', $allWords, $class)); $this->words[] = $allWords; break; @@ -223,11 +223,11 @@ class OperatorQuerySearch implements SearchInterface // must be valid operator: if ( in_array($operator, $this->validOperators, true) && - $this->updateCollector($operator, (string) $value, $prohibited)) { + $this->updateCollector($operator, (string)$value, $prohibited)) { $this->operators->push( [ 'type' => self::getRootOperator($operator), - 'value' => (string) $value, + 'value' => (string)$value, 'prohibited' => $prohibited, ] ); @@ -237,15 +237,15 @@ class OperatorQuerySearch implements SearchInterface Log::debug(sprintf('Added INVALID operator type "%s"', $operator)); $this->invalidOperators[] = [ 'type' => $operator, - 'value' => (string) $value, + 'value' => (string)$value, ]; } } } /** - * @param string $operator - * @param string $value + * @param string $operator + * @param string $value * * @return bool * @throws FireflyException @@ -371,7 +371,7 @@ class OperatorQuerySearch implements SearchInterface $this->searchAccount($value, 1, 3, true); break; case 'source_account_id': - $account = $this->accountRepository->find((int) $value); + $account = $this->accountRepository->find((int)$value); if (null !== $account) { $this->collector->setSourceAccounts(new Collection([$account])); } @@ -381,7 +381,7 @@ class OperatorQuerySearch implements SearchInterface } break; case '-source_account_id': - $account = $this->accountRepository->find((int) $value); + $account = $this->accountRepository->find((int)$value); if (null !== $account) { $this->collector->excludeSourceAccounts(new Collection([$account])); } @@ -455,7 +455,7 @@ class OperatorQuerySearch implements SearchInterface $this->searchAccount($value, 2, 3, true); break; case 'destination_account_id': - $account = $this->accountRepository->find((int) $value); + $account = $this->accountRepository->find((int)$value); if (null !== $account) { $this->collector->setDestinationAccounts(new Collection([$account])); } @@ -464,7 +464,7 @@ class OperatorQuerySearch implements SearchInterface } break; case '-destination_account_id': - $account = $this->accountRepository->find((int) $value); + $account = $this->accountRepository->find((int)$value); if (null !== $account) { $this->collector->excludeDestinationAccounts(new Collection([$account])); } @@ -476,7 +476,7 @@ class OperatorQuerySearch implements SearchInterface $parts = explode(',', $value); $collection = new Collection(); foreach ($parts as $accountId) { - $account = $this->accountRepository->find((int) $accountId); + $account = $this->accountRepository->find((int)$accountId); if (null !== $account) { $collection->push($account); } @@ -492,7 +492,7 @@ class OperatorQuerySearch implements SearchInterface $parts = explode(',', $value); $collection = new Collection(); foreach ($parts as $accountId) { - $account = $this->accountRepository->find((int) $accountId); + $account = $this->accountRepository->find((int)$accountId); if (null !== $account) { $collection->push($account); } @@ -928,7 +928,7 @@ class OperatorQuerySearch implements SearchInterface case 'amount_is': // strip comma's, make dots. Log::debug(sprintf('Original value "%s"', $value)); - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); $this->collector->amountIs($amount); @@ -936,7 +936,7 @@ class OperatorQuerySearch implements SearchInterface case '-amount_is': // strip comma's, make dots. Log::debug(sprintf('Original value "%s"', $value)); - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); $this->collector->amountIsNot($amount); @@ -944,7 +944,7 @@ class OperatorQuerySearch implements SearchInterface case 'foreign_amount_is': // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); @@ -953,7 +953,7 @@ class OperatorQuerySearch implements SearchInterface case '-foreign_amount_is': // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); @@ -962,7 +962,7 @@ class OperatorQuerySearch implements SearchInterface case '-amount_more': case 'amount_less': // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); @@ -971,7 +971,7 @@ class OperatorQuerySearch implements SearchInterface case '-foreign_amount_more': case 'foreign_amount_less': // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); @@ -981,7 +981,7 @@ class OperatorQuerySearch implements SearchInterface case 'amount_more': Log::debug(sprintf('Now handling operator "%s"', $operator)); // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); $this->collector->amountMore($amount); @@ -990,7 +990,7 @@ class OperatorQuerySearch implements SearchInterface case 'foreign_amount_more': Log::debug(sprintf('Now handling operator "%s"', $operator)); // strip comma's, make dots. - $value = str_replace(',', '.', (string) $value); + $value = str_replace(',', '.', (string)$value); $amount = app('steam')->positive($value); Log::debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount)); $this->collector->foreignAmountMore($amount); @@ -1325,7 +1325,7 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $operator + * @param string $operator * * @return string * @throws FireflyException @@ -1361,10 +1361,10 @@ class OperatorQuerySearch implements SearchInterface * searchDirection: 1 = source (default), 2 = destination, 3 = both * stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is * - * @param string $value - * @param int $searchDirection - * @param int $stringPosition - * @param bool $prohibited + * @param string $value + * @param int $searchDirection + * @param int $stringPosition + * @param bool $prohibited */ private function searchAccount(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void { @@ -1437,10 +1437,10 @@ class OperatorQuerySearch implements SearchInterface * searchDirection: 1 = source (default), 2 = destination, 3 = both * stringPosition: 1 = start (default), 2 = end, 3 = contains, 4 = is * - * @param string $value - * @param int $searchDirection - * @param int $stringPosition - * @param bool $prohibited + * @param string $value + * @param int $searchDirection + * @param int $stringPosition + * @param bool $prohibited */ private function searchAccountNr(string $value, int $searchDirection, int $stringPosition, bool $prohibited = false): void { @@ -1500,7 +1500,7 @@ class OperatorQuerySearch implements SearchInterface $filtered = $accounts->filter( function (Account $account) use ($value, $stringMethod) { // either IBAN or account number - $ibanMatch = $stringMethod(strtolower((string) $account->iban), strtolower((string) $value)); + $ibanMatch = $stringMethod(strtolower((string)$account->iban), strtolower((string)$value)); $accountNrMatch = false; /** @var AccountMeta $meta */ foreach ($account->accountMeta as $meta) { @@ -1532,7 +1532,7 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $value + * @param string $value * * @return TransactionCurrency|null */ @@ -1552,7 +1552,7 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $value + * @param string $value * * @return array * @throws FireflyException @@ -1571,14 +1571,14 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param array $range + * @param array $range * * @throws FireflyException */ private function setExactDateParams(array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1630,14 +1630,14 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param array $range + * @param array $range * * @throws FireflyException */ private function setDateBeforeParams(array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1669,14 +1669,14 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param array $range + * @param array $range * * @throws FireflyException */ private function setDateAfterParams(array $range, bool $prohibited = false) { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1708,8 +1708,8 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * @return void * @throws FireflyException */ @@ -1717,7 +1717,7 @@ class OperatorQuerySearch implements SearchInterface { Log::debug('Now in setExactMetaDateParams()'); /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1770,15 +1770,15 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * @return void * @throws FireflyException */ private function setMetaDateBeforeParams(string $field, array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1810,15 +1810,15 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * @return void * @throws FireflyException */ private function setMetaDateAfterParams(string $field, array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1850,15 +1850,15 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * @return void * @throws FireflyException */ private function setExactObjectDateParams(string $field, array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1911,15 +1911,15 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * * @throws FireflyException */ private function setObjectDateBeforeParams(string $field, array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -1951,15 +1951,15 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param string $field - * @param array $range + * @param string $field + * @param array $range * * @throws FireflyException */ private function setObjectDateAfterParams(string $field, array $range, bool $prohibited = false): void { /** - * @var string $key + * @var string $key * @var Carbon|string $value */ foreach ($range as $key => $value) { @@ -2020,7 +2020,7 @@ class OperatorQuerySearch implements SearchInterface } /** - * @param Carbon $date + * @param Carbon $date */ public function setDate(Carbon $date): void { @@ -2052,11 +2052,11 @@ class OperatorQuerySearch implements SearchInterface $this->collector->setUser($user); $this->collector->withAccountInformation()->withCategoryInformation()->withBudgetInformation(); - $this->setLimit((int) app('preferences')->getForUser($user, 'listPageSize', 50)->data); + $this->setLimit((int)app('preferences')->getForUser($user, 'listPageSize', 50)->data); } /** - * @param int $limit + * @param int $limit */ public function setLimit(int $limit): void { diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php index a50f35c833..97bca2720b 100644 --- a/app/Support/Search/SearchInterface.php +++ b/app/Support/Search/SearchInterface.php @@ -1,4 +1,5 @@ whereNull('transaction_journals.deleted_at') ->get( [ - 'transaction_journals.date', - 'transactions.transaction_currency_id', - DB::raw('SUM(transactions.amount) AS modified'), - 'transactions.foreign_currency_id', - DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), + 'transaction_journals.date', + 'transactions.transaction_currency_id', + DB::raw('SUM(transactions.amount) AS modified'), + 'transactions.foreign_currency_id', + DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), ] ); @@ -363,6 +333,38 @@ class Steam return $return; } + /** + * https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers + * + * @param null|string $number + * @param int $precision + * @return string + */ + public function bcround(?string $number, int $precision = 0): string + { + if (null === $number) { + return '0'; + } + if ('' === trim($number)) { + return '0'; + } + // if the number contains "E", it's in scientific notation, so we need to convert it to a normal number first. + if (false !== stripos($number, 'e')) { + $number = sprintf('%.24f', $number); + } + + Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision)); + if (str_contains($number, '.')) { + if ($number[0] !== '-') { + return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision); + } + + return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision); + } + + return $number; + } + /** * @param string $string * @@ -453,8 +455,8 @@ class Steam * * @return string * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function getLocale(): string // get preference { @@ -476,8 +478,8 @@ class Steam * * @return string * @throws FireflyException - * @throws \Psr\Container\ContainerExceptionInterface - * @throws \Psr\Container\NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function getLanguage(): string // get preference { diff --git a/app/Support/System/GeneratesInstallationId.php b/app/Support/System/GeneratesInstallationId.php index c40eb89c65..8ac9d8dd3e 100644 --- a/app/Support/System/GeneratesInstallationId.php +++ b/app/Support/System/GeneratesInstallationId.php @@ -53,7 +53,7 @@ trait GeneratesInstallationId if (null === $config) { $uuid4 = Uuid::uuid4(); - $uniqueId = (string) $uuid4; + $uniqueId = (string)$uuid4; Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId)); app('fireflyconfig')->set('installation_id', $uniqueId); } diff --git a/app/Support/System/OAuthKeys.php b/app/Support/System/OAuthKeys.php index 59ad7d15dc..0266cb5feb 100644 --- a/app/Support/System/OAuthKeys.php +++ b/app/Support/System/OAuthKeys.php @@ -72,8 +72,8 @@ class OAuthKeys // better check if keys are in the database: if (app('fireflyconfig')->has(self::PRIVATE_KEY) && app('fireflyconfig')->has(self::PUBLIC_KEY)) { try { - $privateKey = (string) app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; - $publicKey = (string) app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; + $privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; + $publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; } catch (ContainerExceptionInterface|NotFoundExceptionInterface|FireflyException $e) { Log::error(sprintf('Could not validate keysInDatabase(): %s', $e->getMessage())); Log::error($e->getTraceAsString()); @@ -125,8 +125,8 @@ class OAuthKeys */ public static function restoreKeysFromDB(): bool { - $privateKey = (string) app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; - $publicKey = (string) app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; + $privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; + $publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; try { $privateContent = Crypt::decrypt($privateKey); $publicContent = Crypt::decrypt($publicKey); diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php index b099496113..5ae6db2121 100644 --- a/app/Support/Twig/AmountFormat.php +++ b/app/Support/Twig/AmountFormat.php @@ -1,4 +1,5 @@ = (1024 * 1024)) { - return round($size / (1024 * 1024), 2) . ' MB'; + return round($size / (1024 * 1024), 2).' MB'; } // less than one MB if ($size < (1024 * 1024)) { - return round($size / 1024, 2) . ' KB'; + return round($size / 1024, 2).' KB'; } - return $size . ' bytes'; + return $size.' bytes'; } ); } @@ -192,7 +193,7 @@ class General extends AbstractExtension ] ); - return (string) $converter->convert($text); + return (string)$converter->convert($text); }, ['is_safe' => ['html']] ); @@ -208,8 +209,8 @@ class General extends AbstractExtension return new TwigFilter( 'phphost', static function (string $string): string { - $proto = (string) parse_url($string, PHP_URL_SCHEME); - $host = (string) parse_url($string, PHP_URL_HOST); + $proto = (string)parse_url($string, PHP_URL_SCHEME); + $host = (string)parse_url($string, PHP_URL_HOST); return e(sprintf('%s://%s', $proto, $host)); } @@ -406,7 +407,7 @@ class General extends AbstractExtension return new TwigFunction( 'getRootSearchOperator', static function (string $operator): string { - $result = OperatorQuerySearch::getRootOperator($operator); + $result = OperatorQuerySearch::getRootOperator($operator); return str_replace('-', 'not_', $result); } ); diff --git a/app/Support/Twig/Rule.php b/app/Support/Twig/Rule.php index 564547b325..924cd5157d 100644 --- a/app/Support/Twig/Rule.php +++ b/app/Support/Twig/Rule.php @@ -1,4 +1,5 @@ (string) trans('firefly.rule_trigger_store_journal'), - 'update-journal' => (string) trans('firefly.rule_trigger_update_journal'), + 'store-journal' => (string)trans('firefly.rule_trigger_store_journal'), + 'update-journal' => (string)trans('firefly.rule_trigger_update_journal'), ]; } ); @@ -71,7 +72,7 @@ class Rule extends AbstractExtension $possibleTriggers = []; foreach ($ruleTriggers as $key) { if ('user_action' !== $key) { - $possibleTriggers[$key] = (string) trans('firefly.rule_trigger_' . $key . '_choice'); + $possibleTriggers[$key] = (string)trans('firefly.rule_trigger_'.$key.'_choice'); } } unset($ruleTriggers); @@ -94,7 +95,7 @@ class Rule extends AbstractExtension $ruleActions = array_keys(Config::get('firefly.rule-actions')); $possibleActions = []; foreach ($ruleActions as $key) { - $possibleActions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice'); + $possibleActions[$key] = (string)trans('firefly.rule_action_'.$key.'_choice'); } unset($ruleActions); asort($possibleActions); diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.php index b2d64f3b7a..409f3b21d9 100644 --- a/app/Support/Twig/TransactionGroupTwig.php +++ b/app/Support/Twig/TransactionGroupTwig.php @@ -79,7 +79,7 @@ class TransactionGroupTwig extends AbstractExtension /** * Generate normal amount for transaction from a transaction group. * - * @param array $array + * @param array $array * * @return string */ @@ -95,7 +95,7 @@ class TransactionGroupTwig extends AbstractExtension $colored = false; } - $result = app('amount')->formatFlat($array['currency_symbol'], (int) $array['currency_decimal_places'], $amount, $colored); + $result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored); if ($type === TransactionType::TRANSFER) { $result = sprintf('%s', $result); } @@ -104,9 +104,9 @@ class TransactionGroupTwig extends AbstractExtension } /** - * @param string $amount - * @param string $transactionType - * @param string $sourceType + * @param string $amount + * @param string $transactionType + * @param string $sourceType * * @return string */ @@ -133,7 +133,7 @@ class TransactionGroupTwig extends AbstractExtension /** * Generate foreign amount for transaction from a transaction group. * - * @param array $array + * @param array $array * * @return string */ @@ -149,7 +149,7 @@ class TransactionGroupTwig extends AbstractExtension if ($type === TransactionType::TRANSFER) { $colored = false; } - $result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int) $array['foreign_currency_decimal_places'], $amount, $colored); + $result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored); if ($type === TransactionType::TRANSFER) { $result = sprintf('%s', $result); } @@ -183,7 +183,7 @@ class TransactionGroupTwig extends AbstractExtension /** * Generate normal amount for transaction from a transaction group. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string */ @@ -201,7 +201,7 @@ class TransactionGroupTwig extends AbstractExtension if ($type === TransactionType::TRANSFER) { $colored = false; } - $result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored); + $result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored); if ($type === TransactionType::TRANSFER) { $result = sprintf('%s', $result); } @@ -210,7 +210,7 @@ class TransactionGroupTwig extends AbstractExtension } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return bool */ @@ -225,7 +225,7 @@ class TransactionGroupTwig extends AbstractExtension /** * Generate foreign amount for journal from a transaction group. * - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return string */ @@ -244,7 +244,7 @@ class TransactionGroupTwig extends AbstractExtension if ($type === TransactionType::TRANSFER) { $colored = false; } - $result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored); + $result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored); if ($type === TransactionType::TRANSFER) { $result = sprintf('%s', $result); } diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.php index 752fd27c79..11b420f0be 100644 --- a/app/Support/Twig/Translation.php +++ b/app/Support/Twig/Translation.php @@ -1,4 +1,5 @@ ['html']] ), diff --git a/app/TransactionRules/Actions/ActionInterface.php b/app/TransactionRules/Actions/ActionInterface.php index 0686714f3e..4dd7e1161f 100644 --- a/app/TransactionRules/Actions/ActionInterface.php +++ b/app/TransactionRules/Actions/ActionInterface.php @@ -1,4 +1,5 @@ text = trim(sprintf("%s \n%s", $note->text, $object->description)); } if ('' === $note->text) { - $note->text = (string) $object->description; + $note->text = (string)$object->description; } $after = $note->text; diff --git a/app/TransactionRules/Actions/AppendNotes.php b/app/TransactionRules/Actions/AppendNotes.php index a521334d1a..f55d6dc358 100644 --- a/app/TransactionRules/Actions/AppendNotes.php +++ b/app/TransactionRules/Actions/AppendNotes.php @@ -1,4 +1,5 @@ where('noteable_type', TransactionJournal::class) - ->first(['notes.*']); + $dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id']) + ->where('noteable_type', TransactionJournal::class) + ->first(['notes.*']); if (null === $dbNote) { $dbNote = new Note(); - $dbNote->noteable_id = (int) $journal['transaction_journal_id']; + $dbNote->noteable_id = (int)$journal['transaction_journal_id']; $dbNote->noteable_type = TransactionJournal::class; $dbNote->text = ''; } diff --git a/app/TransactionRules/Actions/AppendNotesToDescription.php b/app/TransactionRules/Actions/AppendNotesToDescription.php index f26e8677bc..9ca6fdaa7a 100644 --- a/app/TransactionRules/Actions/AppendNotesToDescription.php +++ b/app/TransactionRules/Actions/AppendNotesToDescription.php @@ -43,7 +43,7 @@ class AppendNotesToDescription implements ActionInterface /** * TriggerInterface constructor. * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -71,8 +71,8 @@ class AppendNotesToDescription implements ActionInterface } // only append if there is something to append if ('' !== $note->text) { - $before = $object->description; - $object->description = trim(sprintf("%s %s", $object->description, (string) $this->clearString($note->text, false))); + $before = $object->description; + $object->description = trim(sprintf("%s %s", $object->description, (string)$this->clearString($note->text, false))); $object->save(); Log::debug(sprintf('Journal description is updated to "%s".', $object->description)); diff --git a/app/TransactionRules/Actions/ClearBudget.php b/app/TransactionRules/Actions/ClearBudget.php index c58eb59dd5..2bef3a4fe4 100644 --- a/app/TransactionRules/Actions/ClearBudget.php +++ b/app/TransactionRules/Actions/ClearBudget.php @@ -1,4 +1,5 @@ find($journal['transaction_journal_id']); - $budget = $object->budgets()->first(); + $budget = $object->budgets()->first(); if (null === $budget) { Log::debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id'])); return false; diff --git a/app/TransactionRules/Actions/ClearCategory.php b/app/TransactionRules/Actions/ClearCategory.php index 3e8719ee57..43874d063c 100644 --- a/app/TransactionRules/Actions/ClearCategory.php +++ b/app/TransactionRules/Actions/ClearCategory.php @@ -1,4 +1,5 @@ find($journal['transaction_journal_id']); + $object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']); $category = $object->categories()->first(); if (null === $category) { Log::debug(sprintf('RuleAction ClearCategory, no category in journal #%d.', $journal['transaction_journal_id'])); diff --git a/app/TransactionRules/Actions/ClearNotes.php b/app/TransactionRules/Actions/ClearNotes.php index 52ca3e24ca..e14fe32b95 100644 --- a/app/TransactionRules/Actions/ClearNotes.php +++ b/app/TransactionRules/Actions/ClearNotes.php @@ -1,4 +1,5 @@ find($journal['transaction_journal_id']); - $notes = $object->notes()->first(); + $notes = $object->notes()->first(); if (null === $notes) { Log::debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id'])); return false; diff --git a/app/TransactionRules/Actions/ConvertToDeposit.php b/app/TransactionRules/Actions/ConvertToDeposit.php index 1b05ea053e..ce9a74a7f8 100644 --- a/app/TransactionRules/Actions/ConvertToDeposit.php +++ b/app/TransactionRules/Actions/ConvertToDeposit.php @@ -45,7 +45,7 @@ class ConvertToDeposit implements ActionInterface /** * TriggerInterface constructor. * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -94,7 +94,7 @@ class ConvertToDeposit implements ActionInterface * Input is a withdrawal from A to B * Is converted to a deposit from C to A. * - * @param array $journal + * @param array $journal * * @return bool * @throws FireflyException @@ -142,7 +142,7 @@ class ConvertToDeposit implements ActionInterface * Input is a transfer from A to B. * Output is a deposit from C to B. * - * @param array $journal + * @param array $journal * * @return bool * @throws FireflyException diff --git a/app/TransactionRules/Actions/ConvertToTransfer.php b/app/TransactionRules/Actions/ConvertToTransfer.php index 9d3035db24..067a622735 100644 --- a/app/TransactionRules/Actions/ConvertToTransfer.php +++ b/app/TransactionRules/Actions/ConvertToTransfer.php @@ -45,7 +45,7 @@ class ConvertToTransfer implements ActionInterface /** * TriggerInterface constructor. * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -114,8 +114,8 @@ class ConvertToTransfer implements ActionInterface * A withdrawal is from Asset to Expense. * We replace the Expense with another asset. * - * @param array $journal - * @param Account $asset + * @param array $journal + * @param Account $asset * * @return bool */ @@ -154,8 +154,8 @@ class ConvertToTransfer implements ActionInterface * A deposit is from Revenue to Asset. * We replace the Revenue with another asset. * - * @param array $journal - * @param Account $asset + * @param array $journal + * @param Account $asset * * @return bool */ diff --git a/app/TransactionRules/Actions/ConvertToWithdrawal.php b/app/TransactionRules/Actions/ConvertToWithdrawal.php index f7844045a4..447682cfbe 100644 --- a/app/TransactionRules/Actions/ConvertToWithdrawal.php +++ b/app/TransactionRules/Actions/ConvertToWithdrawal.php @@ -45,7 +45,7 @@ class ConvertToWithdrawal implements ActionInterface /** * TriggerInterface constructor. * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -127,7 +127,7 @@ class ConvertToWithdrawal implements ActionInterface * Input is a transfer from A to B. * Output is a withdrawal from A to C. * - * @param array $journal + * @param array $journal * * @return bool * @throws FireflyException diff --git a/app/TransactionRules/Actions/DeleteTransaction.php b/app/TransactionRules/Actions/DeleteTransaction.php index 2912082630..35be86196a 100644 --- a/app/TransactionRules/Actions/DeleteTransaction.php +++ b/app/TransactionRules/Actions/DeleteTransaction.php @@ -1,4 +1,5 @@ setUser($user); - $billName = (string) $this->action->action_value; + $billName = (string)$this->action->action_value; $bill = $repository->findByName($billName); if (null !== $bill && $journal['transaction_type_type'] === TransactionType::WITHDRAWAL) { $count = DB::table('transaction_journals')->where('id', '=', $journal['transaction_journal_id']) ->where('bill_id', $bill->id)->count(); if (0 !== $count) { - Log::error(sprintf('RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": already set.', $journal['transaction_journal_id'], $billName)); + Log::error( + sprintf( + 'RuleAction LinkToBill could not set the bill of journal #%d to bill "%s": already set.', + $journal['transaction_journal_id'], + $billName + ) + ); return false; } diff --git a/app/TransactionRules/Actions/MoveDescriptionToNotes.php b/app/TransactionRules/Actions/MoveDescriptionToNotes.php index 45faf1aef6..fcab74d39b 100644 --- a/app/TransactionRules/Actions/MoveDescriptionToNotes.php +++ b/app/TransactionRules/Actions/MoveDescriptionToNotes.php @@ -42,7 +42,7 @@ class MoveDescriptionToNotes implements ActionInterface * * @codeCoverageIgnore * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -69,11 +69,11 @@ class MoveDescriptionToNotes implements ActionInterface $before = $note->text; $beforeDescription = $object->description; if ('' !== $note->text) { - $note->text = trim(sprintf("%s \n%s", $note->text, $object->description)); + $note->text = trim(sprintf("%s \n%s", $note->text, $object->description)); $object->description = '(no description)'; } if ('' === $note->text) { - $note->text = (string) $object->description; + $note->text = (string)$object->description; $object->description = '(no description)'; } $after = $note->text; diff --git a/app/TransactionRules/Actions/MoveNotesToDescription.php b/app/TransactionRules/Actions/MoveNotesToDescription.php index bd697e8205..0825d17885 100644 --- a/app/TransactionRules/Actions/MoveNotesToDescription.php +++ b/app/TransactionRules/Actions/MoveNotesToDescription.php @@ -41,7 +41,7 @@ class MoveNotesToDescription implements ActionInterface * * @codeCoverageIgnore * - * @param RuleAction $action + * @param RuleAction $action */ public function __construct(RuleAction $action) { @@ -69,9 +69,9 @@ class MoveNotesToDescription implements ActionInterface $note->delete(); return false; } - $before = $object->description; - $beforeNote = $note->text; - $object->description = (string) $this->clearString($note->text, false); + $before = $object->description; + $beforeNote = $note->text; + $object->description = (string)$this->clearString($note->text, false); $object->save(); $note->delete(); diff --git a/app/TransactionRules/Actions/PrependDescription.php b/app/TransactionRules/Actions/PrependDescription.php index 824a015768..f2a12ef24b 100644 --- a/app/TransactionRules/Actions/PrependDescription.php +++ b/app/TransactionRules/Actions/PrependDescription.php @@ -1,4 +1,5 @@ where('noteable_type', TransactionJournal::class) - ->first(['notes.*']); + $dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id']) + ->where('noteable_type', TransactionJournal::class) + ->first(['notes.*']); if (null === $dbNote) { $dbNote = new Note(); - $dbNote->noteable_id = (int) $journal['transaction_journal_id']; + $dbNote->noteable_id = (int)$journal['transaction_journal_id']; $dbNote->noteable_type = TransactionJournal::class; $dbNote->text = ''; } diff --git a/app/TransactionRules/Actions/RemoveAllTags.php b/app/TransactionRules/Actions/RemoveAllTags.php index 486ec340f9..54c9d06e2f 100644 --- a/app/TransactionRules/Actions/RemoveAllTags.php +++ b/app/TransactionRules/Actions/RemoveAllTags.php @@ -1,4 +1,5 @@ where('transaction_journal_id', $journal['transaction_journal_id'])->where('tag_id', $tag->id)->count(); if (0 === $count) { - Log::debug(sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id'])); + Log::debug( + sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id']) + ); return false; } diff --git a/app/TransactionRules/Actions/SetBudget.php b/app/TransactionRules/Actions/SetBudget.php index 4bd2b078d0..35714bd276 100644 --- a/app/TransactionRules/Actions/SetBudget.php +++ b/app/TransactionRules/Actions/SetBudget.php @@ -1,4 +1,5 @@ find($journal['transaction_journal_id']); - $before = $object->description; + $before = $object->description; DB::table('transaction_journals') ->where('id', '=', $journal['transaction_journal_id']) diff --git a/app/TransactionRules/Actions/SetDestinationAccount.php b/app/TransactionRules/Actions/SetDestinationAccount.php index a283fea95a..0bf9b4f187 100644 --- a/app/TransactionRules/Actions/SetDestinationAccount.php +++ b/app/TransactionRules/Actions/SetDestinationAccount.php @@ -1,4 +1,5 @@ transactionJournals()->find((int) $journal['transaction_journal_id']); + $object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']); $this->repository = app(AccountRepositoryInterface::class); if (null === $object) { @@ -98,7 +99,7 @@ class SetDestinationAccount implements ActionInterface return false; } - if (null !== $newAccount && (int) $newAccount->id === (int) $source->account_id) { + if (null !== $newAccount && (int)$newAccount->id === (int)$source->account_id) { Log::error( sprintf( 'New destination account ID #%d and current source account ID #%d are the same. Do nothing.', @@ -132,7 +133,7 @@ class SetDestinationAccount implements ActionInterface } /** - * @param string $type + * @param string $type * * @return Account|null */ diff --git a/app/TransactionRules/Actions/SetNotes.php b/app/TransactionRules/Actions/SetNotes.php index 76457cb887..0979fd8e48 100644 --- a/app/TransactionRules/Actions/SetNotes.php +++ b/app/TransactionRules/Actions/SetNotes.php @@ -1,4 +1,5 @@ transactionJournals()->find((int) $journal['transaction_journal_id']); + $object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']); $this->repository = app(AccountRepositoryInterface::class); if (null === $object) { Log::error('Could not find journal.'); @@ -93,7 +94,7 @@ class SetSourceAccount implements ActionInterface return false; } - if (null !== $newAccount && (int) $newAccount->id === (int) $destination->account_id) { + if (null !== $newAccount && (int)$newAccount->id === (int)$destination->account_id) { Log::error( sprintf( 'New source account ID #%d and current destination account ID #%d are the same. Do nothing.', @@ -127,7 +128,7 @@ class SetSourceAccount implements ActionInterface } /** - * @param string $type + * @param string $type * * @return Account|null */ diff --git a/app/TransactionRules/Actions/UpdatePiggybank.php b/app/TransactionRules/Actions/UpdatePiggybank.php index 2f55051b10..10ad6a967c 100644 --- a/app/TransactionRules/Actions/UpdatePiggybank.php +++ b/app/TransactionRules/Actions/UpdatePiggybank.php @@ -91,7 +91,20 @@ class UpdatePiggybank implements ActionInterface Log::debug('Piggy bank account is linked to source, so remove amount from piggy bank.'); $this->removeAmount($piggyBank, $journalObj, $destination->amount); - event(new TriggeredAuditLog($this->action->rule, $journalObj, 'remove_from_piggy', null, ['currency_symbol' => $journalObj->transactionCurrency->symbol, 'decimal_places' => $journalObj->transactionCurrency->decimal_places, 'amount' => $destination->amount, 'piggy' => $piggyBank->name])); + event( + new TriggeredAuditLog( + $this->action->rule, + $journalObj, + 'remove_from_piggy', + null, + [ + 'currency_symbol' => $journalObj->transactionCurrency->symbol, + 'decimal_places' => $journalObj->transactionCurrency->decimal_places, + 'amount' => $destination->amount, + 'piggy' => $piggyBank->name, + ] + ) + ); return true; } @@ -99,7 +112,20 @@ class UpdatePiggybank implements ActionInterface Log::debug('Piggy bank account is linked to source, so add amount to piggy bank.'); $this->addAmount($piggyBank, $journalObj, $destination->amount); - event(new TriggeredAuditLog($this->action->rule, $journalObj, 'add_to_piggy', null, ['currency_symbol' => $journalObj->transactionCurrency->symbol, 'decimal_places' => $journalObj->transactionCurrency->decimal_places, 'amount' => $destination->amount, 'piggy' => $piggyBank->name])); + event( + new TriggeredAuditLog( + $this->action->rule, + $journalObj, + 'add_to_piggy', + null, + [ + 'currency_symbol' => $journalObj->transactionCurrency->symbol, + 'decimal_places' => $journalObj->transactionCurrency->decimal_places, + 'amount' => $destination->amount, + 'piggy' => $piggyBank->name, + ] + ) + ); return true; } diff --git a/app/TransactionRules/Engine/RuleEngineInterface.php b/app/TransactionRules/Engine/RuleEngineInterface.php index d6e54d0002..111fdb6231 100644 --- a/app/TransactionRules/Engine/RuleEngineInterface.php +++ b/app/TransactionRules/Engine/RuleEngineInterface.php @@ -34,7 +34,7 @@ interface RuleEngineInterface /** * Add operators added to each search by the rule engine. * - * @param array $operator + * @param array $operator */ public function addOperator(array $operator): void; @@ -58,19 +58,19 @@ interface RuleEngineInterface /** * Add entire rule groups for the engine to execute. * - * @param Collection $ruleGroups + * @param Collection $ruleGroups */ public function setRuleGroups(Collection $ruleGroups): void; /** * Add rules for the engine to execute. * - * @param Collection $rules + * @param Collection $rules */ public function setRules(Collection $rules): void; /** - * @param User $user + * @param User $user */ public function setUser(User $user): void; } diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php index 19c45599d0..756716ce82 100644 --- a/app/TransactionRules/Engine/SearchRuleEngine.php +++ b/app/TransactionRules/Engine/SearchRuleEngine.php @@ -89,7 +89,7 @@ class SearchRuleEngine implements RuleEngineInterface /** * Finds the transactions a strict rule will execute on. * - * @param Rule $rule + * @param Rule $rule * * @return Collection */ @@ -152,7 +152,7 @@ class SearchRuleEngine implements RuleEngineInterface * one search operator for "journal_id" it means the date ranges * in the search may need to be updated. * - * @param array $array + * @param array $array * * @return bool */ @@ -178,7 +178,7 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param array $array + * @param array $array * * @return Carbon */ @@ -188,7 +188,7 @@ class SearchRuleEngine implements RuleEngineInterface $journalId = 0; foreach ($array as $triggerName => $values) { if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) { - $journalId = (int) trim(($values[0] ?? '"0"'), '"'); // follows format "123". + $journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123". Log::debug(sprintf('Found journal ID #%d', $journalId)); } } @@ -209,7 +209,16 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param Rule $rule + * @inheritDoc + */ + public function setUser(User $user): void + { + $this->user = $user; + $this->operators = []; + } + + /** + * @param Rule $rule * * @return Collection */ @@ -320,7 +329,7 @@ class SearchRuleEngine implements RuleEngineInterface /** * Returns true if the rule has been triggered. * - * @param Rule $rule + * @param Rule $rule * * @return bool * @throws FireflyException @@ -346,7 +355,7 @@ class SearchRuleEngine implements RuleEngineInterface /** * Return true if the rule is fired (the collection is larger than zero). * - * @param Rule $rule + * @param Rule $rule * * @return bool * @throws FireflyException @@ -371,8 +380,8 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param Rule $rule - * @param Collection $collection + * @param Rule $rule + * @param Collection $collection * * @throws FireflyException */ @@ -386,8 +395,8 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param Rule $rule - * @param array $group + * @param Rule $rule + * @param array $group * * @throws FireflyException */ @@ -401,8 +410,8 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param Rule $rule - * @param array $transaction + * @param Rule $rule + * @param array $transaction * * @throws FireflyException */ @@ -423,8 +432,8 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param RuleAction $ruleAction - * @param array $transaction + * @param RuleAction $ruleAction + * @param array $transaction * * @return bool * @throws FireflyException @@ -463,7 +472,7 @@ class SearchRuleEngine implements RuleEngineInterface /** * Return true if the rule is fired (the collection is larger than zero). * - * @param Rule $rule + * @param Rule $rule * * @return bool * @throws FireflyException @@ -480,7 +489,7 @@ class SearchRuleEngine implements RuleEngineInterface } /** - * @param RuleGroup $group + * @param RuleGroup $group * * @return void * @throws FireflyException @@ -541,13 +550,4 @@ class SearchRuleEngine implements RuleEngineInterface } } } - - /** - * @inheritDoc - */ - public function setUser(User $user): void - { - $this->user = $user; - $this->operators = []; - } } diff --git a/app/TransactionRules/Factory/ActionFactory.php b/app/TransactionRules/Factory/ActionFactory.php index 37a8acae7b..5627727ea6 100644 --- a/app/TransactionRules/Factory/ActionFactory.php +++ b/app/TransactionRules/Factory/ActionFactory.php @@ -1,4 +1,5 @@ accountType->type; - $accountType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); - $liabilityType = (string) config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); + $accountType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); + $liabilityType = (string)config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); $liabilityDirection = $this->repository->getMetaValue($account, 'liability_direction'); @@ -87,17 +87,17 @@ class AccountTransformer extends AbstractTransformer if (null !== $location) { $longitude = $location->longitude; $latitude = $location->latitude; - $zoomLevel = (int) $location->zoom_level; + $zoomLevel = (int)$location->zoom_level; } // no order for some accounts: - $order = (int) $account->order; + $order = (int)$account->order; if (!in_array(strtolower($accountType), ['liability', 'liabilities', 'asset'], true)) { $order = null; } return [ - 'id' => (string) $account->id, + 'id' => (string)$account->id, 'created_at' => $account->created_at->toAtomString(), 'updated_at' => $account->updated_at->toAtomString(), 'active' => $account->active, @@ -132,23 +132,23 @@ class AccountTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/accounts/' . $account->id, + 'uri' => '/accounts/'.$account->id, ], ], ]; } /** - * @param Account $account + * @param Account $account * - * @param string $accountType + * @param string $accountType * * @return string|null */ private function getAccountRole(Account $account, string $accountType): ?string { $accountRole = $this->repository->getMetaValue($account, 'account_role'); - if ('asset' !== $accountType || '' === (string) $accountRole) { + if ('asset' !== $accountType || '' === (string)$accountRole) { $accountRole = null; } @@ -170,7 +170,7 @@ class AccountTransformer extends AbstractTransformer } /** - * @param Account $account + * @param Account $account * * @return array * @throws FireflyException @@ -184,7 +184,7 @@ class AccountTransformer extends AbstractTransformer if (null === $currency) { $currency = app('amount')->getDefaultCurrencyByUser($account->user); } - $currencyId = (string) $currency->id; + $currencyId = (string)$currency->id; $currencyCode = $currency->code; $decimalPlaces = $currency->decimal_places; $currencySymbol = $currency->symbol; @@ -193,9 +193,9 @@ class AccountTransformer extends AbstractTransformer } /** - * @param Account $account - * @param string|null $accountRole - * @param string $accountType + * @param Account $account + * @param string|null $accountRole + * @param string $accountType * * @return array */ @@ -215,8 +215,8 @@ class AccountTransformer extends AbstractTransformer } /** - * @param Account $account - * @param string $accountType + * @param Account $account + * @param string $accountType * * @return array * @@ -239,8 +239,8 @@ class AccountTransformer extends AbstractTransformer } /** - * @param Account $account - * @param string $accountType + * @param Account $account + * @param string $accountType * * @return array */ diff --git a/app/Transformers/AttachmentTransformer.php b/app/Transformers/AttachmentTransformer.php index 3d03a79c4d..e816a8ba3f 100644 --- a/app/Transformers/AttachmentTransformer.php +++ b/app/Transformers/AttachmentTransformer.php @@ -46,7 +46,7 @@ class AttachmentTransformer extends AbstractTransformer /** * Transform attachment. * - * @param Attachment $attachment + * @param Attachment $attachment * * @return array */ @@ -55,10 +55,10 @@ class AttachmentTransformer extends AbstractTransformer $this->repository->setUser($attachment->user); return [ - 'id' => (string) $attachment->id, + 'id' => (string)$attachment->id, 'created_at' => $attachment->created_at->toAtomString(), 'updated_at' => $attachment->updated_at->toAtomString(), - 'attachable_id' => (string) $attachment->attachable_id, + 'attachable_id' => (string)$attachment->attachable_id, 'attachable_type' => str_replace('FireflyIII\\Models\\', '', $attachment->attachable_type), 'md5' => $attachment->md5, 'filename' => $attachment->filename, @@ -67,11 +67,11 @@ class AttachmentTransformer extends AbstractTransformer 'title' => $attachment->title, 'notes' => $this->repository->getNoteText($attachment), 'mime' => $attachment->mime, - 'size' => (int) $attachment->size, + 'size' => (int)$attachment->size, 'links' => [ [ 'rel' => 'self', - 'uri' => '/attachment/' . $attachment->id, + 'uri' => '/attachment/'.$attachment->id, ], ], ]; diff --git a/app/Transformers/AvailableBudgetTransformer.php b/app/Transformers/AvailableBudgetTransformer.php index 62944bab86..ec7cdd1b23 100644 --- a/app/Transformers/AvailableBudgetTransformer.php +++ b/app/Transformers/AvailableBudgetTransformer.php @@ -52,7 +52,7 @@ class AvailableBudgetTransformer extends AbstractTransformer /** * Transform the note. * - * @param AvailableBudget $availableBudget + * @param AvailableBudget $availableBudget * * @return array */ @@ -62,13 +62,13 @@ class AvailableBudgetTransformer extends AbstractTransformer $currency = $availableBudget->transactionCurrency; $data = [ - 'id' => (string) $availableBudget->id, + 'id' => (string)$availableBudget->id, 'created_at' => $availableBudget->created_at->toAtomString(), 'updated_at' => $availableBudget->updated_at->toAtomString(), - 'currency_id' => (string) $currency->id, + 'currency_id' => (string)$currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => (int) $currency->decimal_places, + 'currency_decimal_places' => (int)$currency->decimal_places, 'amount' => app('steam')->bcround($availableBudget->amount, $currency->decimal_places), 'start' => $availableBudget->start_date->toAtomString(), 'end' => $availableBudget->end_date->endOfDay()->toAtomString(), @@ -77,7 +77,7 @@ class AvailableBudgetTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/available_budgets/' . $availableBudget->id, + 'uri' => '/available_budgets/'.$availableBudget->id, ], ], ]; diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php index 54b1d11348..e88ddc7786 100644 --- a/app/Transformers/BillTransformer.php +++ b/app/Transformers/BillTransformer.php @@ -52,7 +52,7 @@ class BillTransformer extends AbstractTransformer /** * Transform the bill. * - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -72,8 +72,8 @@ class BillTransformer extends AbstractTransformer /** @var ObjectGroup $objectGroup */ $objectGroup = $bill->objectGroups->first(); if (null !== $objectGroup) { - $objectGroupId = (int) $objectGroup->id; - $objectGroupOrder = (int) $objectGroup->order; + $objectGroupId = (int)$objectGroup->id; + $objectGroupOrder = (int)$objectGroup->order; $objectGroupTitle = $objectGroup->title; } @@ -107,13 +107,13 @@ class BillTransformer extends AbstractTransformer unset($temp, $temp2); return [ - 'id' => (int) $bill->id, + 'id' => (int)$bill->id, 'created_at' => $bill->created_at->toAtomString(), 'updated_at' => $bill->updated_at->toAtomString(), - 'currency_id' => (string) $bill->transaction_currency_id, + 'currency_id' => (string)$bill->transaction_currency_id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => (int) $currency->decimal_places, + 'currency_decimal_places' => (int)$currency->decimal_places, 'name' => $bill->name, 'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places), 'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places), @@ -121,11 +121,11 @@ class BillTransformer extends AbstractTransformer 'end_date' => $bill->end_date?->toAtomString(), 'extension_date' => $bill->extension_date?->toAtomString(), 'repeat_freq' => $bill->repeat_freq, - 'skip' => (int) $bill->skip, + 'skip' => (int)$bill->skip, 'active' => $bill->active, - 'order' => (int) $bill->order, + 'order' => (int)$bill->order, 'notes' => $notes, - 'object_group_id' => $objectGroupId ? (string) $objectGroupId : null, + 'object_group_id' => $objectGroupId ? (string)$objectGroupId : null, 'object_group_order' => $objectGroupOrder, 'object_group_title' => $objectGroupTitle, @@ -137,7 +137,7 @@ class BillTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/bills/' . $bill->id, + 'uri' => '/bills/'.$bill->id, ], ], ]; @@ -146,7 +146,7 @@ class BillTransformer extends AbstractTransformer /** * Get the data the bill was paid and predict the next expected match. * - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -203,8 +203,8 @@ class BillTransformer extends AbstractTransformer $result = []; foreach ($set as $entry) { $result[] = [ - 'transaction_group_id' => (int) $entry->transaction_group_id, - 'transaction_journal_id' => (int) $entry->id, + 'transaction_group_id' => (int)$entry->transaction_group_id, + 'transaction_journal_id' => (int)$entry->id, 'date' => $entry->date->format('Y-m-d'), ]; } @@ -220,8 +220,8 @@ class BillTransformer extends AbstractTransformer /** * Returns the latest date in the set, or start when set is empty. * - * @param Collection $dates - * @param Carbon $default + * @param Collection $dates + * @param Carbon $default * * @return Carbon */ @@ -242,7 +242,7 @@ class BillTransformer extends AbstractTransformer } /** - * @param Bill $bill + * @param Bill $bill * * @return array */ @@ -285,8 +285,8 @@ class BillTransformer extends AbstractTransformer * Given a bill and a date, this method will tell you at which moment this bill expects its next * transaction. Whether or not it is there already, is not relevant. * - * @param Bill $bill - * @param Carbon $date + * @param Bill $bill + * @param Carbon $date * * @return Carbon */