From 2b6c3fd743a9a7f821cb968e44c896aa5856e025 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 17 Mar 2020 15:01:00 +0100 Subject: [PATCH] Code cleanup that (hopefully) matches style CI --- app/Handlers/Events/APIEventHandler.php | 2 +- .../Events/UpdatedGroupEventHandler.php | 1 - .../Events/VersionCheckEventHandler.php | 9 +- app/Helpers/Attachments/AttachmentHelper.php | 29 +- .../Collector/GroupCollectorInterface.php | 67 ++-- app/Helpers/Fiscal/FiscalHelper.php | 2 +- app/Helpers/Report/NetWorth.php | 8 +- app/Helpers/Report/PopupReport.php | 14 +- app/Helpers/Report/PopupReportInterface.php | 3 +- app/Helpers/Report/ReportHelper.php | 5 +- app/Helpers/Report/ReportHelperInterface.php | 1 - .../Controllers/Account/CreateController.php | 38 +- .../Controllers/Account/DeleteController.php | 17 +- .../Controllers/Account/EditController.php | 50 ++- .../Controllers/Account/IndexController.php | 35 +- .../Account/ReconcileController.php | 62 ++-- .../Controllers/Account/ShowController.php | 62 +++- .../Admin/ConfigurationController.php | 11 +- app/Http/Controllers/Admin/HomeController.php | 15 +- app/Http/Controllers/Admin/LinkController.php | 60 ++-- .../Controllers/Admin/TelemetryController.php | 12 +- .../Controllers/Admin/UpdateController.php | 35 +- app/Http/Controllers/Admin/UserController.php | 53 +-- app/Http/Controllers/AttachmentController.php | 35 +- .../Auth/ForgotPasswordController.php | 17 +- app/Http/Controllers/Auth/LoginController.php | 21 +- .../Controllers/Auth/RegisterController.php | 13 +- .../Auth/ResetPasswordController.php | 23 +- .../Controllers/Auth/TwoFactorController.php | 8 +- app/Http/Controllers/BillController.php | 63 ++-- .../Budget/AvailableBudgetController.php | 30 +- .../Budget/BudgetLimitController.php | 31 +- .../Controllers/Budget/CreateController.php | 43 +-- .../Controllers/Budget/DeleteController.php | 15 +- .../Controllers/Budget/EditController.php | 41 ++- .../Controllers/Budget/IndexController.php | 54 +-- .../Controllers/Budget/ShowController.php | 56 +-- .../Controllers/Category/CreateController.php | 17 +- .../Controllers/Category/DeleteController.php | 15 +- .../Controllers/Category/EditController.php | 21 +- .../Controllers/Category/IndexController.php | 12 +- .../Category/NoCategoryController.php | 25 +- .../Controllers/Category/ShowController.php | 26 +- .../Controllers/Chart/AccountController.php | 141 ++++---- app/Http/Controllers/Chart/BillController.php | 22 +- .../Controllers/Chart/BudgetController.php | 68 ++-- .../Chart/BudgetReportController.php | 13 +- .../Controllers/Chart/CategoryController.php | 8 +- .../Chart/CategoryReportController.php | 9 +- .../Chart/DoubleReportController.php | 25 +- .../Chart/ExpenseReportController.php | 17 +- .../Controllers/Chart/PiggyBankController.php | 5 +- .../Controllers/Chart/ReportController.php | 20 +- .../Controllers/Chart/TagReportController.php | 9 +- .../Chart/TransactionController.php | 25 +- app/Http/Controllers/Controller.php | 7 +- app/Http/Controllers/CurrencyController.php | 82 +++-- app/Http/Controllers/DebugController.php | 43 ++- .../Controllers/Export/IndexController.php | 10 +- app/Http/Controllers/HomeController.php | 18 +- .../Controllers/Import/CallbackController.php | 11 +- .../Controllers/Import/IndexController.php | 21 +- .../Import/JobConfigurationController.php | 23 +- .../Import/JobStatusController.php | 14 +- .../Import/PrerequisitesController.php | 25 +- app/Http/Controllers/JavascriptController.php | 10 +- .../Json/AutoCompleteController.php | 33 +- app/Http/Controllers/Json/BoxController.php | 19 +- .../Controllers/Json/ExchangeController.php | 2 +- app/Http/Controllers/Json/IntroController.php | 2 +- .../Controllers/Json/ReconcileController.php | 46 ++- .../Controllers/Json/RecurrenceController.php | 41 ++- app/Http/Controllers/Json/RuleController.php | 8 +- app/Http/Controllers/NewUserController.php | 12 +- app/Http/Controllers/PiggyBankController.php | 66 ++-- .../Controllers/PreferencesController.php | 25 +- .../Controllers/Profile/DataController.php | 3 +- app/Http/Controllers/ProfileController.php | 74 ++-- .../Recurring/CreateController.php | 42 ++- .../Recurring/DeleteController.php | 19 +- .../Controllers/Recurring/EditController.php | 48 +-- .../Controllers/Recurring/IndexController.php | 25 +- .../Controllers/Recurring/ShowController.php | 12 +- .../Controllers/Report/BudgetController.php | 34 +- .../Controllers/Report/CategoryController.php | 106 +++--- .../Controllers/Report/DoubleController.php | 20 +- app/Http/Controllers/Report/TagController.php | 52 +-- app/Http/Controllers/ReportController.php | 135 +++---- .../Controllers/Rule/CreateController.php | 85 ++--- .../Controllers/Rule/DeleteController.php | 11 +- app/Http/Controllers/Rule/EditController.php | 22 +- app/Http/Controllers/Rule/IndexController.php | 12 +- .../Controllers/Rule/SelectController.php | 34 +- .../RuleGroup/CreateController.php | 17 +- .../RuleGroup/DeleteController.php | 19 +- .../Controllers/RuleGroup/EditController.php | 31 +- .../RuleGroup/ExecutionController.php | 16 +- app/Http/Controllers/SearchController.php | 22 +- .../Controllers/System/InstallController.php | 10 +- app/Http/Controllers/TagController.php | 132 +++---- .../Transaction/BulkController.php | 48 +-- .../Transaction/ConvertController.php | 335 +++++++++--------- .../Transaction/CreateController.php | 38 +- .../Transaction/DeleteController.php | 11 +- .../Transaction/EditController.php | 9 +- .../Transaction/IndexController.php | 33 +- .../Transaction/LinkController.php | 50 +-- .../Transaction/MassController.php | 163 +++++---- .../Transaction/ShowController.php | 13 +- app/Http/Kernel.php | 2 +- 110 files changed, 2060 insertions(+), 1660 deletions(-) diff --git a/app/Handlers/Events/APIEventHandler.php b/app/Handlers/Events/APIEventHandler.php index 31daf32fde..649dc9804c 100644 --- a/app/Handlers/Events/APIEventHandler.php +++ b/app/Handlers/Events/APIEventHandler.php @@ -49,7 +49,7 @@ class APIEventHandler { /** @var UserRepositoryInterface $repository */ $repository = app(UserRepositoryInterface::class); - $user = $repository->findNull((int)$event->userId); + $user = $repository->findNull((int) $event->userId); if (null !== $user) { $email = $user->email; $ipAddress = Request::ip(); diff --git a/app/Handlers/Events/UpdatedGroupEventHandler.php b/app/Handlers/Events/UpdatedGroupEventHandler.php index f478f9983e..f9b0fac623 100644 --- a/app/Handlers/Events/UpdatedGroupEventHandler.php +++ b/app/Handlers/Events/UpdatedGroupEventHandler.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Handlers\Events; use FireflyIII\Events\UpdatedTransactionGroup; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\TransactionJournal; use FireflyIII\TransactionRules\Engine\RuleEngine; diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.php index a1c57662a8..2af01ca01f 100644 --- a/app/Handlers/Events/VersionCheckEventHandler.php +++ b/app/Handlers/Events/VersionCheckEventHandler.php @@ -25,9 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Handlers\Events; -use Carbon\Carbon; use FireflyIII\Events\RequestedVersionCheckStatus; -use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Update\UpdateTrait; use FireflyIII\Models\Configuration; use FireflyIII\Repositories\User\UserRepositoryInterface; @@ -53,9 +51,10 @@ class VersionCheckEventHandler // should not check for updates: $permission = app('fireflyconfig')->get('permission_update_check', -1); - $value = (int)$permission->data; + $value = (int) $permission->data; if (1 !== $value) { Log::info('Update check is not enabled.'); + return; } @@ -65,6 +64,7 @@ class VersionCheckEventHandler $user = $event->user; if (!$repository->hasRole($user, 'owner')) { Log::debug('User is not admin, done.'); + return; } @@ -75,11 +75,12 @@ class VersionCheckEventHandler Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff)); if ($diff < 604800) { Log::debug(sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data))); + return; } // last check time was more than a week ago. Log::debug('Have not checked for a new version in a week!'); - $release = $this->getLatestRelease(); + $release = $this->getLatestRelease(); session()->flash($release['level'], $release['message']); app('fireflyconfig')->set('last_update_check', time()); diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index 9512d2d91d..261363410c 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -26,7 +26,9 @@ use Crypt; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Attachment; use Illuminate\Contracts\Encryption\DecryptException; +use Illuminate\Contracts\Encryption\EncryptException; use Illuminate\Contracts\Filesystem\FileNotFoundException; +use Illuminate\Contracts\Filesystem\Filesystem; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Storage; @@ -50,18 +52,19 @@ class AttachmentHelper implements AttachmentHelperInterface /** @var int Max upload size. */ protected $maxUploadSize = 0; - /** @var \Illuminate\Contracts\Filesystem\Filesystem The disk where attachments are stored. */ + /** @var Filesystem The disk where attachments are stored. */ protected $uploadDisk; /** * AttachmentHelper constructor. + * * @codeCoverageIgnore */ public function __construct() { - $this->maxUploadSize = (int)config('firefly.maxUploadSize'); - $this->allowedMimes = (array)config('firefly.allowedMimes'); + $this->maxUploadSize = (int) config('firefly.maxUploadSize'); + $this->allowedMimes = (array) config('firefly.allowedMimes'); $this->errors = new MessageBag; $this->messages = new MessageBag; $this->attachments = new Collection; @@ -104,16 +107,18 @@ class AttachmentHelper implements AttachmentHelperInterface * Returns the file path relative to upload disk for an attachment, * * @param Attachment $attachment + * * @codeCoverageIgnore * @return string */ public function getAttachmentLocation(Attachment $attachment): string { - return sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int)$attachment->id); + return sprintf('%sat-%d.data', DIRECTORY_SEPARATOR, (int) $attachment->id); } /** * Get all attachments. + * * @codeCoverageIgnore * @return Collection */ @@ -198,8 +203,8 @@ class AttachmentHelper implements AttachmentHelperInterface * @param object $model * @param array|null $files * - * @return bool * @throws FireflyException + * @return bool */ public function saveAttachmentsForModel(object $model, ?array $files): bool { @@ -242,7 +247,7 @@ class AttachmentHelper implements AttachmentHelperInterface $count = $model->user->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); $result = false; if ($count > 0) { - $msg = (string)trans('validation.file_already_attached', ['name' => $name]); + $msg = (string) trans('validation.file_already_attached', ['name' => $name]); $this->errors->add('attachments', $msg); Log::error($msg); $result = true; @@ -257,9 +262,9 @@ class AttachmentHelper implements AttachmentHelperInterface * @param UploadedFile $file * @param Model $model * - * @return Attachment|null - * @throws \Illuminate\Contracts\Encryption\EncryptException + * @throws EncryptException * @throws FireflyException + * @return Attachment|null */ protected function processFile(UploadedFile $file, Model $model): ?Attachment { @@ -286,7 +291,7 @@ class AttachmentHelper implements AttachmentHelperInterface throw new FireflyException('Cannot upload empty or non-existent file.'); // @codeCoverageIgnore } - $content = $fileObject->fread($file->getSize()); + $content = $fileObject->fread($file->getSize()); Log::debug(sprintf('Full file length is %d and upload size is %d.', strlen($content), $file->getSize())); // store it: @@ -296,7 +301,7 @@ class AttachmentHelper implements AttachmentHelperInterface $this->attachments->push($attachment); $name = e($file->getClientOriginalName()); // add message: - $msg = (string)trans('validation.file_attached', ['name' => $name]); + $msg = (string) trans('validation.file_attached', ['name' => $name]); $this->messages->add('attachments', $msg); } @@ -320,7 +325,7 @@ class AttachmentHelper implements AttachmentHelperInterface $result = true; if (!in_array($mime, $this->allowedMimes, true)) { - $msg = (string)trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]); + $msg = (string) trans('validation.file_invalid_mime', ['name' => $name, 'mime' => $mime]); $this->errors->add('attachments', $msg); Log::error($msg); @@ -345,7 +350,7 @@ class AttachmentHelper implements AttachmentHelperInterface $name = e($file->getClientOriginalName()); $result = true; if ($size > $this->maxUploadSize) { - $msg = (string)trans('validation.file_too_large', ['name' => $name]); + $msg = (string) trans('validation.file_too_large', ['name' => $name]); $this->errors->add('attachments', $msg); Log::error($msg); diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index df69fc4439..6975ca7b44 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -57,13 +57,6 @@ interface GroupCollectorInterface */ public function amountLess(string $amount): GroupCollectorInterface; - /** - * Add basic info on attachments of transactions. - * - * @return GroupCollectorInterface - */ - public function withAttachmentInformation(): GroupCollectorInterface; - /** * Get transactions where the amount is more than. * @@ -128,15 +121,6 @@ interface GroupCollectorInterface */ public function setAccounts(Collection $accounts): GroupCollectorInterface; - /** - * Either account can be set, but NOT both. This effectively excludes internal transfers. - * - * @param Collection $accounts - * - * @return GroupCollectorInterface - */ - public function setXorAccounts(Collection $accounts): GroupCollectorInterface; - /** * Collect transactions after a specific date. * @@ -146,24 +130,6 @@ interface GroupCollectorInterface */ public function setAfter(Carbon $date): GroupCollectorInterface; - /** - * Collect transactions created on a specific date. - * - * @param Carbon $date - * - * @return GroupCollectorInterface - */ - public function setCreatedAt(Carbon $date): GroupCollectorInterface; - - /** - * Collect transactions updated on a specific date. - * - * @param Carbon $date - * - * @return GroupCollectorInterface - */ - public function setUpdatedAt(Carbon $date): GroupCollectorInterface; - /** * Collect transactions before a specific date. * @@ -236,6 +202,14 @@ interface GroupCollectorInterface */ public function setCategory(Category $category): GroupCollectorInterface; + /** + * Collect transactions created on a specific date. + * + * @param Carbon $date + * + * @return GroupCollectorInterface + */ + public function setCreatedAt(Carbon $date): GroupCollectorInterface; /** * Limit results to a specific currency, either foreign or normal one. @@ -355,6 +329,15 @@ interface GroupCollectorInterface */ public function setTypes(array $types): GroupCollectorInterface; + /** + * Collect transactions updated on a specific date. + * + * @param Carbon $date + * + * @return GroupCollectorInterface + */ + public function setUpdatedAt(Carbon $date): GroupCollectorInterface; + /** * Set the user object and start the query. * @@ -364,6 +347,15 @@ interface GroupCollectorInterface */ public function setUser(User $user): GroupCollectorInterface; + /** + * Either account can be set, but NOT both. This effectively excludes internal transfers. + * + * @param Collection $accounts + * + * @return GroupCollectorInterface + */ + public function setXorAccounts(Collection $accounts): GroupCollectorInterface; + /** * Automatically include all stuff required to make API calls work. * @@ -378,6 +370,13 @@ interface GroupCollectorInterface */ public function withAccountInformation(): GroupCollectorInterface; + /** + * Add basic info on attachments of transactions. + * + * @return GroupCollectorInterface + */ + public function withAttachmentInformation(): GroupCollectorInterface; + /** * Include bill name + ID. * diff --git a/app/Helpers/Fiscal/FiscalHelper.php b/app/Helpers/Fiscal/FiscalHelper.php index 1bdf1c1852..10959f29c3 100644 --- a/app/Helpers/Fiscal/FiscalHelper.php +++ b/app/Helpers/Fiscal/FiscalHelper.php @@ -79,7 +79,7 @@ class FiscalHelper implements FiscalHelperInterface if (true === $this->useCustomFiscalYear) { $prefStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data; [$mth, $day] = explode('-', $prefStartStr); - $startDate->day((int)$day)->month((int)$mth); + $startDate->day((int) $day)->month((int) $mth); // if start date is after passed date, sub 1 year. if ($startDate > $date) { diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index 347f7ec68b..a906e08619 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -99,7 +99,7 @@ class NetWorth implements NetWorthInterface /** @var Account $account */ foreach ($accounts as $account) { Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name)); - $currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id'); + $currencyId = (int) $this->accountRepository->getMetaValue($account, 'currency_id'); $currencyId = 0 === $currencyId ? $default->id : $currencyId; Log::debug(sprintf('Currency ID is #%d', $currencyId)); @@ -111,9 +111,9 @@ class NetWorth implements NetWorthInterface // if the account is a credit card, subtract the virtual balance from the balance, // to better reflect that this is not money that is actually "yours". - $role = (string)$this->accountRepository->getMetaValue($account, 'account_role'); - $virtualBalance = (string)$account->virtual_balance; - if ('ccAsset' === $role && '' !== $virtualBalance && (float)$virtualBalance > 0) { + $role = (string) $this->accountRepository->getMetaValue($account, 'account_role'); + $virtualBalance = (string) $account->virtual_balance; + if ('ccAsset' === $role && '' !== $virtualBalance && (float) $virtualBalance > 0) { $balance = bcsub($balance, $virtualBalance); } diff --git a/app/Helpers/Report/PopupReport.php b/app/Helpers/Report/PopupReport.php index 46900e008b..7b586b8866 100644 --- a/app/Helpers/Report/PopupReport.php +++ b/app/Helpers/Report/PopupReport.php @@ -87,7 +87,7 @@ class PopupReport implements PopupReportInterface if (null !== $currencyId) { /** @var CurrencyRepositoryInterface $repos */ $repos = app(CurrencyRepositoryInterface::class); - $currency = $repos->find((int)$currencyId); + $currency = $repos->find((int) $currencyId); } @@ -124,7 +124,7 @@ class PopupReport implements PopupReportInterface if (null !== $currencyId) { /** @var CurrencyRepositoryInterface $repos */ $repos = app(CurrencyRepositoryInterface::class); - $currency = $repos->find((int)$currencyId); + $currency = $repos->find((int) $currencyId); } @@ -154,7 +154,7 @@ class PopupReport implements PopupReportInterface * Collect journals by a category. * * @param Category|null $category - * @param array $attributes + * @param array $attributes * * @return array */ @@ -166,7 +166,7 @@ class PopupReport implements PopupReportInterface if (null !== $currencyId) { /** @var CurrencyRepositoryInterface $repos */ $repos = app(CurrencyRepositoryInterface::class); - $currency = $repos->find((int)$currencyId); + $currency = $repos->find((int) $currencyId); } /** @var GroupCollectorInterface $collector */ @@ -179,10 +179,10 @@ class PopupReport implements PopupReportInterface ->withCategoryInformation() ->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation(); - if(null!== $category) { + if (null !== $category) { $collector->setCategory($category); } - if(null === $category) { + if (null === $category) { $collector->withoutCategory(); } @@ -209,7 +209,7 @@ class PopupReport implements PopupReportInterface if (null !== $currencyId) { /** @var CurrencyRepositoryInterface $repos */ $repos = app(CurrencyRepositoryInterface::class); - $currency = $repos->find((int)$currencyId); + $currency = $repos->find((int) $currencyId); } /** @var JournalRepositoryInterface $repository */ diff --git a/app/Helpers/Report/PopupReportInterface.php b/app/Helpers/Report/PopupReportInterface.php index 6c987b6030..4e46ee3805 100644 --- a/app/Helpers/Report/PopupReportInterface.php +++ b/app/Helpers/Report/PopupReportInterface.php @@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Report; use FireflyIII\Models\Account; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; -use Illuminate\Support\Collection; /** * Interface PopupReportInterface. @@ -68,7 +67,7 @@ interface PopupReportInterface * Group by category. * * @param Category|null $category - * @param array $attributes + * @param array $attributes * * @return array */ diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 72c495315a..3d532a132a 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -43,6 +43,7 @@ class ReportHelper implements ReportHelperInterface /** * ReportHelper constructor. + * * @param BudgetRepositoryInterface $budgetRepository */ public function __construct(BudgetRepositoryInterface $budgetRepository) @@ -62,8 +63,8 @@ class ReportHelper implements ReportHelperInterface * * Excludes bills which have not had a payment on the mentioned accounts. * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * @param Collection $accounts * * @return array diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 0c7d668ad1..e246ee946f 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Helpers\Report; use Carbon\Carbon; -use FireflyIII\Helpers\Collection\Bill as BillCollection; use Illuminate\Support\Collection; /** diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index ed01a7b06d..0aa93172d6 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -23,13 +23,16 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Account; - use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Http\Controllers\ModelInformation; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** @@ -44,6 +47,7 @@ class CreateController extends Controller /** * CreateController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -54,7 +58,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); @@ -66,17 +70,17 @@ class CreateController extends Controller /** * Create a new account. * - * @param Request $request + * @param Request $request * @param string|null $objectType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request, string $objectType = null) { $objectType = $objectType ?? 'asset'; $defaultCurrency = app('amount')->getDefaultCurrency(); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); - $subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType)); + $subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType)); $roles = $this->getRoles(); $liabilityTypes = $this->getLiabilityTypes(); $hasOldInput = null !== $request->old('_token'); @@ -91,17 +95,18 @@ class CreateController extends Controller // interest calculation periods: $interestPeriods = [ - 'daily' => (string)trans('firefly.interest_calc_daily'), - 'monthly' => (string)trans('firefly.interest_calc_monthly'), - 'yearly' => (string)trans('firefly.interest_calc_yearly'), + 'daily' => (string) trans('firefly.interest_calc_daily'), + 'monthly' => (string) trans('firefly.interest_calc_monthly'), + 'yearly' => (string) trans('firefly.interest_calc_yearly'), ]; // pre fill some data $request->session()->flash( - 'preFilled', [ - 'currency_id' => $defaultCurrency->id, - 'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : true, - ] + 'preFilled', + [ + 'currency_id' => $defaultCurrency->id, + 'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true, + ] ); // put previous url in session if not redirect from store (not "create another"). @@ -119,13 +124,13 @@ class CreateController extends Controller * * @param AccountFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(AccountFormRequest $request) { $data = $request->getAccountData(); $account = $this->repository->store($data); - $request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name])); + $request->session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name])); app('preferences')->mark(); Log::channel('audit')->info('Stored new account.', $data); @@ -138,7 +143,7 @@ class CreateController extends Controller } // redirect to previous URL. $redirect = redirect($this->getPreviousUri('accounts.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // set value so create routine will not overwrite URL: $request->session()->put('accounts.create.fromStore', true); @@ -147,7 +152,4 @@ class CreateController extends Controller return $redirect; } - - - } diff --git a/app/Http/Controllers/Account/DeleteController.php b/app/Http/Controllers/Account/DeleteController.php index d04ca94a94..2823266223 100644 --- a/app/Http/Controllers/Account/DeleteController.php +++ b/app/Http/Controllers/Account/DeleteController.php @@ -28,7 +28,11 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Http\Controllers\UserNavigation; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class DeleteController @@ -42,6 +46,7 @@ class DeleteController extends Controller /** * DeleteController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -52,7 +57,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); @@ -66,7 +71,7 @@ class DeleteController extends Controller * * @param Account $account * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function delete(Account $account) { @@ -75,7 +80,7 @@ class DeleteController extends Controller } $typeName = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); - $subTitle = (string)trans(sprintf('firefly.delete_%s_account', $typeName), ['name' => $account->name]); + $subTitle = (string) trans(sprintf('firefly.delete_%s_account', $typeName), ['name' => $account->name]); $accountList = app('expandedform')->makeSelectListWithEmpty($this->repository->getAccountsByType([$account->accountType->type])); $objectType = $typeName; unset($accountList[$account->id]); @@ -92,7 +97,7 @@ class DeleteController extends Controller * @param Request $request * @param Account $account * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, Account $account) { @@ -103,11 +108,11 @@ class DeleteController extends Controller $type = $account->accountType->type; $typeName = config(sprintf('firefly.shortNamesByFullName.%s', $type)); $name = $account->name; - $moveTo = $this->repository->findNull((int)$request->get('move_account_before_delete')); + $moveTo = $this->repository->findNull((int) $request->get('move_account_before_delete')); $this->repository->destroy($account, $moveTo); - $request->session()->flash('success', (string)trans(sprintf('firefly.%s_deleted', $typeName), ['name' => $name])); + $request->session()->flash('success', (string) trans(sprintf('firefly.%s_deleted', $typeName), ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('accounts.delete.uri')); diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index 06e59e435d..cce2a91275 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Account; - use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Models\Account; @@ -31,7 +30,11 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\ModelInformation; use FireflyIII\Support\Http\Controllers\UserNavigation; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * @@ -56,7 +59,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); @@ -69,11 +72,11 @@ class EditController extends Controller /** * Edit account overview. * - * @param Request $request - * @param Account $account + * @param Request $request + * @param Account $account * @param AccountRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View * */ public function edit(Request $request, Account $account, AccountRepositoryInterface $repository) @@ -83,7 +86,7 @@ class EditController extends Controller } $objectType = config('firefly.shortNamesByFullName')[$account->accountType->type]; - $subTitle = (string)trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]); + $subTitle = (string) trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $roles = $this->getRoles(); $liabilityTypes = $this->getLiabilityTypes(); @@ -103,9 +106,9 @@ class EditController extends Controller // interest calculation periods: $interestPeriods = [ - 'daily' => (string)trans('firefly.interest_calc_daily'), - 'monthly' => (string)trans('firefly.interest_calc_monthly'), - 'yearly' => (string)trans('firefly.interest_calc_yearly'), + 'daily' => (string) trans('firefly.interest_calc_daily'), + 'monthly' => (string) trans('firefly.interest_calc_monthly'), + 'yearly' => (string) trans('firefly.interest_calc_yearly'), ]; // put previous url in session if not redirect from store (not "return_to_edit"). @@ -114,7 +117,7 @@ class EditController extends Controller } $request->session()->forget('accounts.edit.fromUpdate'); - $openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account); + $openingBalanceAmount = (string) $repository->getOpeningBalanceAmount($account); $openingBalanceDate = $repository->getOpeningBalanceDate($account); $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); @@ -139,15 +142,25 @@ class EditController extends Controller 'interest' => $repository->getMetaValue($account, 'interest'), 'interest_period' => $repository->getMetaValue($account, 'interest_period'), 'notes' => $this->repository->getNoteText($account), - 'active' => $hasOldInput ? (bool)$request->old('active') : $account->active, + 'active' => $hasOldInput ? (bool) $request->old('active') : $account->active, ]; $request->session()->flash('preFilled', $preFilled); return view( - 'accounts.edit', compact( - 'account', 'currency', 'subTitle', 'subTitleIcon', 'locations', 'objectType', 'roles', 'preFilled', 'liabilityTypes', 'interestPeriods' - ) + 'accounts.edit', + compact( + 'account', + 'currency', + 'subTitle', + 'subTitleIcon', + 'locations', + 'objectType', + 'roles', + 'preFilled', + 'liabilityTypes', + 'interestPeriods' + ) ); } @@ -156,9 +169,9 @@ class EditController extends Controller * Update the account. * * @param AccountFormRequest $request - * @param Account $account + * @param Account $account * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function update(AccountFormRequest $request, Account $account) { @@ -169,11 +182,11 @@ class EditController extends Controller $data = $request->getAccountData(); $this->repository->update($account, $data); - $request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name])); + $request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('accounts.edit.uri')); - 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('accounts.edit.fromUpdate', true); @@ -182,5 +195,4 @@ class EditController extends Controller return $redirect; } - } diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php index b1af86bcdd..8d09a2d818 100644 --- a/app/Http/Controllers/Account/IndexController.php +++ b/app/Http/Controllers/Account/IndexController.php @@ -28,8 +28,10 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Http\Controllers\BasicDataSupport; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\View\View; /** * @@ -43,6 +45,7 @@ class IndexController extends Controller /** * IndexController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -53,7 +56,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); @@ -66,19 +69,19 @@ class IndexController extends Controller * @param Request $request * @param string $objectType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function inactive(Request $request, string $objectType) { $objectType = $objectType ?? 'asset'; $inactivePage = true; - $subTitle = (string)trans(sprintf('firefly.%s_accounts_inactive', $objectType)); + $subTitle = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); $collection = $this->repository->getInactiveAccountsByType($types); $total = $collection->count(); - $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; $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); unset($collection); /** @var Carbon $start */ @@ -99,8 +102,8 @@ class IndexController extends Controller $account->endBalance = $this->isInArray($endBalances, $account->id); $account->difference = bcsub($account->endBalance, $account->startBalance); $account->interest = round($this->repository->getMetaValue($account, 'interest'), 6); - $account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); - $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type)); + $account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); + $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type)); } ); @@ -108,7 +111,7 @@ class IndexController extends Controller $accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page); $accounts->setPath(route('accounts.inactive.index', [$objectType])); - return view('accounts.index', compact('objectType','inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts')); + return view('accounts.index', compact('objectType', 'inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts')); } @@ -116,20 +119,20 @@ class IndexController extends Controller * Show list of accounts. * * @param Request $request - * @param string $objectType + * @param string $objectType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(Request $request, string $objectType) { $objectType = $objectType ?? 'asset'; - $subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType)); + $subTitle = (string) trans(sprintf('firefly.%s_accounts', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); $collection = $this->repository->getActiveAccountsByType($types); $total = $collection->count(); - $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; $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); $inactiveCount = $this->repository->getInactiveAccountsByType($types)->count(); @@ -153,9 +156,9 @@ class IndexController extends Controller $account->endBalance = $this->isInArray($endBalances, $account->id); $account->difference = bcsub($account->endBalance, $account->startBalance); $account->interest = round($this->repository->getMetaValue($account, 'interest'), 6); - $account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); - $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type)); - $account->location = $this->repository->getLocation($account); + $account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); + $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type)); + $account->location = $this->repository->getLocation($account); } ); diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index cbc6185ecf..6e5106194f 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Account; use Carbon\Carbon; use Exception; +use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionGroupFactory; use FireflyIII\Http\Controllers\Controller; @@ -37,6 +38,10 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Http\Controllers\UserNavigation; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** @@ -54,6 +59,7 @@ class ReconcileController extends Controller /** * ReconcileController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -64,7 +70,7 @@ class ReconcileController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(JournalRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); @@ -77,12 +83,12 @@ class ReconcileController extends Controller /** * Reconciliation overview. * - * @param Account $account + * @param Account $account * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View * @throws Exception + * @return Factory|RedirectResponse|Redirector|View */ public function reconcile(Account $account, Carbon $start = null, Carbon $end = null) { @@ -93,7 +99,7 @@ class ReconcileController extends Controller if (AccountType::ASSET !== $account->accountType->type) { // @codeCoverageIgnoreStart - session()->flash('error', (string)trans('firefly.must_be_asset_account')); + session()->flash('error', (string) trans('firefly.must_be_asset_account')); return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))])); // @codeCoverageIgnoreEnd @@ -111,7 +117,6 @@ class ReconcileController extends Controller $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range)); /** @var Carbon $end */ $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range)); - } if (null === $end) { /** @var Carbon $end */ @@ -128,7 +133,7 @@ class ReconcileController extends Controller $endBalance = round(app('steam')->balance($account, $end), $currency->decimal_places); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); - $subTitle = (string)trans('firefly.reconcile_account', ['account' => $account->name]); + $subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]); // various links $transactionsUri = route('accounts.reconcile.transactions', [$account->id, '%start%', '%end%']); @@ -136,21 +141,34 @@ class ReconcileController extends Controller $indexUri = route('accounts.reconcile', [$account->id, '%start%', '%end%']); $objectType = 'asset'; - return view('accounts.reconcile.index', - compact('account', 'currency', 'objectType', - 'subTitleIcon', 'start', 'end', 'subTitle', 'startBalance', 'endBalance', - 'transactionsUri', 'overviewUri', 'indexUri')); + return view( + 'accounts.reconcile.index', + compact( + 'account', + 'currency', + 'objectType', + 'subTitleIcon', + 'start', + 'end', + 'subTitle', + 'startBalance', + 'endBalance', + 'transactionsUri', + 'overviewUri', + 'indexUri' + ) + ); } /** * Submit a new reconciliation. * * @param ReconciliationStoreRequest $request - * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Account $account + * @param Carbon $start + * @param Carbon $end * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function submit(ReconciliationStoreRequest $request, Account $account, Carbon $start, Carbon $end) { @@ -163,7 +181,7 @@ class ReconcileController extends Controller /** @var string $journalId */ foreach ($data['journals'] as $journalId) { - $this->repository->reconcileById((int)$journalId); + $this->repository->reconcileById((int) $journalId); } Log::debug('Reconciled all transactions.'); @@ -180,10 +198,10 @@ class ReconcileController extends Controller Log::debug('End of routine.'); app('preferences')->mark(); if ('' === $result) { - session()->flash('success', (string)trans('firefly.reconciliation_stored')); + session()->flash('success', (string) trans('firefly.reconciliation_stored')); } if ('' !== $result) { - session()->flash('error', (string)trans('firefly.reconciliation_error', ['error' => $result])); + session()->flash('error', (string) trans('firefly.reconciliation_error', ['error' => $result])); } return redirect(route('accounts.show', [$account->id])); @@ -197,8 +215,8 @@ class ReconcileController extends Controller * @param Carbon $end * @param string $difference * + * @throws DuplicateTransactionException * @return string - * @throws \FireflyIII\Exceptions\DuplicateTransactionException */ private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference) { @@ -220,9 +238,11 @@ class ReconcileController extends Controller } // title: - $description = trans('firefly.reconciliation_transaction_title', - ['from' => $start->formatLocalized($this->monthAndDayFormat), 'to' => $end->formatLocalized($this->monthAndDayFormat)]); - $submission = [ + $description = trans( + 'firefly.reconciliation_transaction_title', + ['from' => $start->formatLocalized($this->monthAndDayFormat), 'to' => $end->formatLocalized($this->monthAndDayFormat)] + ); + $submission = [ 'user' => auth()->user()->id, 'group_title' => null, 'transactions' => [ diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index f422374399..ea8d7bc57f 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -32,7 +32,9 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; use FireflyIII\Support\Http\Controllers\UserNavigation; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; use View; @@ -51,6 +53,7 @@ class ShowController extends Controller /** * ShowController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -63,7 +66,7 @@ class ShowController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); @@ -77,13 +80,13 @@ class ShowController extends Controller /** * Show an account. * - * @param Request $request - * @param Account $account + * @param Request $request + * @param Account $account * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View * @throws Exception + * @return RedirectResponse|Redirector|View */ public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null) { @@ -103,12 +106,12 @@ class ShowController extends Controller $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); $today = new Carbon; $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $fStart = $start->formatLocalized($this->monthAndDayFormat); $fEnd = $end->formatLocalized($this->monthAndDayFormat); - $subTitle = (string)trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); + $subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); $chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); $firstTransaction = $this->repository->oldestJournalDate($account) ?? $start; $periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end); @@ -123,13 +126,25 @@ class ShowController extends Controller $groups = $collector->getPaginatedGroups(); $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); $showAll = false; - $balance = app('steam')->balance($account, $end); + $balance = app('steam')->balance($account, $end); return view( 'accounts.show', compact( - 'account', 'showAll', 'objectType', 'currency', 'today', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end', - 'chartUri', 'location','balance' + 'account', + 'showAll', + 'objectType', + 'currency', + 'today', + 'periods', + 'subTitleIcon', + 'groups', + 'subTitle', + 'start', + 'end', + 'chartUri', + 'location', + 'balance' ) ); } @@ -139,8 +154,9 @@ class ShowController extends Controller * * @param Request $request * @param Account $account - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * * @throws Exception + * @return RedirectResponse|Redirector|View */ public function showAll(Request $request, Account $account) { @@ -156,10 +172,10 @@ class ShowController extends Controller $today = new Carbon; $start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); - $subTitle = (string)trans('firefly.all_journals_for_account', ['name' => $account->name]); + $subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); $periods = new Collection; /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -173,10 +189,22 @@ class ShowController extends Controller return view( 'accounts.show', compact( - 'account', 'showAll', 'location', 'objectType', 'isLiability', 'currency', 'today', - 'chartUri', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end', 'balance' + 'account', + 'showAll', + 'location', + 'objectType', + 'isLiability', + 'currency', + 'today', + 'chartUri', + 'periods', + 'subTitleIcon', + 'groups', + 'subTitle', + 'start', + 'end', + 'balance' ) ); } - } diff --git a/app/Http/Controllers/Admin/ConfigurationController.php b/app/Http/Controllers/Admin/ConfigurationController.php index c83a0ab33d..6a026d938d 100644 --- a/app/Http/Controllers/Admin/ConfigurationController.php +++ b/app/Http/Controllers/Admin/ConfigurationController.php @@ -27,7 +27,9 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\IsSandStormUser; use FireflyIII\Http\Requests\ConfigurationRequest; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; +use Illuminate\View\View; use Log; /** @@ -37,6 +39,7 @@ class ConfigurationController extends Controller { /** * ConfigurationController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -45,7 +48,7 @@ class ConfigurationController extends Controller $this->middleware( static function ($request, $next) { - app('view')->share('title', (string)trans('firefly.administration')); + app('view')->share('title', (string) trans('firefly.administration')); app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); return $next($request); @@ -58,11 +61,11 @@ class ConfigurationController extends Controller /** * Show configuration index. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { - $subTitle = (string)trans('firefly.instance_configuration'); + $subTitle = (string) trans('firefly.instance_configuration'); $subTitleIcon = 'fa-wrench'; Log::channel('audit')->info('User visits admin config index.'); @@ -98,7 +101,7 @@ class ConfigurationController extends Controller app('fireflyconfig')->set('is_demo_site', $data['is_demo_site']); // flash message - session()->flash('success', (string)trans('firefly.configuration_updated')); + session()->flash('success', (string) trans('firefly.configuration_updated')); app('preferences')->mark(); return redirect()->route('admin.configuration.index'); diff --git a/app/Http/Controllers/Admin/HomeController.php b/app/Http/Controllers/Admin/HomeController.php index efb892300f..5c3366037f 100644 --- a/app/Http/Controllers/Admin/HomeController.php +++ b/app/Http/Controllers/Admin/HomeController.php @@ -27,7 +27,11 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\IsSandStormUser; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** @@ -37,6 +41,7 @@ class HomeController extends Controller { /** * ConfigurationController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -49,14 +54,14 @@ class HomeController extends Controller /** * Index of the admin. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { Log::channel('audit')->info('User visits admin index.'); - $title = (string)trans('firefly.administration'); + $title = (string) trans('firefly.administration'); $mainTitleIcon = 'fa-hand-spock-o'; - $sandstorm = 1 === (int)getenv('SANDSTORM'); + $sandstorm = 1 === (int) getenv('SANDSTORM'); return view('admin.index', compact('title', 'mainTitleIcon', 'sandstorm')); } @@ -66,7 +71,7 @@ class HomeController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function testMessage(Request $request) { @@ -76,7 +81,7 @@ class HomeController extends Controller $ipAddress = $request->ip(); Log::debug(sprintf('Now in testMessage() controller. IP is %s', $ipAddress)); event(new AdminRequestedTestMessage($user, $ipAddress)); - session()->flash('info', (string)trans('firefly.send_test_triggered')); + session()->flash('info', (string) trans('firefly.send_test_triggered')); return redirect(route('admin.index')); } diff --git a/app/Http/Controllers/Admin/LinkController.php b/app/Http/Controllers/Admin/LinkController.php index 370aa8c564..134943c4e1 100644 --- a/app/Http/Controllers/Admin/LinkController.php +++ b/app/Http/Controllers/Admin/LinkController.php @@ -27,7 +27,10 @@ use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Requests\LinkTypeFormRequest; use FireflyIII\Models\LinkType; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Log; use View; @@ -42,6 +45,7 @@ class LinkController extends Controller /** * LinkController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -50,7 +54,7 @@ class LinkController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.administration')); + app('view')->share('title', (string) trans('firefly.administration')); app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); $this->repository = app(LinkTypeRepositoryInterface::class); @@ -63,13 +67,13 @@ class LinkController extends Controller /** * Make a new link form. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|\Illuminate\View\View */ public function create() { Log::channel('audit')->info('User visits link index.'); - $subTitle = (string)trans('firefly.create_new_link_type'); + $subTitle = (string) trans('firefly.create_new_link_type'); $subTitleIcon = 'fa-link'; // put previous url in session if not redirect from store (not "create another"). @@ -83,25 +87,25 @@ class LinkController extends Controller /** * Delete a link form. * - * @param Request $request + * @param Request $request * @param LinkType $linkType * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function delete(Request $request, LinkType $linkType) { if (!$linkType->editable) { - $request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); + $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); return redirect(route('admin.links.index')); } Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id)); - $subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]); + $subTitle = (string) trans('firefly.delete_link_type', ['name' => $linkType->name]); $otherTypes = $this->repository->get(); $count = $this->repository->countJournals($linkType); $moveTo = []; - $moveTo[0] = (string)trans('firefly.do_not_save_connection'); + $moveTo[0] = (string) trans('firefly.do_not_save_connection'); /** @var LinkType $otherType */ foreach ($otherTypes as $otherType) { @@ -119,19 +123,19 @@ class LinkController extends Controller /** * Actually destroy the link. * - * @param Request $request + * @param Request $request * @param LinkType $linkType * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, LinkType $linkType) { Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id)); $name = $linkType->name; - $moveTo = $this->repository->findNull((int)$request->get('move_link_type_before_delete')); + $moveTo = $this->repository->findNull((int) $request->get('move_link_type_before_delete')); $this->repository->destroy($linkType, $moveTo); - $request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name])); + $request->session()->flash('success', (string) trans('firefly.deleted_link_type', ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('link-types.delete.uri')); @@ -140,19 +144,19 @@ class LinkController extends Controller /** * Edit a link form. * - * @param Request $request + * @param Request $request * @param LinkType $linkType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View + * @return Factory|RedirectResponse|Redirector|\Illuminate\View\View */ public function edit(Request $request, LinkType $linkType) { if (!$linkType->editable) { - $request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); + $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); return redirect(route('admin.links.index')); } - $subTitle = (string)trans('firefly.edit_link_type', ['name' => $linkType->name]); + $subTitle = (string) trans('firefly.edit_link_type', ['name' => $linkType->name]); $subTitleIcon = 'fa-link'; Log::channel('audit')->info(sprintf('User wants to edit link type #%d', $linkType->id)); @@ -169,11 +173,11 @@ class LinkController extends Controller /** * Show index of all links. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|\Illuminate\View\View */ public function index() { - $subTitle = (string)trans('firefly.journal_link_configuration'); + $subTitle = (string) trans('firefly.journal_link_configuration'); $subTitleIcon = 'fa-link'; $linkTypes = $this->repository->get(); @@ -192,11 +196,11 @@ class LinkController extends Controller * * @param LinkType $linkType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|\Illuminate\View\View */ public function show(LinkType $linkType) { - $subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]); + $subTitle = (string) trans('firefly.overview_for_link', ['name' => $linkType->name]); $subTitleIcon = 'fa-link'; $links = $this->repository->getJournalLinks($linkType); @@ -210,7 +214,7 @@ class LinkController extends Controller * * @param LinkTypeFormRequest $request * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function store(LinkTypeFormRequest $request) { @@ -223,9 +227,9 @@ class LinkController extends Controller Log::channel('audit')->info('User stored new link type.', $linkType->toArray()); - $request->session()->flash('success', (string)trans('firefly.stored_new_link_type', ['name' => $linkType->name])); + $request->session()->flash('success', (string) trans('firefly.stored_new_link_type', ['name' => $linkType->name])); $redirect = redirect($this->getPreviousUri('link-types.create.uri')); - 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('link-types.create.fromStore', true); @@ -240,14 +244,14 @@ class LinkController extends Controller * Update an existing link. * * @param LinkTypeFormRequest $request - * @param LinkType $linkType + * @param LinkType $linkType * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function update(LinkTypeFormRequest $request, LinkType $linkType) { if (!$linkType->editable) { - $request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); + $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); return redirect(route('admin.links.index')); } @@ -261,10 +265,10 @@ class LinkController extends Controller Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data); - $request->session()->flash('success', (string)trans('firefly.updated_link_type', ['name' => $linkType->name])); + $request->session()->flash('success', (string) trans('firefly.updated_link_type', ['name' => $linkType->name])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('link-types.edit.uri')); - 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('link-types.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Admin/TelemetryController.php b/app/Http/Controllers/Admin/TelemetryController.php index 0456883e67..b0ac841193 100644 --- a/app/Http/Controllers/Admin/TelemetryController.php +++ b/app/Http/Controllers/Admin/TelemetryController.php @@ -21,8 +21,9 @@ namespace FireflyIII\Http\Controllers\Admin; - use FireflyIII\Http\Controllers\Controller; +use Illuminate\Contracts\View\Factory; +use Illuminate\View\View; /** * Class TelemetryController @@ -35,7 +36,7 @@ class TelemetryController extends Controller $this->middleware( static function ($request, $next) { - app('view')->share('title', (string)trans('firefly.administration')); + app('view')->share('title', (string) trans('firefly.administration')); app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); return $next($request); @@ -59,7 +60,7 @@ class TelemetryController extends Controller public function index() { app('view')->share('subTitleIcon', 'fa-eye'); - app('view')->share('subTitle', (string)trans('firefly.telemetry_admin_index')); + app('view')->share('subTitle', (string) trans('firefly.telemetry_admin_index')); $version = config('firefly.version'); $enabled = config('firefly.telemetry', false); $count = 1; @@ -68,11 +69,10 @@ class TelemetryController extends Controller } /** - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function view() { return view('admin.telemetry.view'); } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Admin/UpdateController.php b/app/Http/Controllers/Admin/UpdateController.php index 620ccb7565..f21d016fda 100644 --- a/app/Http/Controllers/Admin/UpdateController.php +++ b/app/Http/Controllers/Admin/UpdateController.php @@ -27,8 +27,13 @@ use FireflyIII\Helpers\Update\UpdateTrait; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\IsSandStormUser; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class HomeController. @@ -45,7 +50,7 @@ class UpdateController extends Controller parent::__construct(); $this->middleware( static function ($request, $next) { - app('view')->share('title', (string)trans('firefly.administration')); + app('view')->share('title', (string) trans('firefly.administration')); app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); return $next($request); @@ -58,28 +63,28 @@ class UpdateController extends Controller /** * Show page with update options. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \Psr\Container\NotFoundExceptionInterface - * @throws \Psr\Container\ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws ContainerExceptionInterface + * @return Factory|View */ public function index() { - $subTitle = (string)trans('firefly.update_check_title'); + $subTitle = (string) trans('firefly.update_check_title'); $subTitleIcon = 'fa-star'; $permission = app('fireflyconfig')->get('permission_update_check', -1); $channel = app('fireflyconfig')->get('update_channel', 'stable'); $selected = $permission->data; $channelSelected = $channel->data; $options = [ - -1 => (string)trans('firefly.updates_ask_me_later'), - 0 => (string)trans('firefly.updates_do_not_check'), - 1 => (string)trans('firefly.updates_enable_check'), + -1 => (string) trans('firefly.updates_ask_me_later'), + 0 => (string) trans('firefly.updates_do_not_check'), + 1 => (string) trans('firefly.updates_enable_check'), ]; $channelOptions = [ - 'stable' => (string)trans('firefly.update_channel_stable'), - 'beta' => (string)trans('firefly.update_channel_beta'), - 'alpha' => (string)trans('firefly.update_channel_alpha'), + 'stable' => (string) trans('firefly.update_channel_stable'), + 'beta' => (string) trans('firefly.update_channel_beta'), + 'alpha' => (string) trans('firefly.update_channel_alpha'), ]; return view('admin.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options', 'channelSelected', 'channelOptions')); @@ -90,17 +95,17 @@ class UpdateController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function post(Request $request) { - $checkForUpdates = (int)$request->get('check_for_updates'); + $checkForUpdates = (int) $request->get('check_for_updates'); $channel = $request->get('update_channel'); $channel = in_array($channel, ['stable', 'beta', 'alpha'], true) ? $channel : 'stable'; app('fireflyconfig')->set('permission_update_check', $checkForUpdates); app('fireflyconfig')->set('last_update_check', time()); app('fireflyconfig')->set('update_channel', $channel); - session()->flash('success', (string)trans('firefly.configuration_updated')); + session()->flash('success', (string) trans('firefly.configuration_updated')); return redirect(route('admin.update-check')); } @@ -110,7 +115,7 @@ class UpdateController extends Controller */ public function updateCheck(): RedirectResponse { - $release = $this->getLatestRelease(); + $release = $this->getLatestRelease(); session()->flash($release['level'], $release['message']); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 605ce72cb0..0236199d6c 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -28,6 +28,8 @@ use FireflyIII\Http\Middleware\IsSandStormUser; use FireflyIII\Http\Requests\UserFormRequest; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use Log; /** @@ -47,9 +49,10 @@ class UserController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.administration')); + app('view')->share('title', (string) trans('firefly.administration')); app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); $this->repository = app(UserRepositoryInterface::class); + return $next($request); } ); @@ -66,7 +69,7 @@ class UserController extends Controller */ public function delete(User $user) { - $subTitle = (string)trans('firefly.delete_user', ['email' => $user->email]); + $subTitle = (string) trans('firefly.delete_user', ['email' => $user->email]); return view('admin.users.delete', compact('user', 'subTitle')); } @@ -74,14 +77,14 @@ class UserController extends Controller /** * Destroy a user. * - * @param User $user + * @param User $user * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(User $user) { $this->repository->destroy($user); - session()->flash('success', (string)trans('firefly.user_deleted')); + session()->flash('success', (string) trans('firefly.user_deleted')); return redirect(route('admin.users')); } @@ -101,13 +104,13 @@ class UserController extends Controller } session()->forget('users.edit.fromUpdate'); - $subTitle = (string)trans('firefly.edit_user', ['email' => $user->email]); + $subTitle = (string) trans('firefly.edit_user', ['email' => $user->email]); $subTitleIcon = 'fa-user-o'; $codes = [ - '' => (string)trans('firefly.no_block_code'), - 'bounced' => (string)trans('firefly.block_code_bounced'), - 'expired' => (string)trans('firefly.block_code_expired'), - 'email_changed' => (string)trans('firefly.block_code_email_changed'), + '' => (string) trans('firefly.no_block_code'), + 'bounced' => (string) trans('firefly.block_code_bounced'), + 'expired' => (string) trans('firefly.block_code_expired'), + 'email_changed' => (string) trans('firefly.block_code_email_changed'), ]; return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes')); @@ -120,7 +123,7 @@ class UserController extends Controller */ public function index() { - $subTitle = (string)trans('firefly.user_administration'); + $subTitle = (string) trans('firefly.user_administration'); $subTitleIcon = 'fa-users'; $users = $this->repository->all(); @@ -138,32 +141,38 @@ class UserController extends Controller /** * Show single user. * - * @param User $user + * @param User $user * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function show(User $user) { - $title = (string)trans('firefly.administration'); + $title = (string) trans('firefly.administration'); $mainTitleIcon = 'fa-hand-spock-o'; - $subTitle = (string)trans('firefly.single_user_administration', ['email' => $user->email]); + $subTitle = (string) trans('firefly.single_user_administration', ['email' => $user->email]); $subTitleIcon = 'fa-user'; $information = $this->repository->getUserData($user); return view( - 'admin.users.show', compact( - 'title', 'mainTitleIcon', 'subTitle', 'subTitleIcon', 'information', 'user' - ) + 'admin.users.show', + compact( + 'title', + 'mainTitleIcon', + 'subTitle', + 'subTitleIcon', + 'information', + 'user' + ) ); } /** * Update single user. * - * @param UserFormRequest $request - * @param User $user + * @param UserFormRequest $request + * @param User $user * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function update(UserFormRequest $request, User $user) { @@ -178,10 +187,10 @@ class UserController extends Controller $this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']); $this->repository->updateEmail($user, $data['email']); - session()->flash('success', (string)trans('firefly.updated_user', ['email' => $user->email])); + session()->flash('success', (string) trans('firefly.updated_user', ['email' => $user->email])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('users.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart session()->put('users.edit.fromUpdate', true); diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 2b52e55758..211be6430d 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -41,6 +41,7 @@ class AttachmentController extends Controller /** * AttachmentController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -51,7 +52,7 @@ class AttachmentController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-paperclip'); - app('view')->share('title', (string)trans('firefly.attachments')); + app('view')->share('title', (string) trans('firefly.attachments')); $this->repository = app(AttachmentRepositoryInterface::class); return $next($request); @@ -68,7 +69,7 @@ class AttachmentController extends Controller */ public function delete(Attachment $attachment) { - $subTitle = (string)trans('firefly.delete_attachment', ['name' => $attachment->filename]); + $subTitle = (string) trans('firefly.delete_attachment', ['name' => $attachment->filename]); // put previous url in session $this->rememberPreviousUri('attachments.delete.uri'); @@ -79,7 +80,7 @@ class AttachmentController extends Controller /** * Destroy attachment. * - * @param Request $request + * @param Request $request * @param Attachment $attachment * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector @@ -90,7 +91,7 @@ class AttachmentController extends Controller $this->repository->destroy($attachment); - $request->session()->flash('success', (string)trans('firefly.attachment_deleted', ['name' => $name])); + $request->session()->flash('success', (string) trans('firefly.attachment_deleted', ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('attachments.delete.uri')); @@ -101,9 +102,9 @@ class AttachmentController extends Controller * * @param Attachment $attachment * + * @throws FireflyException * @return mixed * - * @throws FireflyException */ public function download(Attachment $attachment) { @@ -132,7 +133,7 @@ class AttachmentController extends Controller /** * Edit an attachment. * - * @param Request $request + * @param Request $request * @param Attachment $attachment * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View @@ -140,7 +141,7 @@ class AttachmentController extends Controller public function edit(Request $request, Attachment $attachment) { $subTitleIcon = 'fa-pencil'; - $subTitle = (string)trans('firefly.edit_attachment', ['name' => $attachment->filename]); + $subTitle = (string) trans('firefly.edit_attachment', ['name' => $attachment->filename]); // put previous url in session if not redirect from store (not "return_to_edit"). if (true !== session('attachments.edit.fromUpdate')) { @@ -179,7 +180,7 @@ class AttachmentController extends Controller * Update attachment. * * @param AttachmentFormRequest $request - * @param Attachment $attachment + * @param Attachment $attachment * * @return RedirectResponse */ @@ -188,11 +189,11 @@ class AttachmentController extends Controller $data = $request->getAttachmentData(); $this->repository->update($attachment, $data); - $request->session()->flash('success', (string)trans('firefly.attachment_updated', ['name' => $attachment->filename])); + $request->session()->flash('success', (string) trans('firefly.attachment_updated', ['name' => $attachment->filename])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('attachments.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart $request->session()->put('attachments.edit.fromUpdate', true); @@ -209,8 +210,8 @@ class AttachmentController extends Controller * * @param Attachment $attachment * - * @return LaravelResponse * @throws FireflyException + * @return LaravelResponse */ public function view(Request $request, Attachment $attachment): LaravelResponse { @@ -231,11 +232,13 @@ class AttachmentController extends Controller ]; return response()->make( - $content, 200, [ - 'Content-Security-Policy' => implode('; ', $csp), - 'Content-Type' => $attachment->mime, - 'Content-Disposition' => 'inline; filename="' . $attachment->filename . '"', - ] + $content, + 200, + [ + 'Content-Security-Policy' => implode('; ', $csp), + 'Content-Type' => $attachment->mime, + 'Content-Disposition' => 'inline; filename="' . $attachment->filename . '"', + ] ); } throw new FireflyException('Could not find the indicated attachment. The file is no longer there.'); diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index a26156997b..d45cb00d97 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -26,13 +26,18 @@ namespace FireflyIII\Http\Controllers\Auth; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; +use Illuminate\View\View; use Log; /** * Class ForgotPasswordController + * * @codeCoverageIgnore */ class ForgotPasswordController extends Controller @@ -51,11 +56,11 @@ class ForgotPasswordController extends Controller /** * Send a reset link to the given user. * - * @param \Illuminate\Http\Request $request + * @param Request $request * - * @param UserRepositoryInterface $repository + * @param UserRepositoryInterface $repository * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse + * @return RedirectResponse|JsonResponse */ public function sendResetLinkEmail(Request $request, UserRepositoryInterface $repository) { @@ -77,7 +82,7 @@ class ForgotPasswordController extends Controller $user = User::where('email', $request->get('email'))->first(); if (null !== $user && $repository->hasRole($user, 'demo')) { - return back()->withErrors(['email' => (string)trans('firefly.cannot_reset_demo_user')]); + return back()->withErrors(['email' => (string) trans('firefly.cannot_reset_demo_user')]); } // We will send the password reset link to this user. Once we have attempted @@ -99,7 +104,7 @@ class ForgotPasswordController extends Controller * * @codeCoverageIgnore * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function showLinkRequestForm() { @@ -114,7 +119,7 @@ class ForgotPasswordController extends Controller $singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $userCount = User::count(); $allowRegistration = true; - $pageTitle = (string)trans('firefly.forgot_pw_page_title'); + $pageTitle = (string) trans('firefly.forgot_pw_page_title'); if (true === $singleUserMode && $userCount > 0) { $allowRegistration = false; } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b35328dc67..1b6ee69d60 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -26,10 +26,15 @@ use Adldap; use DB; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Providers\RouteServiceProvider; +use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; +use Illuminate\View\View; use Log; +use Symfony\Component\HttpFoundation\Response; /** * Class LoginController @@ -66,11 +71,11 @@ class LoginController extends Controller /** * Handle a login request to the application. * - * @param \Illuminate\Http\Request $request + * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse + * @throws ValidationException + * @return RedirectResponse|\Illuminate\Http\Response|JsonResponse * - * @throws \Illuminate\Validation\ValidationException */ public function login(Request $request) { @@ -121,13 +126,13 @@ class LoginController extends Controller /** * Show the application's login form. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View + * @return Factory|\Illuminate\Http\Response|View */ public function showLoginForm(Request $request) { $count = DB::table('users')->count(); $loginProvider = config('firefly.login_provider'); - $title = (string)trans('firefly.login_page_title'); + $title = (string) trans('firefly.login_page_title'); if (0 === $count && 'eloquent' === $loginProvider) { return redirect(route('register')); // @codeCoverageIgnore } @@ -155,11 +160,11 @@ class LoginController extends Controller /** * Get the failed login response instance. * - * @param \Illuminate\Http\Request $request - * - * @return \Symfony\Component\HttpFoundation\Response + * @param Request $request * * @throws ValidationException + * @return Response + * */ protected function sendFailedLoginResponse(Request $request) { diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 88c32c106b..f6671ee5a2 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -28,9 +28,12 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Http\Controllers\CreateStuff; use FireflyIII\Support\Http\Controllers\RequestInformation; use FireflyIII\User; -use Illuminate\Auth\Events\Registered; +use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\RegistersUsers; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** @@ -67,7 +70,7 @@ class RegisterController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View + * @return Factory|RedirectResponse|Redirector|View */ public function register(Request $request) { @@ -97,7 +100,7 @@ class RegisterController extends Controller $this->guard()->login($user); - session()->flash('success', (string)trans('firefly.registered')); + session()->flash('success', (string) trans('firefly.registered')); $this->registered($request, $user); @@ -109,7 +112,7 @@ class RegisterController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function showRegistrationForm(Request $request) { @@ -118,7 +121,7 @@ class RegisterController extends Controller $isDemoSite = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site'))->data; $singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $userCount = User::count(); - $pageTitle = (string)trans('firefly.register_page_title'); + $pageTitle = (string) trans('firefly.register_page_title'); if (true === $isDemoSite) { $allowRegistration = false; diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 4b9372e896..da141ca67b 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -25,9 +25,13 @@ namespace FireflyIII\Http\Controllers\Auth; use FireflyIII\Http\Controllers\Controller; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\ResetsPasswords; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Password; +use Illuminate\View\View; /** * Class ResetPasswordController @@ -61,10 +65,10 @@ class ResetPasswordController extends Controller /** * Reset the given user's password. * - * @param \Illuminate\Http\Request $request + * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse * @throws \Illuminate\Validation\ValidationException + * @return RedirectResponse|JsonResponse */ public function reset(Request $request) { @@ -87,9 +91,10 @@ class ResetPasswordController extends Controller // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( - $this->credentials($request), function ($user, $password) { - $this->resetPassword($user, $password); - } + $this->credentials($request), + function ($user, $password) { + $this->resetPassword($user, $password); + } ); // If the password was successfully reset, we will redirect the user back to @@ -105,10 +110,10 @@ class ResetPasswordController extends Controller * * If no token is present, display the link request form. * - * @param Request $request - * @param string|null $token + * @param Request $request + * @param string|null $token * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function showResetForm(Request $request, $token = null) { @@ -123,7 +128,7 @@ class ResetPasswordController extends Controller $singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $userCount = User::count(); $allowRegistration = true; - $pageTitle = (string)trans('firefly.reset_pw_page_title'); + $pageTitle = (string) trans('firefly.reset_pw_page_title'); if (true === $singleUserMode && $userCount > 0) { $allowRegistration = false; } diff --git a/app/Http/Controllers/Auth/TwoFactorController.php b/app/Http/Controllers/Auth/TwoFactorController.php index 3f0ea68425..a0ed675119 100644 --- a/app/Http/Controllers/Auth/TwoFactorController.php +++ b/app/Http/Controllers/Auth/TwoFactorController.php @@ -24,8 +24,9 @@ namespace FireflyIII\Http\Controllers\Auth; use FireflyIII\Http\Controllers\Controller; use FireflyIII\User; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Log; +use Illuminate\Routing\Redirector; use PragmaRX\Google2FALaravel\Support\Authenticator; use Preferences; @@ -44,14 +45,15 @@ class TwoFactorController extends Controller /** @var User $user */ $user = auth()->user(); $siteOwner = config('firefly.site_owner'); - $title = (string)trans('firefly.two_factor_forgot_title'); + $title = (string) trans('firefly.two_factor_forgot_title'); + return view('auth.lost-two-factor', compact('user', 'siteOwner', 'title')); } /** * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function submitMFA(Request $request) { diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index c41b5cbc4d..dd20530567 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -34,14 +34,17 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\TransactionRules\TransactionMatcher; use FireflyIII\Transformers\AttachmentTransformer; use FireflyIII\Transformers\BillTransformer; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use League\Fractal\Manager; use League\Fractal\Resource\Item; use League\Fractal\Serializer\DataArraySerializer; -use Symfony\Component\HttpFoundation\ParameterBag; use Log; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Class BillController. @@ -71,7 +74,7 @@ class BillController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.bills')); + app('view')->share('title', (string) trans('firefly.bills')); app('view')->share('mainTitleIcon', 'fa-calendar-o'); $this->attachments = app(AttachmentHelperInterface::class); $this->billRepository = app(BillRepositoryInterface::class); @@ -86,7 +89,7 @@ class BillController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request) { @@ -94,9 +97,9 @@ class BillController extends Controller /** @var array $billPeriods */ $billPeriods = config('firefly.bill_periods'); foreach ($billPeriods as $current) { - $periods[$current] = strtolower((string)trans('firefly.repeat_freq_' . $current)); + $periods[$current] = strtolower((string) trans('firefly.repeat_freq_' . $current)); } - $subTitle = (string)trans('firefly.create_new_bill'); + $subTitle = (string) trans('firefly.create_new_bill'); $defaultCurrency = app('amount')->getDefaultCurrency(); // put previous url in session if not redirect from store (not "create another"). @@ -113,13 +116,13 @@ class BillController extends Controller * * @param Bill $bill * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function delete(Bill $bill) { // put previous url in session $this->rememberPreviousUri('bills.delete.uri'); - $subTitle = (string)trans('firefly.delete_bill', ['name' => $bill->name]); + $subTitle = (string) trans('firefly.delete_bill', ['name' => $bill->name]); return view('bills.delete', compact('bill', 'subTitle')); } @@ -130,14 +133,14 @@ class BillController extends Controller * @param Request $request * @param Bill $bill * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, Bill $bill) { $name = $bill->name; $this->billRepository->destroy($bill); - $request->session()->flash('success', (string)trans('firefly.deleted_bill', ['name' => $name])); + $request->session()->flash('success', (string) trans('firefly.deleted_bill', ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('bills.delete.uri')); @@ -149,7 +152,7 @@ class BillController extends Controller * @param Request $request * @param Bill $bill * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(Request $request, Bill $bill) { @@ -158,10 +161,10 @@ class BillController extends Controller $billPeriods = config('firefly.bill_periods'); foreach ($billPeriods as $current) { - $periods[$current] = (string)trans('firefly.' . $current); + $periods[$current] = (string) trans('firefly.' . $current); } - $subTitle = (string)trans('firefly.edit_bill', ['name' => $bill->name]); + $subTitle = (string) trans('firefly.edit_bill', ['name' => $bill->name]); // put previous url in session if not redirect from store (not "return_to_edit"). if (true !== session('bills.edit.fromUpdate')) { @@ -169,8 +172,8 @@ class BillController extends Controller } $currency = app('amount')->getDefaultCurrency(); - $bill->amount_min = round((float)$bill->amount_min, $currency->decimal_places); - $bill->amount_max = round((float)$bill->amount_max, $currency->decimal_places); + $bill->amount_min = round((float) $bill->amount_min, $currency->decimal_places); + $bill->amount_max = round((float) $bill->amount_max, $currency->decimal_places); $defaultCurrency = app('amount')->getDefaultCurrency(); // code to handle active-checkboxes @@ -179,7 +182,7 @@ class BillController extends Controller $preFilled = [ 'notes' => $this->billRepository->getNoteText($bill), 'transaction_currency_id' => $bill->transaction_currency_id, - 'active' => $hasOldInput ? (bool)$request->old('active') : $bill->active, + 'active' => $hasOldInput ? (bool) $request->old('active') : $bill->active, ]; $request->session()->flash('preFilled', $preFilled); @@ -191,7 +194,7 @@ class BillController extends Controller /** * Show all bills. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { @@ -244,14 +247,14 @@ class BillController extends Controller * @param Request $request * @param Bill $bill * - * @return RedirectResponse|\Illuminate\Routing\Redirector - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException + * @return RedirectResponse|Redirector */ public function rescan(Request $request, Bill $bill) { $total = 0; if (false === $bill->active) { - $request->session()->flash('warning', (string)trans('firefly.cannot_scan_inactive_bill')); + $request->session()->flash('warning', (string) trans('firefly.cannot_scan_inactive_bill')); return redirect(route('bills.show', [$bill->id])); } @@ -261,7 +264,7 @@ class BillController extends Controller $total = 0; } if (0 === $set->count()) { - $request->session()->flash('error', (string)trans('firefly.no_rules_for_bill')); + $request->session()->flash('error', (string) trans('firefly.no_rules_for_bill')); return redirect(route('bills.show', [$bill->id])); } @@ -282,7 +285,7 @@ class BillController extends Controller } - $request->session()->flash('success', (string)trans('firefly.rescanned_bill', ['total' => $total])); + $request->session()->flash('success', (string) trans('firefly.rescanned_bill', ['total' => $total])); app('preferences')->mark(); return redirect(route('bills.show', [$bill->id])); @@ -294,7 +297,7 @@ class BillController extends Controller * @param Request $request * @param Bill $bill * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function show(Request $request, Bill $bill) { @@ -306,8 +309,8 @@ class BillController extends Controller /** @var Carbon $end */ $end = session('end'); $year = $start->year; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $yearAverage = $this->billRepository->getYearAverage($bill, $start); $overallAverage = $this->billRepository->getOverallAverage($bill); $manager = new Manager(); @@ -372,11 +375,11 @@ class BillController extends Controller $bill = $this->billRepository->store($billData); } catch (FireflyException $e) { Log::error($e->getMessage()); - $request->session()->flash('error', (string)trans('firefly.bill_store_error')); + $request->session()->flash('error', (string) trans('firefly.bill_store_error')); return redirect(route('bills.create'))->withInput(); } - $request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name])); + $request->session()->flash('success', (string) trans('firefly.stored_new_bill', ['name' => $bill->name])); app('preferences')->mark(); /** @var array $files */ @@ -403,7 +406,7 @@ class BillController extends Controller $billData = $request->getBillData(); $bill = $this->billRepository->update($bill, $billData); - $request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name])); + $request->session()->flash('success', (string) trans('firefly.updated_bill', ['name' => $bill->name])); app('preferences')->mark(); /** @var array $files */ @@ -416,7 +419,7 @@ class BillController extends Controller } $redirect = redirect($this->getPreviousUri('bills.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart $request->session()->put('bills.edit.fromUpdate', true); @@ -455,8 +458,8 @@ class BillController extends Controller 'avg' => '0', ]; - $avg = bcdiv(bcadd((string)$bill['amount_min'], (string)$bill['amount_max']), '2'); - $avg = bcmul($avg, (string)count($bill['pay_dates'])); + $avg = bcdiv(bcadd((string) $bill['amount_min'], (string) $bill['amount_max']), '2'); + $avg = bcmul($avg, (string) count($bill['pay_dates'])); $sums[$currencyId]['avg'] = bcadd($sums[$currencyId]['avg'], $avg); } diff --git a/app/Http/Controllers/Budget/AvailableBudgetController.php b/app/Http/Controllers/Budget/AvailableBudgetController.php index 57e5b1c4ab..9458546129 100644 --- a/app/Http/Controllers/Budget/AvailableBudgetController.php +++ b/app/Http/Controllers/Budget/AvailableBudgetController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; - use Carbon\Carbon; use Carbon\Exceptions\InvalidDateException; use FireflyIII\Http\Controllers\Controller; @@ -31,7 +30,11 @@ use FireflyIII\Models\AvailableBudget; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** @@ -55,7 +58,7 @@ class AvailableBudgetController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->abRepository = app(AvailableBudgetRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); @@ -75,7 +78,7 @@ class AvailableBudgetController extends Controller * @param Carbon $end * @param TransactionCurrency|null $currency * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View + * @return Factory|RedirectResponse|Redirector|View */ public function create(Request $request, Carbon $start, Carbon $end, ?TransactionCurrency $currency = null) { @@ -92,7 +95,7 @@ class AvailableBudgetController extends Controller return redirect(route('available-budgets.edit', [$first->id])); } - $page = (int)($request->get('page') ?? 1); + $page = (int) ($request->get('page') ?? 1); return view('budgets.available-budgets.create', compact('start', 'end', 'page', 'currency')); } @@ -104,7 +107,7 @@ class AvailableBudgetController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function createAlternative(Request $request, Carbon $start, Carbon $end) { @@ -126,7 +129,7 @@ class AvailableBudgetController extends Controller ); - $page = (int)($request->get('page') ?? 1); + $page = (int) ($request->get('page') ?? 1); return view('budgets.available-budgets.create-alternative', compact('start', 'end', 'page', 'currencies')); } @@ -134,7 +137,7 @@ class AvailableBudgetController extends Controller /** * @param AvailableBudget $availableBudget * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function delete(AvailableBudget $availableBudget) { @@ -150,17 +153,17 @@ class AvailableBudgetController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end) { - return view('budgets.available-budgets.edit', compact('availableBudget','start','end')); + return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end')); } /** * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(Request $request) { @@ -174,7 +177,7 @@ class AvailableBudgetController extends Controller Log::info($e->getMessage()); } // find currency - $currency = $this->currencyRepos->find((int)$request->get('currency_id')); + $currency = $this->currencyRepos->find((int) $request->get('currency_id')); if (null === $currency) { session()->flash('error', trans('firefly.invalid_currency')); @@ -209,7 +212,7 @@ class AvailableBudgetController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end) { @@ -218,5 +221,4 @@ class AvailableBudgetController extends Controller return redirect(route('budgets.index', [$start->format('Y-m-d'), $end->format('Y-m-d')])); } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Budget/BudgetLimitController.php b/app/Http/Controllers/Budget/BudgetLimitController.php index 800c5ed0b4..5e528faf61 100644 --- a/app/Http/Controllers/Budget/BudgetLimitController.php +++ b/app/Http/Controllers/Budget/BudgetLimitController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; - use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -36,9 +35,13 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\DateCalculation; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -66,7 +69,7 @@ class BudgetLimitController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); @@ -83,7 +86,7 @@ class BudgetLimitController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Budget $budget, Carbon $start, Carbon $end) { @@ -111,7 +114,7 @@ class BudgetLimitController extends Controller * @param Request $request * @param BudgetLimit $budgetLimit * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function delete(Request $request, BudgetLimit $budgetLimit) { @@ -124,14 +127,14 @@ class BudgetLimitController extends Controller /** * @param Request $request * - * @return JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws FireflyException + * @return JsonResponse|RedirectResponse|Redirector */ public function store(Request $request) { // first search for existing one and update it if necessary. - $currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id')); - $budget = $this->repository->findNull((int)$request->get('budget_id')); + $currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id')); + $budget = $this->repository->findNull((int) $request->get('budget_id')); if (null === $currency || null === $budget) { throw new FireflyException('No valid currency or budget.'); } @@ -169,7 +172,7 @@ class BudgetLimitController extends Controller $array['spent'] = $spentArr[$currency->id]['sum'] ?? '0'; $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); - $array['days_left'] = (string)$this->activeDaysLeft($start, $end); + $array['days_left'] = (string) $this->activeDaysLeft($start, $end); // left per day: $array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']); @@ -196,12 +199,16 @@ class BudgetLimitController extends Controller $array = $limit->toArray(); $spentArr = $this->opsRepository->sumExpenses( - $limit->start_date, $limit->end_date, null, new Collection([$budgetLimit->budget]), $budgetLimit->transactionCurrency + $limit->start_date, + $limit->end_date, + null, + new Collection([$budgetLimit->budget]), + $budgetLimit->transactionCurrency ); $array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0'; $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); - $array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date); + $array['days_left'] = (string) $this->activeDaysLeft($limit->start_date, $limit->end_date); // left per day: $array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']); @@ -210,7 +217,5 @@ class BudgetLimitController extends Controller $array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']); return response()->json($array); - } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Budget/CreateController.php b/app/Http/Controllers/Budget/CreateController.php index b4b203e2a4..607e3ea84e 100644 --- a/app/Http/Controllers/Budget/CreateController.php +++ b/app/Http/Controllers/Budget/CreateController.php @@ -24,12 +24,14 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; -use FireflyIII\Models\AutoBudget; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\BudgetFormStoreRequest; +use FireflyIII\Models\AutoBudget; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\View\View; /** * Class CreateController @@ -41,6 +43,7 @@ class CreateController extends Controller /** * CreateController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -50,7 +53,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); @@ -65,31 +68,31 @@ class CreateController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request) { $hasOldInput = null !== $request->old('_token'); // auto budget types - $autoBudgetTypes = [ - 0 => (string)trans('firefly.auto_budget_none'), - AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), - AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), + $autoBudgetTypes = [ + 0 => (string) trans('firefly.auto_budget_none'), + AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'), + AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'), ]; $autoBudgetPeriods = [ - 'daily' => (string)trans('firefly.auto_budget_period_daily'), - 'weekly' => (string)trans('firefly.auto_budget_period_weekly'), - 'monthly' => (string)trans('firefly.auto_budget_period_monthly'), - 'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'), - 'half_year' => (string)trans('firefly.auto_budget_period_half_year'), - 'yearly' => (string)trans('firefly.auto_budget_period_yearly'), + 'daily' => (string) trans('firefly.auto_budget_period_daily'), + 'weekly' => (string) trans('firefly.auto_budget_period_weekly'), + 'monthly' => (string) trans('firefly.auto_budget_period_monthly'), + 'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'), + 'half_year' => (string) trans('firefly.auto_budget_period_half_year'), + 'yearly' => (string) trans('firefly.auto_budget_period_yearly'), ]; $currency = app('amount')->getDefaultCurrency(); $preFilled = [ - 'auto_budget_period' => $hasOldInput ? (bool)$request->old('auto_budget_period') : 'monthly', - 'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, + 'auto_budget_period' => $hasOldInput ? (bool) $request->old('auto_budget_period') : 'monthly', + 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id, ]; $request->session()->flash('preFilled', $preFilled); @@ -99,7 +102,7 @@ class CreateController extends Controller $this->rememberPreviousUri('budgets.create.uri'); } $request->session()->forget('budgets.create.fromStore'); - $subTitle = (string)trans('firefly.create_new_budget'); + $subTitle = (string) trans('firefly.create_new_budget'); return view('budgets.create', compact('subTitle', 'autoBudgetTypes', 'autoBudgetPeriods')); } @@ -110,20 +113,20 @@ class CreateController extends Controller * * @param BudgetFormStoreRequest $request * - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ public function store(BudgetFormStoreRequest $request): RedirectResponse { - $data = $request->getBudgetData(); + $data = $request->getBudgetData(); $budget = $this->repository->store($data); $this->repository->cleanupBudgets(); - $request->session()->flash('success', (string)trans('firefly.stored_new_budget', ['name' => $budget->name])); + $request->session()->flash('success', (string) trans('firefly.stored_new_budget', ['name' => $budget->name])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('budgets.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart $request->session()->put('budgets.create.fromStore', true); diff --git a/app/Http/Controllers/Budget/DeleteController.php b/app/Http/Controllers/Budget/DeleteController.php index d6090143d4..442b856fa8 100644 --- a/app/Http/Controllers/Budget/DeleteController.php +++ b/app/Http/Controllers/Budget/DeleteController.php @@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\Budget; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Budget; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * @@ -40,6 +44,7 @@ class DeleteController extends Controller /** * DeleteController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -48,7 +53,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); @@ -63,11 +68,11 @@ class DeleteController extends Controller * * @param Budget $budget * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function delete(Budget $budget) { - $subTitle = (string)trans('firefly.delete_budget', ['name' => $budget->name]); + $subTitle = (string) trans('firefly.delete_budget', ['name' => $budget->name]); // put previous url in session $this->rememberPreviousUri('budgets.delete.uri'); @@ -81,13 +86,13 @@ class DeleteController extends Controller * @param Request $request * @param Budget $budget * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, Budget $budget) { $name = $budget->name; $this->repository->destroy($budget); - $request->session()->flash('success', (string)trans('firefly.deleted_budget', ['name' => $name])); + $request->session()->flash('success', (string) trans('firefly.deleted_budget', ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('budgets.delete.uri')); diff --git a/app/Http/Controllers/Budget/EditController.php b/app/Http/Controllers/Budget/EditController.php index b150d5eb9f..ad79b1cced 100644 --- a/app/Http/Controllers/Budget/EditController.php +++ b/app/Http/Controllers/Budget/EditController.php @@ -29,8 +29,10 @@ use FireflyIII\Http\Requests\BudgetFormUpdateRequest; use FireflyIII\Models\AutoBudget; use FireflyIII\Models\Budget; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\View\View; /** * @@ -43,6 +45,7 @@ class EditController extends Controller /** * EditController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -51,7 +54,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); @@ -66,36 +69,36 @@ class EditController extends Controller * @param Request $request * @param Budget $budget * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(Request $request, Budget $budget) { - $subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]); + $subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]); $autoBudget = $this->repository->getAutoBudget($budget); // auto budget types $autoBudgetTypes = [ - 0 => (string)trans('firefly.auto_budget_none'), - AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), - AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), + 0 => (string) trans('firefly.auto_budget_none'), + AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'), + AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'), ]; $autoBudgetPeriods = [ - 'daily' => (string)trans('firefly.auto_budget_period_daily'), - 'weekly' => (string)trans('firefly.auto_budget_period_weekly'), - 'monthly' => (string)trans('firefly.auto_budget_period_monthly'), - 'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'), - 'half_year' => (string)trans('firefly.auto_budget_period_half_year'), - 'yearly' => (string)trans('firefly.auto_budget_period_yearly'), + 'daily' => (string) trans('firefly.auto_budget_period_daily'), + 'weekly' => (string) trans('firefly.auto_budget_period_weekly'), + 'monthly' => (string) trans('firefly.auto_budget_period_monthly'), + 'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'), + 'half_year' => (string) trans('firefly.auto_budget_period_half_year'), + 'yearly' => (string) trans('firefly.auto_budget_period_yearly'), ]; // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); $currency = app('amount')->getDefaultCurrency(); $preFilled = [ - 'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active, - 'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, + 'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active, + 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id, ]; - if($autoBudget) { + if ($autoBudget) { $preFilled['auto_budget_amount'] = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; } @@ -113,22 +116,22 @@ class EditController extends Controller * Budget update routine. * * @param BudgetFormUpdateRequest $request - * @param Budget $budget + * @param Budget $budget * - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ public function update(BudgetFormUpdateRequest $request, Budget $budget): RedirectResponse { $data = $request->getBudgetData(); $this->repository->update($budget, $data); - $request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name])); + $request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name])); $this->repository->cleanupBudgets(); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('budgets.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart $request->session()->put('budgets.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index 32644396bc..4690f03887 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; - use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\AvailableBudget; @@ -36,9 +35,11 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\DateCalculation; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -47,7 +48,6 @@ use Log; */ class IndexController extends Controller { - use DateCalculation; /** @var AvailableBudgetRepositoryInterface */ private $abRepository; @@ -71,7 +71,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); @@ -94,7 +94,7 @@ class IndexController extends Controller * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(Request $request, Carbon $start = null, Carbon $end = null) { @@ -157,15 +157,15 @@ class IndexController extends Controller // complement budget with budget limits in range, and expenses in currency X in range. /** @var Budget $current */ foreach ($collection as $current) { - $array = $current->toArray(); - $array['spent'] = []; - $array['budgeted'] = []; + $array = $current->toArray(); + $array['spent'] = []; + $array['budgeted'] = []; $array['auto_budget'] = $this->repository->getAutoBudget($current); - $budgetLimits = $this->blRepository->getBudgetLimits($current, $start, $end); + $budgetLimits = $this->blRepository->getBudgetLimits($current, $start, $end); /** @var BudgetLimit $limit */ foreach ($budgetLimits as $limit) { - $currency = $limit->transactionCurrency ?? $defaultCurrency; + $currency = $limit->transactionCurrency ?? $defaultCurrency; $array['budgeted'][] = [ 'id' => $limit->id, 'amount' => round($limit->amount, $currency->decimal_places), @@ -184,7 +184,6 @@ class IndexController extends Controller $array['spent'][$currency->id]['currency_id'] = $currency->id; $array['spent'][$currency->id]['currency_symbol'] = $currency->symbol; $array['spent'][$currency->id]['currency_decimal_places'] = $currency->decimal_places; - } } $budgets[] = $array; @@ -195,18 +194,25 @@ class IndexController extends Controller return view( - 'budgets.index', compact( - 'availableBudgets', - 'budgeted', 'spent', - 'prevLoop', 'nextLoop', - 'budgets', - 'currencies', - 'enableAddButton', - 'periodTitle', - 'defaultCurrency', - 'activeDaysPassed', 'activeDaysLeft', - 'inactive', 'budgets', 'start', 'end' - ) + 'budgets.index', + compact( + 'availableBudgets', + 'budgeted', + 'spent', + 'prevLoop', + 'nextLoop', + 'budgets', + 'currencies', + 'enableAddButton', + 'periodTitle', + 'defaultCurrency', + 'activeDaysPassed', + 'activeDaysLeft', + 'inactive', + 'budgets', + 'start', + 'end' + ) ); } @@ -222,7 +228,7 @@ class IndexController extends Controller $budgetIds = $request->get('budgetIds'); foreach ($budgetIds as $index => $budgetId) { - $budgetId = (int)$budgetId; + $budgetId = (int) $budgetId; $budget = $repository->findNull($budgetId); if (null !== $budget) { Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1)); @@ -232,6 +238,4 @@ class IndexController extends Controller return response()->json(['OK']); } - - } diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index 5577640a39..5676e77660 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -34,7 +34,9 @@ use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Http\Controllers\AugumentData; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; +use Illuminate\View\View; /** * @@ -57,7 +59,7 @@ class ShowController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.budgets')); + app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->journalRepos = app(JournalRepositoryInterface::class); @@ -69,11 +71,11 @@ class ShowController extends Controller /** * Show transactions without a budget. * - * @param Request $request + * @param Request $request * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function noBudget(Request $request, Carbon $start = null, Carbon $end = null) { @@ -92,8 +94,8 @@ class ShowController extends Controller $first = $this->journalRepos->firstNull(); $firstDate = null !== $first ? $first->date : $start; $periods = $this->getNoBudgetPeriodOverview($firstDate, $end); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -110,17 +112,17 @@ class ShowController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function noBudgetAll(Request $request) { - $subTitle = (string)trans('firefly.all_journals_without_budget'); + $subTitle = (string) trans('firefly.all_journals_without_budget'); $first = $this->journalRepos->firstNull(); $start = null === $first ? new Carbon : $first->date; $end = new Carbon; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -137,23 +139,23 @@ class ShowController extends Controller * Show a single budget. * * @param Request $request - * @param Budget $budget + * @param Budget $budget * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function show(Request $request, Budget $budget) { /** @var Carbon $start */ - $allStart = session('first', Carbon::now()->startOfYear()); - $allEnd = new Carbon; + $allStart = session('first', Carbon::now()->startOfYear()); + $allEnd = new Carbon; // use session range: $start = session('start'); - $end = session('end'); + $end = session('end'); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $limits = $this->getLimits($budget, $allStart, $allEnd); $repetition = null; @@ -161,12 +163,12 @@ class ShowController extends Controller /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end)->setBudget($budget) - ->withAccountInformation() - ->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation(); + ->withAccountInformation() + ->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation(); $groups = $collector->getPaginatedGroups(); $groups->setPath(route('budgets.show', [$budget->id])); - $subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]); + $subTitle = (string) trans('firefly.all_journals_for_budget', ['name' => $budget->name]); return view('budgets.show', compact('limits', 'budget', 'repetition', 'groups', 'subTitle')); } @@ -174,12 +176,12 @@ class ShowController extends Controller /** * Show a single budget by a budget limit. * - * @param Request $request - * @param Budget $budget + * @param Request $request + * @param Budget $budget * @param BudgetLimit $budgetLimit * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws FireflyException + * @return Factory|View */ public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit) { @@ -187,14 +189,14 @@ class ShowController extends Controller throw new FireflyException('This budget limit is not part of this budget.'); // @codeCoverageIgnore } - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $subTitle = trans( 'firefly.budget_in_period', [ - 'name' => $budget->name, - 'start' => $budgetLimit->start_date->formatLocalized($this->monthAndDayFormat), - 'end' => $budgetLimit->end_date->formatLocalized($this->monthAndDayFormat), + 'name' => $budget->name, + 'start' => $budgetLimit->start_date->formatLocalized($this->monthAndDayFormat), + 'end' => $budgetLimit->end_date->formatLocalized($this->monthAndDayFormat), 'currency' => $budgetLimit->transactionCurrency->name, ] ); diff --git a/app/Http/Controllers/Category/CreateController.php b/app/Http/Controllers/Category/CreateController.php index fccb666e29..b9990df11c 100644 --- a/app/Http/Controllers/Category/CreateController.php +++ b/app/Http/Controllers/Category/CreateController.php @@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\Category; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class CreateController @@ -39,6 +43,7 @@ class CreateController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -47,7 +52,7 @@ class CreateController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); @@ -62,7 +67,7 @@ class CreateController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request) { @@ -70,7 +75,7 @@ class CreateController extends Controller $this->rememberPreviousUri('categories.create.uri'); } $request->session()->forget('categories.create.fromStore'); - $subTitle = (string)trans('firefly.create_new_category'); + $subTitle = (string) trans('firefly.create_new_category'); return view('categories.create', compact('subTitle')); } @@ -81,18 +86,18 @@ class CreateController extends Controller * * @param CategoryFormRequest $request * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function store(CategoryFormRequest $request) { $data = $request->getCategoryData(); $category = $this->repository->store($data); - $request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name])); + $request->session()->flash('success', (string) trans('firefly.stored_category', ['name' => $category->name])); app('preferences')->mark(); $redirect = redirect(route('categories.index')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart $request->session()->put('categories.create.fromStore', true); diff --git a/app/Http/Controllers/Category/DeleteController.php b/app/Http/Controllers/Category/DeleteController.php index d79a0b2d99..6856243e14 100644 --- a/app/Http/Controllers/Category/DeleteController.php +++ b/app/Http/Controllers/Category/DeleteController.php @@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\Category; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class DeleteController @@ -39,6 +43,7 @@ class DeleteController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -47,7 +52,7 @@ class DeleteController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); @@ -61,11 +66,11 @@ class DeleteController extends Controller * * @param Category $category * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function delete(Category $category) { - $subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]); + $subTitle = (string) trans('firefly.delete_category', ['name' => $category->name]); // put previous url in session $this->rememberPreviousUri('categories.delete.uri'); @@ -79,14 +84,14 @@ class DeleteController extends Controller * @param Request $request * @param Category $category * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, Category $category) { $name = $category->name; $this->repository->destroy($category); - $request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name])); + $request->session()->flash('success', (string) trans('firefly.deleted_category', ['name' => $name])); app('preferences')->mark(); return redirect($this->getPreviousUri('categories.delete.uri')); diff --git a/app/Http/Controllers/Category/EditController.php b/app/Http/Controllers/Category/EditController.php index 6d422c7f74..3a37863f4b 100644 --- a/app/Http/Controllers/Category/EditController.php +++ b/app/Http/Controllers/Category/EditController.php @@ -28,7 +28,11 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class EditController @@ -41,6 +45,7 @@ class EditController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -49,7 +54,7 @@ class EditController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); @@ -65,11 +70,11 @@ class EditController extends Controller * @param Request $request * @param Category $category * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(Request $request, Category $category) { - $subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]); + $subTitle = (string) trans('firefly.edit_category', ['name' => $category->name]); // put previous url in session if not redirect from store (not "return_to_edit"). if (true !== session('categories.edit.fromUpdate')) { @@ -83,22 +88,22 @@ class EditController extends Controller /** * Update category. * - * @param CategoryFormRequest $request - * @param Category $category + * @param CategoryFormRequest $request + * @param Category $category * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function update(CategoryFormRequest $request, Category $category) { $data = $request->getCategoryData(); $this->repository->update($category, $data); - $request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name])); + $request->session()->flash('success', (string) trans('firefly.updated_category', ['name' => $category->name])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('categories.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart $request->session()->put('categories.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Category/IndexController.php b/app/Http/Controllers/Category/IndexController.php index 7cbdf2244a..063d9e6cec 100644 --- a/app/Http/Controllers/Category/IndexController.php +++ b/app/Http/Controllers/Category/IndexController.php @@ -27,9 +27,11 @@ namespace FireflyIII\Http\Controllers\Category; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; +use Illuminate\View\View; /** * Class IndexController @@ -41,6 +43,7 @@ class IndexController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -49,7 +52,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); @@ -59,18 +62,17 @@ class IndexController extends Controller } - /** * Show all categories. * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ 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->repository->getCategories(); $total = $collection->count(); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php index 53dbeb0698..e4ff1bef55 100644 --- a/app/Http/Controllers/Category/NoCategoryController.php +++ b/app/Http/Controllers/Category/NoCategoryController.php @@ -30,8 +30,10 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -46,6 +48,7 @@ class NoCategoryController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -55,7 +58,7 @@ class NoCategoryController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->journalRepos = app(JournalRepositoryInterface::class); @@ -67,11 +70,11 @@ class NoCategoryController extends Controller /** * Show transactions without a category. * - * @param Request $request + * @param Request $request * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function show(Request $request, Carbon $start = null, Carbon $end = null) { @@ -80,8 +83,8 @@ class NoCategoryController extends Controller $start = $start ?? session('start'); /** @var Carbon $end */ $end = $end ?? session('end'); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $subTitle = trans( 'firefly.without_category_between', ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] @@ -95,7 +98,7 @@ class NoCategoryController extends Controller $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end) ->setLimit($pageSize)->setPage($page)->withoutCategory() - ->withAccountInformation()->withBudgetInformation() + ->withAccountInformation()->withBudgetInformation() ->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]); $groups = $collector->getPaginatedGroups(); $groups->setPath(route('categories.no-category')); @@ -109,7 +112,7 @@ class NoCategoryController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function showAll(Request $request) { @@ -117,10 +120,10 @@ class NoCategoryController extends Controller $start = null; $end = null; $periods = new Collection; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; Log::debug('Start of noCategory()'); - $subTitle = (string)trans('firefly.all_journals_without_category'); + $subTitle = (string) trans('firefly.all_journals_without_category'); $first = $this->journalRepos->firstNull(); $start = null === $first ? new Carbon : $first->date; $end = new Carbon; @@ -130,7 +133,7 @@ class NoCategoryController extends Controller /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory() - ->withAccountInformation()->withBudgetInformation() + ->withAccountInformation()->withBudgetInformation() ->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]); $groups = $collector->getPaginatedGroups(); $groups->setPath(route('categories.no-category.all')); diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php index cf2d608d4e..633f5496fe 100644 --- a/app/Http/Controllers/Category/ShowController.php +++ b/app/Http/Controllers/Category/ShowController.php @@ -29,8 +29,10 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Category; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Illuminate\View\View; /** * @@ -45,6 +47,7 @@ class ShowController extends Controller /** * CategoryController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -54,7 +57,7 @@ class ShowController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.categories')); + app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); @@ -64,16 +67,15 @@ class ShowController extends Controller } - /** * Show a single category. * - * @param Request $request - * @param Category $category + * @param Request $request + * @param Category $category * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) { @@ -83,8 +85,8 @@ class ShowController extends Controller /** @var Carbon $end */ $end = $end ?? session('end', Carbon::now()->endOfMonth()); $subTitleIcon = 'fa-bar-chart'; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear(); $periods = $this->getCategoryPeriodOverview($category, $oldest, $end); $path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); @@ -111,22 +113,22 @@ class ShowController extends Controller /** * Show all transactions within a category. * - * @param Request $request + * @param Request $request * @param Category $category * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function showAll(Request $request, Category $category) { // default values: $subTitleIcon = 'fa-bar-chart'; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $start = null; $end = null; $periods = new Collection; - $subTitle = (string)trans('firefly.all_journals_for_category', ['name' => $category->name]); + $subTitle = (string) trans('firefly.all_journals_for_category', ['name' => $category->name]); $first = $this->repository->firstUseDate($category); /** @var Carbon $start */ $start = $first ?? new Carbon; diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 475ce39d7a..825d017c00 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -59,6 +59,7 @@ class AccountController extends Controller /** * AccountController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -116,10 +117,10 @@ class AccountController extends Controller // loop the end balances. This is an array for each account ($expenses) foreach ($endBalances as $accountId => $expenses) { - $accountId = (int)$accountId; + $accountId = (int) $accountId; // loop each expense entry (each entry can be a different currency). foreach ($expenses as $currencyId => $endAmount) { - $currencyId = (int)$currencyId; + $currencyId = (int) $currencyId; // see if there is an accompanying start amount. // grab the difference and find the currency. @@ -131,7 +132,7 @@ class AccountController extends Controller $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float)$diff, + 'diff_float' => (float) $diff, 'currency_id' => $currencyId, ]; } @@ -144,13 +145,13 @@ class AccountController extends Controller // loop all found currencies and build the data array for the chart. /** - * @var int $currencyId + * @var int $currencyId * @var TransactionCurrency $currency */ foreach ($currencies as $currencyId => $currency) { $dataSet = [ - 'label' => (string)trans('firefly.spent'), + 'label' => (string) trans('firefly.spent'), 'type' => 'bar', 'currency_symbol' => $currency->symbol, 'entries' => $this->expandNames($tempData), @@ -171,28 +172,12 @@ class AccountController extends Controller return response()->json($data); } - /** - * Expenses per budget for all time, as shown on account overview. - * - * @param AccountRepositoryInterface $repository - * @param Account $account - * - * @return JsonResponse - */ - public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse - { - $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); - $end = Carbon::now(); - - return $this->expenseBudget($account, $start, $end); - } - /** * Expenses per budget, as shown on account overview. * * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -215,7 +200,7 @@ class AccountController extends Controller $budgetIds = []; /** @var array $journal */ foreach ($journals as $journal) { - $budgetId = (int)$journal['budget_id']; + $budgetId = (int) $journal['budget_id']; $key = sprintf('%d-%d', $budgetId, $journal['currency_id']); $budgetIds[] = $budgetId; if (!isset($result[$key])) { @@ -234,7 +219,7 @@ class AccountController extends Controller foreach ($result as $row) { $budgetId = $row['budget_id']; $name = $names[$budgetId]; - $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']]; } @@ -245,27 +230,27 @@ class AccountController extends Controller } /** - * Expenses grouped by category for account. + * Expenses per budget for all time, as shown on account overview. * * @param AccountRepositoryInterface $repository - * @param Account $account + * @param Account $account * * @return JsonResponse */ - public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse + public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse { $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); $end = Carbon::now(); - return $this->expenseCategory($account, $start, $end); + return $this->expenseBudget($account, $start, $end); } /** * Expenses per category for one single account. * * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -283,9 +268,9 @@ class AccountController extends Controller /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]); - $journals = $collector->getExtractedJournals(); - $result = []; - $chartData = []; + $journals = $collector->getExtractedJournals(); + $result = []; + $chartData = []; /** @var array $journal */ foreach ($journals as $journal) { @@ -293,7 +278,7 @@ class AccountController extends Controller if (!isset($result[$key])) { $result[$key] = [ 'total' => '0', - 'category_id' => (int)$journal['category_id'], + 'category_id' => (int) $journal['category_id'], 'currency_name' => $journal['currency_name'], 'currency_symbol' => $journal['currency_symbol'], ]; @@ -305,7 +290,7 @@ class AccountController extends Controller foreach ($result as $row) { $categoryId = $row['category_id']; $name = $names[$categoryId] ?? '(unknown)'; - $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']]; } @@ -315,6 +300,22 @@ class AccountController extends Controller return response()->json($data); } + /** + * Expenses grouped by category for account. + * + * @param AccountRepositoryInterface $repository + * @param Account $account + * + * @return JsonResponse + */ + public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse + { + $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); + $end = Carbon::now(); + + return $this->expenseCategory($account, $start, $end); + } + /** * Shows the balances for all the user's frontpage accounts. * @@ -341,28 +342,12 @@ class AccountController extends Controller return response()->json($this->accountBalanceChart($accounts, $start, $end)); } - /** - * Shows the income grouped by category for an account, in all time. - * - * @param AccountRepositoryInterface $repository - * @param Account $account - * - * @return JsonResponse - */ - public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse - { - $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); - $end = Carbon::now(); - - return $this->incomeCategory($account, $start, $end); - } - /** * Shows all income per account for each category. * * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -382,9 +367,9 @@ class AccountController extends Controller $collector = app(GroupCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]); - $journals = $collector->getExtractedJournals(); - $result = []; - $chartData = []; + $journals = $collector->getExtractedJournals(); + $result = []; + $chartData = []; /** @var array $journal */ foreach ($journals as $journal) { $key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']); @@ -403,7 +388,7 @@ class AccountController extends Controller foreach ($result as $row) { $categoryId = $row['category_id']; $name = $names[$categoryId] ?? '(unknown)'; - $label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); + $label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]); $chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']]; } $data = $this->generator->multiCurrencyPieChart($chartData); @@ -412,15 +397,31 @@ class AccountController extends Controller return response()->json($data); } + /** + * Shows the income grouped by category for an account, in all time. + * + * @param AccountRepositoryInterface $repository + * @param Account $account + * + * @return JsonResponse + */ + public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse + { + $start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); + $end = Carbon::now(); + + return $this->incomeCategory($account, $start, $end); + } + /** * Shows overview of account during a single period. * * TODO this chart is not multi-currency aware. * * @param Account $account - * @param Carbon $start + * @param Carbon $start * - * @param Carbon $end + * @param Carbon $end * * @return JsonResponse */ @@ -440,14 +441,14 @@ class AccountController extends Controller $current = clone $start; switch ($step) { case '1D': - $format = (string)trans('config.month_and_day'); + $format = (string) trans('config.month_and_day'); $range = app('steam')->balanceInRange($account, $start, $end); $previous = array_values($range)[0]; while ($end >= $current) { $theDate = $current->format('Y-m-d'); $balance = $range[$theDate] ?? $previous; $label = $current->formatLocalized($format); - $chartData[$label] = (float)$balance; + $chartData[$label] = (float) $balance; $previous = $balance; $current->addDay(); } @@ -457,7 +458,7 @@ class AccountController extends Controller case '1M': case '1Y': while ($end >= $current) { - $balance = (float)app('steam')->balance($account, $current); + $balance = (float) app('steam')->balance($account, $current); $label = app('navigation')->periodShow($current, $step); $chartData[$label] = $balance; $current = app('navigation')->addPeriod($current, $step, 0); @@ -476,8 +477,8 @@ class AccountController extends Controller * * TODO this chart is not multi-currency aware. * - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * @param Collection $accounts * * @return JsonResponse @@ -525,10 +526,10 @@ class AccountController extends Controller // loop the end balances. This is an array for each account ($expenses) foreach ($endBalances as $accountId => $expenses) { - $accountId = (int)$accountId; + $accountId = (int) $accountId; // loop each expense entry (each entry can be a different currency). foreach ($expenses as $currencyId => $endAmount) { - $currencyId = (int)$currencyId; + $currencyId = (int) $currencyId; // see if there is an accompanying start amount. // grab the difference and find the currency. @@ -540,7 +541,7 @@ class AccountController extends Controller $tempData[] = [ 'name' => $accountNames[$accountId], 'difference' => $diff, - 'diff_float' => (float)$diff, + 'diff_float' => (float) $diff, 'currency_id' => $currencyId, ]; } @@ -553,13 +554,13 @@ class AccountController extends Controller // loop all found currencies and build the data array for the chart. /** - * @var int $currencyId + * @var int $currencyId * @var TransactionCurrency $currency */ foreach ($currencies as $currencyId => $currency) { $dataSet = [ - 'label' => (string)trans('firefly.earned'), + 'label' => (string) trans('firefly.earned'), 'type' => 'bar', 'currency_symbol' => $currency->symbol, 'entries' => $this->expandNames($tempData), diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index 9909ef07f7..b817da0147 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -42,6 +42,7 @@ class BillController extends Controller /** * BillController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -79,12 +80,12 @@ class BillController extends Controller foreach ($paid as $currencyId => $amount) { $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId); - $label = (string)trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]); + $label = (string) trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]); $chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol]; } foreach ($unpaid as $currencyId => $amount) { $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId); - $label = (string)trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]); + $label = (string) trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]); $chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol]; } @@ -116,18 +117,21 @@ class BillController extends Controller $journals = $collector->setBill($bill)->getExtractedJournals(); // sort the other way around: - usort($journals, static function (array $left, array $right) { - return $left['date']->gte($right['date'])? 1 : 0; - }); + usort( + $journals, + static function (array $left, array $right) { + return $left['date']->gte($right['date']) ? 1 : 0; + } + ); $chartData = [ - ['type' => 'line', 'label' => (string)trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], - ['type' => 'line', 'label' => (string)trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], - ['type' => 'bar', 'label' => (string)trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], + ['type' => 'line', 'label' => (string) trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], + ['type' => 'line', 'label' => (string) trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], + ['type' => 'bar', 'label' => (string) trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []], ]; foreach ($journals as $journal) { - $date = $journal['date']->formatLocalized((string)trans('config.month_and_day')); + $date = $journal['date']->formatLocalized((string) trans('config.month_and_day')); $chartData[0]['entries'][$date] = $bill->amount_min; // minimum amount of bill $chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 295aa232a7..b83692f914 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -27,9 +27,9 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; -use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\Budget; use FireflyIII\Models\BudgetLimit; +use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; @@ -104,11 +104,11 @@ class BudgetController extends Controller if ($cache->has()) { return response()->json($cache->get()); // @codeCoverageIgnore } - $step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart. - $collection = new Collection([$budget]); - $chartData = []; - $loopStart = clone $start; - $loopStart = app('navigation')->startOfPeriod($loopStart, $step); + $step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart. + $collection = new Collection([$budget]); + $chartData = []; + $loopStart = clone $start; + $loopStart = app('navigation')->startOfPeriod($loopStart, $step); $currencies = []; $defaultEntries = []; // echo '
'; @@ -135,10 +135,10 @@ class BudgetController extends Controller // loop all currencies: foreach ($currencies as $currencyId => $currency) { $chartData[$currencyId] = [ - 'label' => count($currencies) > 1 ? sprintf('%s (%s)', $budget->name, $currency['currency_name']) : $budget->name, - 'type' => 'bar', + 'label' => count($currencies) > 1 ? sprintf('%s (%s)', $budget->name, $currency['currency_name']) : $budget->name, + 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], - 'entries' => $defaultEntries, + 'entries' => $defaultEntries, ]; foreach ($currency['spent'] as $label => $spent) { $chartData[$currencyId]['entries'][$label] = round(bcmul($spent, '-1'), $currency['currency_decimal_places']); @@ -157,9 +157,9 @@ class BudgetController extends Controller * @param Budget $budget * @param BudgetLimit $budgetLimit * + * @throws FireflyException * @return JsonResponse * - * @throws FireflyException */ public function budgetLimit(Budget $budget, BudgetLimit $budgetLimit): JsonResponse { @@ -186,12 +186,12 @@ class BudgetController extends Controller while ($start <= $end) { $spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start); $amount = bcadd($amount, $spent); - $format = $start->formatLocalized((string)trans('config.month_and_day')); + $format = $start->formatLocalized((string) trans('config.month_and_day')); $entries[$format] = $amount; $start->addDay(); } - $data = $this->generator->singleSet((string)trans('firefly.left'), $entries); + $data = $this->generator->singleSet((string) trans('firefly.left'), $entries); // add currency symbol from budget limit: $data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol; $cache->store($data); @@ -211,7 +211,7 @@ class BudgetController extends Controller public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse { /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id; $cache = new CacheProperties; $cache->addProperty($budget->id); @@ -238,7 +238,7 @@ class BudgetController extends Controller // group by asset account ID: foreach ($journals as $journal) { - $key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']); + $key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']); $result[$key] = $result[$key] ?? [ 'amount' => '0', 'currency_symbol' => $journal['currency_symbol'], @@ -250,7 +250,7 @@ class BudgetController extends Controller $names = $this->getAccountNames(array_keys($result)); foreach ($result as $combinedId => $info) { $parts = explode('-', $combinedId); - $assetId = (int)$parts[0]; + $assetId = (int) $parts[0]; $title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']); $chartData[$title] = [ @@ -277,7 +277,7 @@ class BudgetController extends Controller public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse { /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id; $cache = new CacheProperties; $cache->addProperty($budget->id); @@ -314,7 +314,7 @@ class BudgetController extends Controller $names = $this->getCategoryNames(array_keys($result)); foreach ($result as $combinedId => $info) { $parts = explode('-', $combinedId); - $categoryId = (int)$parts[0]; + $categoryId = (int) $parts[0]; $title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']); $chartData[$title] = [ 'amount' => $info['amount'], @@ -340,7 +340,7 @@ class BudgetController extends Controller public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse { /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $budgetLimitId = null === $budgetLimit ? 0 : $budgetLimit->id; $cache = new CacheProperties; $cache->addProperty($budget->id); @@ -379,7 +379,7 @@ class BudgetController extends Controller $names = $this->getAccountNames(array_keys($result)); foreach ($result as $combinedId => $info) { $parts = explode('-', $combinedId); - $opposingId = (int)$parts[0]; + $opposingId = (int) $parts[0]; $name = $names[$opposingId] ?? 'no name'; $title = sprintf('%s (%s)', $name, $info['currency_name']); $chartData[$title] = [ @@ -418,9 +418,9 @@ class BudgetController extends Controller } $budgets = $this->repository->getActiveBudgets(); $chartData = [ - ['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'], ]; /** @var Budget $budget */ @@ -440,14 +440,20 @@ class BudgetController extends Controller /** @var BudgetLimit $limit */ foreach ($limits as $limit) { $spent = $this->opsRepository->sumExpenses( - $limit->start_date, $limit->end_date, null, new Collection([$budget]), $limit->transactionCurrency + $limit->start_date, + $limit->end_date, + null, + new Collection([$budget]), + $limit->transactionCurrency ); /** @var array $entry */ foreach ($spent as $entry) { $title = sprintf('%s (%s)', $budget->name, $entry['currency_name']); if ($limit->start_date->startOfDay()->ne($start->startOfDay()) || $limit->end_date->startOfDay()->ne($end->startOfDay())) { $title = sprintf( - '%s (%s) (%s - %s)', $budget->name, $entry['currency_name'], + '%s (%s) (%s - %s)', + $budget->name, + $entry['currency_name'], $limit->start_date->formatLocalized($this->monthAndDayFormat), $limit->end_date->formatLocalized($this->monthAndDayFormat) ); @@ -498,13 +504,13 @@ class BudgetController extends Controller $preferredRange = app('navigation')->preferredRangeFormat($start, $end); $chartData = [ [ - 'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]), + 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency->name]), 'type' => 'bar', 'entries' => [], 'currency_symbol' => $currency->symbol, ], [ - 'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]), + 'label' => (string) trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]), 'type' => 'bar', 'currency_symbol' => $currency->symbol, 'entries' => [], @@ -513,9 +519,9 @@ class BudgetController extends Controller $currentStart = clone $start; while ($currentStart <= $end) { - $currentStart= app('navigation')->startOfPeriod($currentStart, $preferredRange); - $title = $currentStart->formatLocalized($titleFormat); - $currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange); + $currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange); + $title = $currentStart->formatLocalized($titleFormat); + $currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange); // default limit is no limit: $chartData[0]['entries'][$title] = 0; @@ -582,11 +588,9 @@ class BudgetController extends Controller $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); } - $data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData); + $data = $this->generator->singleSet((string) trans('firefly.spent'), $chartData); $cache->store($data); return response()->json($data); } - - } diff --git a/app/Http/Controllers/Chart/BudgetReportController.php b/app/Http/Controllers/Chart/BudgetReportController.php index aaca008c5f..5d16a52981 100644 --- a/app/Http/Controllers/Chart/BudgetReportController.php +++ b/app/Http/Controllers/Chart/BudgetReportController.php @@ -18,7 +18,7 @@ * along with this program. If not, see . */ - /** @noinspection MoreThanThreeArgumentsInspection */ +/** @noinspection MoreThanThreeArgumentsInspection */ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Chart; @@ -118,8 +118,6 @@ class BudgetReportController extends Controller // loop expenses. foreach ($spent as $currency) { foreach ($currency['budgets'] as $budget) { - - foreach ($budget['transaction_journals'] as $journal) { $categoryName = $journal['category_name'] ?? trans('firefly.no_category'); $title = sprintf('%s (%s)', $categoryName, $currency['currency_name']); @@ -157,8 +155,6 @@ class BudgetReportController extends Controller // loop expenses. foreach ($spent as $currency) { foreach ($currency['budgets'] as $budget) { - - foreach ($budget['transaction_journals'] as $journal) { $title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']); $result[$title] = $result[$title] ?? [ @@ -199,7 +195,9 @@ class BudgetReportController extends Controller $spentKey = sprintf('%d-spent', $currency['currency_id']); $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -240,8 +238,6 @@ class BudgetReportController extends Controller // loop expenses. foreach ($spent as $currency) { foreach ($currency['budgets'] as $budget) { - - foreach ($budget['transaction_journals'] as $journal) { $title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']); $result[$title] = $result[$title] ?? [ @@ -282,5 +278,4 @@ class BudgetReportController extends Controller return $return; } - } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index ddc6062980..657a982c54 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -191,7 +191,7 @@ class CategoryController extends Controller /** @var array $currency */ foreach ($currencies as $currency) { $dataSet = [ - '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' => $this->expandNames($tempData), @@ -353,7 +353,7 @@ class CategoryController extends Controller if (null !== $category) { /** @var OperationsRepositoryInterface $opsRepository */ $opsRepository = app(OperationsRepositoryInterface::class); - $categoryId = (int)$category->id; + $categoryId = (int) $category->id; // this gives us all currencies $collection = new Collection([$category]); $expenses = $opsRepository->listExpenses($start, $end, null, $collection); @@ -372,7 +372,7 @@ class CategoryController extends Controller $inKey = sprintf('%d-in', $currencyId); $chartData[$outKey] = [ - 'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']), + 'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currencyInfo['currency_name']), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red @@ -380,7 +380,7 @@ class CategoryController extends Controller $chartData[$inKey] = [ - 'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']), + 'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']), 'entries' => [], 'type' => 'bar', 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php index 11847457d3..4ee924d082 100644 --- a/app/Http/Controllers/Chart/CategoryReportController.php +++ b/app/Http/Controllers/Chart/CategoryReportController.php @@ -316,7 +316,9 @@ class CategoryReportController extends Controller $spentKey = sprintf('%d-spent', $currency['currency_id']); $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.spent_in_specific_category', ['category' => $category->name]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.spent_in_specific_category', ['category' => $category->name]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -340,7 +342,9 @@ class CategoryReportController extends Controller $spentKey = sprintf('%d-earned', $currency['currency_id']); $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.earned_in_specific_category', ['category' => $category->name]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.earned_in_specific_category', ['category' => $category->name]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -457,5 +461,4 @@ class CategoryReportController extends Controller return $return; } - } diff --git a/app/Http/Controllers/Chart/DoubleReportController.php b/app/Http/Controllers/Chart/DoubleReportController.php index 309397e997..287a2ff551 100644 --- a/app/Http/Controllers/Chart/DoubleReportController.php +++ b/app/Http/Controllers/Chart/DoubleReportController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Chart; - use Carbon\Carbon; use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Http\Controllers\Controller; @@ -196,7 +195,9 @@ class DoubleReportController extends Controller $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.spent_in_specific_double', ['account' => $name]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.spent_in_specific_double', ['account' => $name]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -210,7 +211,6 @@ class DoubleReportController extends Controller $chartData[$spentKey]['entries'][$key] = $chartData[$spentKey]['entries'][$key] ?? '0'; $chartData[$spentKey]['entries'][$key] = bcadd($chartData[$spentKey]['entries'][$key], $amount); } - } // loop income. foreach ($earned as $currency) { @@ -220,7 +220,9 @@ class DoubleReportController extends Controller $chartData[$earnedKey] = $chartData[$earnedKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.earned_in_specific_double', ['account' => $name]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.earned_in_specific_double', ['account' => $name]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -242,7 +244,6 @@ class DoubleReportController extends Controller } - /** * @param Collection $accounts * @param Collection $others @@ -275,7 +276,6 @@ class DoubleReportController extends Controller ]; $amount = app('steam')->positive($journal['amount']); $result[$title]['amount'] = bcadd($result[$title]['amount'], $amount); - } // loop each tag: /** @var array $tag */ @@ -334,7 +334,6 @@ class DoubleReportController extends Controller ]; $amount = app('steam')->positive($journal['amount']); $result[$title]['amount'] = bcadd($result[$title]['amount'], $amount); - } // loop each tag: /** @var array $tag */ @@ -364,10 +363,10 @@ class DoubleReportController extends Controller /** * TODO this method is double. * - * @param Collection $accounts - * @param int $id - * @param string $name - * @param null|string $iban + * @param Collection $accounts + * @param int $id + * @param string $name + * @param null|string $iban * * @return string */ @@ -410,6 +409,4 @@ class DoubleReportController extends Controller return $return; } - - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php index 61fc1eedc9..59d24800ca 100644 --- a/app/Http/Controllers/Chart/ExpenseReportController.php +++ b/app/Http/Controllers/Chart/ExpenseReportController.php @@ -49,6 +49,7 @@ class ExpenseReportController extends Controller /** * ExpenseReportController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -72,8 +73,8 @@ class ExpenseReportController extends Controller * * @param Collection $accounts * @param Collection $expense - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse * @@ -87,7 +88,7 @@ class ExpenseReportController extends Controller $cache->addProperty($start); $cache->addProperty($end); if ($cache->has()) { - return response()->json($cache->get()); // @codeCoverageIgnore + return response()->json($cache->get()); // @codeCoverageIgnore } $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end); @@ -103,7 +104,7 @@ class ExpenseReportController extends Controller // prep chart data: /** - * @var string $name + * @var string $name * @var Collection $combination */ foreach ($combined as $name => $combination) { @@ -111,27 +112,27 @@ class ExpenseReportController extends Controller /** @var Account $exp */ $exp = $combination->first(); $chartData[$exp->id . '-in'] = [ - 'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.income'))), + 'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.income'))), 'type' => 'bar', 'yAxisID' => 'y-axis-0', 'entries' => [], ]; $chartData[$exp->id . '-out'] = [ - 'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.expenses'))), + 'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.expenses'))), 'type' => 'bar', 'yAxisID' => 'y-axis-0', 'entries' => [], ]; // total in, total out: $chartData[$exp->id . '-total-in'] = [ - 'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_income'))), + 'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.sum_of_income'))), 'type' => 'line', 'fill' => false, 'yAxisID' => 'y-axis-1', 'entries' => [], ]; $chartData[$exp->id . '-total-out'] = [ - 'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_expenses'))), + 'label' => sprintf('%s (%s)', $name, strtolower((string) trans('firefly.sum_of_expenses'))), 'type' => 'line', 'fill' => false, 'yAxisID' => 'y-axis-1', diff --git a/app/Http/Controllers/Chart/PiggyBankController.php b/app/Http/Controllers/Chart/PiggyBankController.php index b99e272b52..72a96d43b7 100644 --- a/app/Http/Controllers/Chart/PiggyBankController.php +++ b/app/Http/Controllers/Chart/PiggyBankController.php @@ -44,6 +44,7 @@ class PiggyBankController extends Controller /** * PiggyBankController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -98,7 +99,7 @@ class PiggyBankController extends Controller } ); $currentSum = $filtered->sum('amount'); - $label = $oldest->formatLocalized((string)trans('config.month_and_day')); + $label = $oldest->formatLocalized((string) trans('config.month_and_day')); $chartData[$label] = $currentSum; $oldest = app('navigation')->addPeriod($oldest, $step, 0); } @@ -109,7 +110,7 @@ class PiggyBankController extends Controller } ); $finalSum = $finalFiltered->sum('amount'); - $finalLabel = $today->formatLocalized((string)trans('config.month_and_day')); + $finalLabel = $today->formatLocalized((string) trans('config.month_and_day')); $chartData[$finalLabel] = $finalSum; $data = $this->generator->singleSet($piggyBank->name, $chartData); diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php index 107116ab0a..79e3d65a7c 100644 --- a/app/Http/Controllers/Chart/ReportController.php +++ b/app/Http/Controllers/Chart/ReportController.php @@ -110,7 +110,7 @@ class ReportController extends Controller /** @var array $netWorthItem */ foreach ($result as $netWorthItem) { $currencyId = $netWorthItem['currency']->id; - $label = $current->formatLocalized((string)trans('config.month_and_day')); + $label = $current->formatLocalized((string) trans('config.month_and_day')); if (!isset($chartData[$currencyId])) { $chartData[$currencyId] = [ 'label' => 'Net worth in ' . $netWorthItem['currency']->name, @@ -138,7 +138,7 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\JsonResponse + * @return JsonResponse */ public function operations(Collection $accounts, Carbon $start, Carbon $end): JsonResponse { @@ -152,10 +152,10 @@ class ReportController extends Controller return response()->json($cache->get()); // @codeCoverageIgnore } Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray()); - $format = app('navigation')->preferredCarbonFormat($start, $end); - $titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end); + $format = app('navigation')->preferredCarbonFormat($start, $end); + $titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end); $preferredRange = app('navigation')->preferredRangeFormat($start, $end); - $ids = $accounts->pluck('id')->toArray(); + $ids = $accounts->pluck('id')->toArray(); // get journals for entire period: $data = []; @@ -173,13 +173,13 @@ class ReportController extends Controller /** @var array $journal */ foreach ($journals as $journal) { $period = $journal['date']->format($format); - $currencyId = (int)$journal['currency_id']; + $currencyId = (int) $journal['currency_id']; $data[$currencyId] = $data[$currencyId] ?? [ 'currency_id' => $currencyId, 'currency_symbol' => $journal['currency_symbol'], 'currency_code' => $journal['currency_code'], 'currency_name' => $journal['currency_name'], - 'currency_decimal_places' => (int)$journal['currency_decimal_places'], + 'currency_decimal_places' => (int) $journal['currency_decimal_places'], ]; $data[$currencyId][$period] = $data[$currencyId][$period] ?? [ 'period' => $period, @@ -211,7 +211,7 @@ class ReportController extends Controller /** @var array $currency */ foreach ($data as $currency) { $income = [ - 'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]), + 'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]), 'type' => 'bar', 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green 'currency_id' => $currency['currency_id'], @@ -219,7 +219,7 @@ class ReportController extends Controller 'entries' => [], ]; $expense = [ - 'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]), + 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]), 'type' => 'bar', 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red 'currency_id' => $currency['currency_id'], @@ -234,7 +234,7 @@ class ReportController extends Controller $title = $currentStart->formatLocalized($titleFormat); $income['entries'][$title] = round($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']); $expense['entries'][$title] = round($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']); - $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); + $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); } $chartData[] = $income; diff --git a/app/Http/Controllers/Chart/TagReportController.php b/app/Http/Controllers/Chart/TagReportController.php index 8603d93afa..9b6f8505fd 100644 --- a/app/Http/Controllers/Chart/TagReportController.php +++ b/app/Http/Controllers/Chart/TagReportController.php @@ -264,7 +264,9 @@ class TagReportController extends Controller $spentKey = sprintf('%d-spent', $currency['currency_id']); $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -288,7 +290,9 @@ class TagReportController extends Controller $spentKey = sprintf('%d-earned', $currency['currency_id']); $chartData[$spentKey] = $chartData[$spentKey] ?? [ 'label' => sprintf( - '%s (%s)', (string)trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]), $currency['currency_name'] + '%s (%s)', + (string) trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]), + $currency['currency_name'] ), 'type' => 'bar', 'currency_symbol' => $currency['currency_symbol'], @@ -475,5 +479,4 @@ class TagReportController extends Controller return $return; } - } diff --git a/app/Http/Controllers/Chart/TransactionController.php b/app/Http/Controllers/Chart/TransactionController.php index 95b3743eb7..1792a002ed 100644 --- a/app/Http/Controllers/Chart/TransactionController.php +++ b/app/Http/Controllers/Chart/TransactionController.php @@ -21,7 +21,6 @@ namespace FireflyIII\Http\Controllers\Chart; - use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Generator\Chart\Basic\GeneratorInterface; @@ -29,6 +28,7 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionType; use FireflyIII\Support\CacheProperties; +use Illuminate\Http\JsonResponse; /** * Class TransactionController @@ -53,8 +53,8 @@ class TransactionController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\JsonResponse * @throws FireflyException + * @return JsonResponse */ public function budgets(Carbon $start, Carbon $end) { @@ -79,7 +79,7 @@ class TransactionController extends Controller // group by category. /** @var array $journal */ foreach ($result as $journal) { - $budget = $journal['budget_name'] ?? (string)trans('firefly.no_budget'); + $budget = $journal['budget_name'] ?? (string) trans('firefly.no_budget'); $title = sprintf('%s (%s)', $budget, $journal['currency_symbol']); // key => [value => x, 'currency_symbol' => 'x'] $data[$title] = $data[$title] ?? [ @@ -108,8 +108,8 @@ class TransactionController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\JsonResponse * @throws FireflyException + * @return JsonResponse */ public function categories(string $objectType, Carbon $start, Carbon $end) { @@ -146,7 +146,7 @@ class TransactionController extends Controller // group by category. /** @var array $journal */ foreach ($result as $journal) { - $category = $journal['category_name'] ?? (string)trans('firefly.no_category'); + $category = $journal['category_name'] ?? (string) trans('firefly.no_category'); $title = sprintf('%s (%s)', $category, $journal['currency_symbol']); // key => [value => x, 'currency_symbol' => 'x'] $data[$title] = $data[$title] ?? [ @@ -175,8 +175,8 @@ class TransactionController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\JsonResponse * @throws FireflyException + * @return JsonResponse */ public function destinationAccounts(string $objectType, Carbon $start, Carbon $end) { @@ -213,8 +213,8 @@ class TransactionController extends Controller // group by category. /** @var array $journal */ foreach ($result as $journal) { - $name = $journal['destination_account_name']; - $title = sprintf('%s (%s)', $name, $journal['currency_symbol']); + $name = $journal['destination_account_name']; + $title = sprintf('%s (%s)', $name, $journal['currency_symbol']); $data[$title] = $data[$title] ?? [ 'amount' => '0', 'currency_symbol' => $journal['currency_symbol'], @@ -241,8 +241,8 @@ class TransactionController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Http\JsonResponse * @throws FireflyException + * @return JsonResponse */ public function sourceAccounts(string $objectType, Carbon $start, Carbon $end) { @@ -279,8 +279,8 @@ class TransactionController extends Controller // group by category. /** @var array $journal */ foreach ($result as $journal) { - $name = $journal['source_account_name']; - $title = sprintf('%s (%s)', $name, $journal['currency_symbol']); + $name = $journal['source_account_name']; + $title = sprintf('%s (%s)', $name, $journal['currency_symbol']); $data[$title] = $data[$title] ?? [ 'amount' => '0', 'currency_symbol' => $journal['currency_symbol'], @@ -301,5 +301,4 @@ class TransactionController extends Controller return response()->json($chart); } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 990eb50182..cdbe66a9cd 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -78,9 +78,9 @@ class Controller extends BaseController $this->middleware( function ($request, $next) { // translations for specific strings: - $this->monthFormat = (string)trans('config.month'); - $this->monthAndDayFormat = (string)trans('config.month_and_day'); - $this->dateTimeFormat = (string)trans('config.date_time'); + $this->monthFormat = (string) trans('config.month'); + $this->monthAndDayFormat = (string) trans('config.month_and_day'); + $this->dateTimeFormat = (string) trans('config.date_time'); // get shown-intro-preference: if (auth()->check()) { @@ -97,5 +97,4 @@ class Controller extends BaseController } ); } - } diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 5f909449a0..eea45f4b80 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -29,8 +29,11 @@ use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Routing\Redirector; use Log; use View; @@ -47,6 +50,7 @@ class CurrencyController extends Controller /** * CurrencyController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -55,7 +59,7 @@ class CurrencyController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.currencies')); + app('view')->share('title', (string) trans('firefly.currencies')); app('view')->share('mainTitleIcon', 'fa-usd'); $this->repository = app(CurrencyRepositoryInterface::class); $this->userRepository = app(UserRepositoryInterface::class); @@ -71,20 +75,20 @@ class CurrencyController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function create(Request $request) { /** @var User $user */ $user = auth()->user(); if (!$this->userRepository->hasRole($user, 'owner')) { - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); return redirect(route('currencies.index')); } $subTitleIcon = 'fa-plus'; - $subTitle = (string)trans('firefly.create_currency'); + $subTitle = (string) trans('firefly.create_currency'); // put previous url in session if not redirect from store (not "create another"). if (true !== session('currencies.create.fromStore')) { @@ -103,7 +107,7 @@ class CurrencyController extends Controller * @param Request $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function defaultCurrency(Request $request, TransactionCurrency $currency) { @@ -113,7 +117,7 @@ class CurrencyController extends Controller Log::channel('audit')->info(sprintf('Make %s the default currency.', $currency->code)); $this->repository->enable($currency); - $request->session()->flash('success', (string)trans('firefly.new_default_currency', ['name' => $currency->name])); + $request->session()->flash('success', (string) trans('firefly.new_default_currency', ['name' => $currency->name])); return redirect(route('currencies.index')); } @@ -124,7 +128,7 @@ class CurrencyController extends Controller * @param Request $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function delete(Request $request, TransactionCurrency $currency) { @@ -132,7 +136,7 @@ class CurrencyController extends Controller $user = auth()->user(); if (!$this->userRepository->hasRole($user, 'owner')) { // @codeCoverageIgnoreStart - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but is not site owner.', $currency->code)); return redirect(route('currencies.index')); @@ -141,7 +145,7 @@ class CurrencyController extends Controller if ($this->repository->currencyInUse($currency)) { $location = $this->repository->currencyInUseAt($currency); - $message = (string)trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); + $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); $request->session()->flash('error', $message); Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but currency is in use.', $currency->code)); @@ -150,7 +154,7 @@ class CurrencyController extends Controller // put previous url in session $this->rememberPreviousUri('currencies.delete.uri'); - $subTitle = (string)trans('form.delete_currency', ['name' => $currency->name]); + $subTitle = (string) trans('form.delete_currency', ['name' => $currency->name]); Log::channel('audit')->info(sprintf('Visit page to delete currency %s.', $currency->code)); return view('currencies.delete', compact('currency', 'subTitle')); @@ -162,7 +166,7 @@ class CurrencyController extends Controller * @param Request $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, TransactionCurrency $currency) { @@ -170,7 +174,7 @@ class CurrencyController extends Controller $user = auth()->user(); if (!$this->userRepository->hasRole($user, 'owner')) { // @codeCoverageIgnoreStart - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is not site owner.', $currency->code)); return redirect(route('currencies.index')); @@ -178,14 +182,14 @@ class CurrencyController extends Controller } if ($this->repository->currencyInUse($currency)) { - $request->session()->flash('error', (string)trans('firefly.cannot_delete_currency', ['name' => e($currency->name)])); + $request->session()->flash('error', (string) trans('firefly.cannot_delete_currency', ['name' => e($currency->name)])); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is in use.', $currency->code)); return redirect(route('currencies.index')); } if ($this->repository->isFallbackCurrency($currency)) { - $request->session()->flash('error', (string)trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)])); + $request->session()->flash('error', (string) trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)])); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is FALLBACK.', $currency->code)); return redirect(route('currencies.index')); @@ -194,7 +198,7 @@ class CurrencyController extends Controller Log::channel('audit')->info(sprintf('Deleted currency %s.', $currency->code)); $this->repository->destroy($currency); - $request->session()->flash('success', (string)trans('firefly.deleted_currency', ['name' => $currency->name])); + $request->session()->flash('success', (string) trans('firefly.deleted_currency', ['name' => $currency->name])); return redirect($this->getPreviousUri('currencies.delete.uri')); } @@ -203,8 +207,8 @@ class CurrencyController extends Controller * @param Request $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws FireflyException + * @return RedirectResponse|Redirector */ public function disableCurrency(Request $request, TransactionCurrency $currency) { @@ -214,7 +218,7 @@ class CurrencyController extends Controller $user = auth()->user(); if (!$this->userRepository->hasRole($user, 'owner')) { // @codeCoverageIgnoreStart - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); Log::channel('audit')->info(sprintf('Tried to disable currency %s but is not site owner.', $currency->code)); return redirect(route('currencies.index')); @@ -224,7 +228,7 @@ class CurrencyController extends Controller if ($this->repository->currencyInUse($currency)) { $location = $this->repository->currencyInUseAt($currency); - $message = (string)trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); + $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); $request->session()->flash('error', $message); Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code)); @@ -248,10 +252,10 @@ class CurrencyController extends Controller } if ('EUR' === $currency->code) { - session()->flash('warning', (string)trans('firefly.disable_EUR_side_effects')); + session()->flash('warning', (string) trans('firefly.disable_EUR_side_effects')); } - session()->flash('success', (string)trans('firefly.currency_is_now_disabled', ['name' => $currency->name])); + session()->flash('success', (string) trans('firefly.currency_is_now_disabled', ['name' => $currency->name])); return redirect(route('currencies.index')); } @@ -262,7 +266,7 @@ class CurrencyController extends Controller * @param Request $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function edit(Request $request, TransactionCurrency $currency) { @@ -270,7 +274,7 @@ class CurrencyController extends Controller $user = auth()->user(); if (!$this->userRepository->hasRole($user, 'owner')) { // @codeCoverageIgnoreStart - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); Log::channel('audit')->info(sprintf('Tried to edit currency %s but is not owner.', $currency->code)); return redirect(route('currencies.index')); @@ -278,13 +282,13 @@ class CurrencyController extends Controller } $subTitleIcon = 'fa-pencil'; - $subTitle = (string)trans('breadcrumbs.edit_currency', ['name' => $currency->name]); + $subTitle = (string) trans('breadcrumbs.edit_currency', ['name' => $currency->name]); $currency->symbol = htmlentities($currency->symbol); // code to handle active-checkboxes $hasOldInput = null !== $request->old('_token'); $preFilled = [ - 'enabled' => $hasOldInput ? (bool)$request->old('enabled') : $currency->enabled, + 'enabled' => $hasOldInput ? (bool) $request->old('enabled') : $currency->enabled, ]; $request->session()->flash('preFilled', $preFilled); @@ -302,14 +306,14 @@ class CurrencyController extends Controller /** * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function enableCurrency(TransactionCurrency $currency) { app('preferences')->mark(); $this->repository->enable($currency); - session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name])); + session()->flash('success', (string) trans('firefly.currency_is_now_enabled', ['name' => $currency->name])); Log::channel('audit')->info(sprintf('Enabled currency %s.', $currency->code)); return redirect(route('currencies.index')); @@ -320,14 +324,14 @@ class CurrencyController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|\Illuminate\View\View */ public function index(Request $request) { /** @var User $user */ $user = auth()->user(); - $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->repository->getAll(); $total = $collection->count(); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); @@ -337,7 +341,7 @@ class CurrencyController extends Controller $defaultCurrency = $this->repository->getCurrencyByPreference(app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'))); $isOwner = true; if (!$this->userRepository->hasRole($user, 'owner')) { - $request->session()->flash('info', (string)trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')])); + $request->session()->flash('info', (string) trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')])); $isOwner = false; } @@ -350,7 +354,7 @@ class CurrencyController extends Controller * * @param CurrencyFormRequest $request * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function store(CurrencyFormRequest $request) { @@ -372,15 +376,15 @@ class CurrencyController extends Controller } catch (FireflyException $e) { Log::error($e->getMessage()); Log::channel('audit')->info('Could not store (POST) currency without admin rights.', $data); - $request->session()->flash('error', (string)trans('firefly.could_not_store_currency')); + $request->session()->flash('error', (string) trans('firefly.could_not_store_currency')); $currency = null; } - $redirect = redirect($this->getPreviousUri('currencies.create.uri')); + $redirect = redirect($this->getPreviousUri('currencies.create.uri')); if (null !== $currency) { - $request->session()->flash('success', (string)trans('firefly.created_currency', ['name' => $currency->name])); + $request->session()->flash('success', (string) trans('firefly.created_currency', ['name' => $currency->name])); Log::channel('audit')->info('Created (POST) currency.', $data); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart $request->session()->put('currencies.create.fromStore', true); @@ -399,7 +403,7 @@ class CurrencyController extends Controller * @param CurrencyFormRequest $request * @param TransactionCurrency $currency * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function update(CurrencyFormRequest $request, TransactionCurrency $currency) { @@ -412,7 +416,7 @@ class CurrencyController extends Controller } if (!$this->userRepository->hasRole($user, 'owner')) { // @codeCoverageIgnoreStart - $request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); + $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); Log::channel('audit')->info('Tried to update (POST) currency without admin rights.', $data); return redirect(route('currencies.index')); @@ -422,10 +426,10 @@ class CurrencyController extends Controller $currency = $this->repository->update($currency, $data); Log::channel('audit')->info('Updated (POST) currency.', $data); - $request->session()->flash('success', (string)trans('firefly.updated_currency', ['name' => $currency->name])); + $request->session()->flash('success', (string) trans('firefly.updated_currency', ['name' => $currency->name])); app('preferences')->mark(); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart $request->session()->put('currencies.edit.fromUpdate', true); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index d0e2dd61e3..30e158829f 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -30,7 +30,9 @@ use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Support\Http\Controllers\GetConfigurationData; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Routing\Route; use Log; use Monolog\Handler\RotatingFileHandler; @@ -46,6 +48,7 @@ class DebugController extends Controller /** * DebugController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -77,7 +80,7 @@ class DebugController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function flush(Request $request) { @@ -129,7 +132,7 @@ class DebugController extends Controller $userAgent = $request->header('user-agent'); $trustedProxies = config('firefly.trusted_proxies'); $displayErrors = ini_get('display_errors'); - $errorReporting = $this->errorReporting((int)ini_get('error_reporting')); + $errorReporting = $this->errorReporting((int) ini_get('error_reporting')); $appEnv = config('app.env'); $appDebug = var_export(config('app.debug'), true); $logChannel = config('logging.default'); @@ -140,7 +143,7 @@ class DebugController extends Controller // set languages, see what happens: $original = setlocale(LC_ALL, 0); $localeAttempts = []; - $parts = explode(',', (string)trans('config.locale')); + $parts = explode(',', (string) trans('config.locale')); foreach ($parts as $code) { $code = trim($code); $localeAttempts[$code] = var_export(setlocale(LC_ALL, $code), true); @@ -172,11 +175,29 @@ class DebugController extends Controller } return view( - 'debug', compact( - 'phpVersion', 'extensions', 'localeAttempts', 'appEnv', 'appDebug', 'logChannel', 'appLogLevel', 'now', 'drivers', 'currentDriver', - 'loginProvider', - 'userAgent', 'displayErrors', 'installationId', 'errorReporting', 'phpOs', 'interface', 'logContent', 'cacheDriver', 'trustedProxies' - ) + 'debug', + compact( + 'phpVersion', + 'extensions', + 'localeAttempts', + 'appEnv', + 'appDebug', + 'logChannel', + 'appLogLevel', + 'now', + 'drivers', + 'currentDriver', + 'loginProvider', + 'userAgent', + 'displayErrors', + 'installationId', + 'errorReporting', + 'phpOs', + 'interface', + 'logContent', + 'cacheDriver', + 'trustedProxies' + ) ); } @@ -203,7 +224,7 @@ class DebugController extends Controller $return = ' '; /** @var Route $route */ foreach ($set as $route) { - $name = (string)$route->getName(); + $name = (string) $route->getName(); if (in_array('GET', $route->methods(), true)) { $found = false; foreach ($ignore as $string) { @@ -226,7 +247,7 @@ class DebugController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function testFlash(Request $request) { @@ -237,6 +258,4 @@ class DebugController extends Controller return redirect(route('home')); } - - } diff --git a/app/Http/Controllers/Export/IndexController.php b/app/Http/Controllers/Export/IndexController.php index afeeab5912..04464901cc 100644 --- a/app/Http/Controllers/Export/IndexController.php +++ b/app/Http/Controllers/Export/IndexController.php @@ -27,7 +27,10 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Export\ExportDataGenerator; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Response as LaravelResponse; +use Illuminate\View\View; +use League\Csv\CannotInsertRecord; /** * Class IndexController @@ -51,7 +54,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-life-bouy'); - app('view')->share('title', (string)trans('firefly.export_data_title')); + app('view')->share('title', (string) trans('firefly.export_data_title')); $this->journalRepository = app(JournalRepositoryInterface::class); $this->middleware(IsDemoUser::class)->except(['index']); @@ -61,8 +64,8 @@ class IndexController extends Controller } /** + * @throws CannotInsertRecord * @return LaravelResponse - * @throws \League\Csv\CannotInsertRecord */ public function export(): LaravelResponse { @@ -97,12 +100,13 @@ class IndexController extends Controller ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') ->header('Pragma', 'public') ->header('Content-Length', strlen($result['transactions'])); + // return CSV file made from 'transactions' array. return $response; } /** - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7ad7d90e99..270afd955f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -31,9 +31,13 @@ use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -59,8 +63,8 @@ class HomeController extends Controller * * @param Request $request * - * @return JsonResponse * @throws Exception + * @return JsonResponse */ public function dateRange(Request $request): JsonResponse { @@ -74,7 +78,7 @@ class HomeController extends Controller // check if the label is "everything" or "Custom range" which will betray // a possible problem with the budgets. - if ($label === (string)trans('firefly.everything') || $label === (string)trans('firefly.customRange')) { + if ($label === (string) trans('firefly.everything') || $label === (string) trans('firefly.customRange')) { $isCustomRange = true; Log::debug('Range is now marked as "custom".'); } @@ -82,7 +86,7 @@ class HomeController extends Controller $diff = $start->diffInDays($end); if ($diff > 50) { - $request->session()->flash('warning', (string)trans('firefly.warning_much_data', ['days' => $diff])); + $request->session()->flash('warning', (string) trans('firefly.warning_much_data', ['days' => $diff])); } $request->session()->put('is_custom_range', $isCustomRange); @@ -101,8 +105,8 @@ class HomeController extends Controller * * @param AccountRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View * @throws Exception + * @return Factory|RedirectResponse|Redirector|View */ public function index(AccountRepositoryInterface $repository) { @@ -113,10 +117,11 @@ class HomeController extends Controller if (0 === $count) { return redirect(route('new-user.index')); } - $subTitle = (string)trans('firefly.welcomeBack'); + $subTitle = (string) trans('firefly.welcomeBack'); $transactions = []; $frontPage = app('preferences')->get( - 'frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray() + 'frontPageAccounts', + $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray() ); /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); @@ -145,5 +150,4 @@ class HomeController extends Controller return view('index', compact('count', 'subTitle', 'transactions', 'billCount', 'start', 'end', 'today')); } - } diff --git a/app/Http/Controllers/Import/CallbackController.php b/app/Http/Controllers/Import/CallbackController.php index fe069701b7..9e9c8ad65a 100644 --- a/app/Http/Controllers/Import/CallbackController.php +++ b/app/Http/Controllers/Import/CallbackController.php @@ -26,11 +26,16 @@ namespace FireflyIII\Http\Controllers\Import; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** * Class CallbackController + * * @deprecated * @codeCoverageIgnore */ @@ -44,12 +49,12 @@ class CallbackController extends Controller * * @param ImportJobRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View + * @return Factory|RedirectResponse|Redirector|View */ public function ynab(Request $request, ImportJobRepositoryInterface $repository) { - $code = (string)$request->get('code'); - $jobKey = (string)$request->get('state'); + $code = (string) $request->get('code'); + $jobKey = (string) $request->get('state'); if ('' === $code) { return view('error')->with('message', 'You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.'); diff --git a/app/Http/Controllers/Import/IndexController.php b/app/Http/Controllers/Import/IndexController.php index 1bcb51c57c..d06579bded 100644 --- a/app/Http/Controllers/Import/IndexController.php +++ b/app/Http/Controllers/Import/IndexController.php @@ -28,12 +28,17 @@ use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Support\Binder\ImportProvider; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Response as LaravelResponse; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** * * Class IndexController + * * @deprecated * @codeCoverageIgnore */ @@ -56,7 +61,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-archive'); - app('view')->share('title', (string)trans('firefly.import_index_title')); + app('view')->share('title', (string) trans('firefly.import_index_title')); $this->repository = app(ImportJobRepositoryInterface::class); $this->userRepository = app(UserRepositoryInterface::class); $this->providers = ImportProvider::getProviders(); @@ -71,14 +76,14 @@ class IndexController extends Controller * * @param string $importProvider * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector * */ public function create(string $importProvider) { - $hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider)); - $hasConfig = (bool)config(sprintf('import.has_job_config.%s', $importProvider)); - $allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $importProvider)); + $hasPreReq = (bool) config(sprintf('import.has_prereq.%s', $importProvider)); + $hasConfig = (bool) config(sprintf('import.has_job_config.%s', $importProvider)); + $allowedForDemo = (bool) config(sprintf('import.allowed_for_demo.%s', $importProvider)); $isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo'); Log::debug(sprintf('Will create job for provider "%s"', $importProvider)); @@ -111,7 +116,7 @@ class IndexController extends Controller // job has prerequisites: Log::debug('Job provider has prerequisites.'); /** @var PrerequisitesInterface $providerPre */ - $providerPre = app((string)config(sprintf('import.prerequisites.%s', $importProvider))); + $providerPre = app((string) config(sprintf('import.prerequisites.%s', $importProvider))); $providerPre->setUser($importJob->user); // and are not filled in: @@ -179,12 +184,12 @@ class IndexController extends Controller /** * General import index. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { $providers = $this->providers; - $subTitle = (string)trans('import.index_breadcrumb'); + $subTitle = (string) trans('import.index_breadcrumb'); $subTitleIcon = 'fa-home'; $isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo'); diff --git a/app/Http/Controllers/Import/JobConfigurationController.php b/app/Http/Controllers/Import/JobConfigurationController.php index c0df56fe1f..50c4ba1aa5 100644 --- a/app/Http/Controllers/Import/JobConfigurationController.php +++ b/app/Http/Controllers/Import/JobConfigurationController.php @@ -27,13 +27,18 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Support\Http\Controllers\CreateStuff; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Http\UploadedFile; +use Illuminate\Routing\Redirector; use Illuminate\Support\MessageBag; +use Illuminate\View\View; use Log; /** * Class JobConfigurationController + * * @deprecated * @codeCoverageIgnore */ @@ -53,7 +58,7 @@ class JobConfigurationController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-archive'); - app('view')->share('title', (string)trans('firefly.import_index_title')); + app('view')->share('title', (string) trans('firefly.import_index_title')); $this->repository = app(ImportJobRepositoryInterface::class); return $next($request); @@ -66,10 +71,10 @@ class JobConfigurationController extends Controller * * @param ImportJob $importJob * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View - * * @throws FireflyException * + * @return Factory|RedirectResponse|Redirector|View + * */ public function index(ImportJob $importJob) { @@ -77,7 +82,7 @@ class JobConfigurationController extends Controller $allowed = ['has_prereq', 'need_job_config']; if (null !== $importJob && !in_array($importJob->status, $allowed, true)) { Log::error(sprintf('Job has state "%s", but we only accept %s', $importJob->status, json_encode($allowed))); - session()->flash('error', (string)trans('import.bad_job_status', ['status' => e($importJob->status)])); + session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)])); return redirect(route('import.index')); } @@ -85,7 +90,7 @@ class JobConfigurationController extends Controller // if provider has no config, just push it through: $importProvider = $importJob->provider; - if (!(bool)config(sprintf('import.has_job_config.%s', $importProvider))) { + if (!(bool) config(sprintf('import.has_job_config.%s', $importProvider))) { // @codeCoverageIgnoreStart Log::debug('Job needs no config, is ready to run!'); $this->repository->setStatus($importJob, 'ready_to_run'); @@ -104,7 +109,7 @@ class JobConfigurationController extends Controller $view = $configurator->getNextView(); $data = $configurator->getNextData(); - $subTitle = (string)trans('import.job_configuration_breadcrumb', ['key' => $importJob->key]); + $subTitle = (string) trans('import.job_configuration_breadcrumb', ['key' => $importJob->key]); $subTitleIcon = 'fa-wrench'; return view($view, compact('data', 'importJob', 'subTitle', 'subTitleIcon')); @@ -116,16 +121,16 @@ class JobConfigurationController extends Controller * @param Request $request * @param ImportJob $importJob * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * * @throws FireflyException + * @return RedirectResponse|Redirector + * */ public function post(Request $request, ImportJob $importJob) { // catch impossible status: $allowed = ['has_prereq', 'need_job_config']; if (null !== $importJob && !in_array($importJob->status, $allowed, true)) { - session()->flash('error', (string)trans('import.bad_job_status', ['status' => e($importJob->status)])); + session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)])); return redirect(route('import.index')); } diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.php index c4a392a996..f90dc9f383 100644 --- a/app/Http/Controllers/Import/JobStatusController.php +++ b/app/Http/Controllers/Import/JobStatusController.php @@ -34,6 +34,7 @@ use Log; /** * Class JobStatusController + * * @deprecated * @codeCoverageIgnore */ @@ -55,7 +56,7 @@ class JobStatusController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-archive'); - app('view')->share('title', (string)trans('firefly.import_index_title')); + app('view')->share('title', (string) trans('firefly.import_index_title')); $this->repository = app(ImportJobRepositoryInterface::class); return $next($request); @@ -73,7 +74,7 @@ class JobStatusController extends Controller public function index(ImportJob $importJob) { $subTitleIcon = 'fa-gear'; - $subTitle = (string)trans('import.job_status_breadcrumb', ['key' => $importJob->key]); + $subTitle = (string) trans('import.job_status_breadcrumb', ['key' => $importJob->key]); return view('import.status', compact('importJob', 'subTitle', 'subTitleIcon')); } @@ -94,7 +95,7 @@ class JobStatusController extends Controller 'count' => $count, 'tag_id' => $importJob->tag_id, 'tag_name' => null === $importJob->tag_id ? null : $importJob->tag->tag, - 'report_txt' => (string)trans('import.unknown_import_result'), + 'report_txt' => (string) trans('import.unknown_import_result'), 'download_config' => false, 'download_config_text' => '', ]; @@ -111,11 +112,12 @@ class JobStatusController extends Controller $count = $this->repository->countByTag($importJob); } if (0 === $count) { - $json['report_txt'] = (string)trans('import.result_no_transactions'); + $json['report_txt'] = (string) trans('import.result_no_transactions'); } if (1 === $count && null !== $importJob->tag_id) { $json['report_txt'] = trans( - 'import.result_one_transaction', ['route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag] + 'import.result_one_transaction', + ['route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag] ); } if ($count > 1 && null !== $importJob->tag_id) { @@ -235,6 +237,4 @@ class JobStatusController extends Controller // expect nothing from routine, just return OK to user. return response()->json(['status' => 'OK', 'message' => 'storage_finished']); } - - } diff --git a/app/Http/Controllers/Import/PrerequisitesController.php b/app/Http/Controllers/Import/PrerequisitesController.php index f148d39149..e0c1fea936 100644 --- a/app/Http/Controllers/Import/PrerequisitesController.php +++ b/app/Http/Controllers/Import/PrerequisitesController.php @@ -27,11 +27,16 @@ use FireflyIII\Import\Prerequisites\PrerequisitesInterface; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Log; /** * Class PrerequisitesController + * * @deprecated * @codeCoverageIgnore */ @@ -51,7 +56,7 @@ class PrerequisitesController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-archive'); - app('view')->share('title', (string)trans('firefly.import_index_title')); + app('view')->share('title', (string) trans('firefly.import_index_title')); app('view')->share('subTitleIcon', 'fa-check'); $this->repository = app(ImportJobRepositoryInterface::class); @@ -68,7 +73,7 @@ class PrerequisitesController extends Controller * @param string $importProvider * @param ImportJob $importJob * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(string $importProvider, ImportJob $importJob = null) { @@ -76,13 +81,13 @@ class PrerequisitesController extends Controller $allowed = ['new']; if (null !== $importJob && !in_array($importJob->status, $allowed, true)) { Log::error(sprintf('Job has state "%s" but this Prerequisites::index() only accepts %s', $importJob->status, json_encode($allowed))); - session()->flash('error', (string)trans('import.bad_job_status', ['status' => e($importJob->status)])); + session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)])); return redirect(route('import.index')); } - app('view')->share('subTitle', (string)trans('import.prerequisites_breadcrumb_' . $importProvider)); - $class = (string)config(sprintf('import.prerequisites.%s', $importProvider)); + app('view')->share('subTitle', (string) trans('import.prerequisites_breadcrumb_' . $importProvider)); + $class = (string) config(sprintf('import.prerequisites.%s', $importProvider)); /** @var User $user */ $user = auth()->user(); /** @var PrerequisitesInterface $object */ @@ -99,7 +104,7 @@ class PrerequisitesController extends Controller $view = $object->getView(); - $parameters = ['title' => (string)trans('firefly.import_index_title'), 'mainTitleIcon' => 'fa-archive', 'importJob' => $importJob]; + $parameters = ['title' => (string) trans('firefly.import_index_title'), 'mainTitleIcon' => 'fa-archive', 'importJob' => $importJob]; $parameters = array_merge($object->getViewParameters(), $parameters); return view($view, $parameters); @@ -115,7 +120,7 @@ class PrerequisitesController extends Controller * @param string $importProvider * @param ImportJob $importJob * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector * @see PrerequisitesInterface::storePrerequisites * */ @@ -127,13 +132,13 @@ class PrerequisitesController extends Controller $allowed = ['new']; if (null !== $importJob && !in_array($importJob->status, $allowed, true)) { Log::error(sprintf('Job has state "%s" but this Prerequisites::post() only accepts %s', $importJob->status, json_encode($allowed))); - session()->flash('error', (string)trans('import.bad_job_status', ['status' => e($importJob->status)])); + session()->flash('error', (string) trans('import.bad_job_status', ['status' => e($importJob->status)])); return redirect(route('import.index')); } - $class = (string)config(sprintf('import.prerequisites.%s', $importProvider)); + $class = (string) config(sprintf('import.prerequisites.%s', $importProvider)); /** @var User $user */ $user = auth()->user(); /** @var PrerequisitesInterface $object */ @@ -153,7 +158,7 @@ class PrerequisitesController extends Controller } // session flash! - $request->session()->flash('success', (string)trans('import.prerequisites_saved_for_' . $importProvider)); + $request->session()->flash('success', (string) trans('import.prerequisites_saved_for_' . $importProvider)); // if has job, redirect to global config for provider // if no job, back to index! diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php index f2b901bbd6..240c78a98d 100644 --- a/app/Http/Controllers/JavascriptController.php +++ b/app/Http/Controllers/JavascriptController.php @@ -44,7 +44,7 @@ class JavascriptController extends Controller * @param AccountRepositoryInterface $repository * @param CurrencyRepositoryInterface $currencyRepository * - * @return \Illuminate\Http\Response + * @return Response */ public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response { @@ -60,7 +60,7 @@ class JavascriptController extends Controller /** @var Account $account */ foreach ($accounts as $account) { $accountId = $account->id; - $currency = (int)$repository->getMetaValue($account, 'currency_id'); + $currency = (int) $repository->getMetaValue($account, 'currency_id'); /** @noinspection NullPointerExceptionInspection */ $currency = 0 === $currency ? $default->id : $currency; $entry = ['preferredCurrency' => $currency, 'name' => $account->name]; @@ -102,15 +102,15 @@ class JavascriptController extends Controller * @param AccountRepositoryInterface $repository * @param CurrencyRepositoryInterface $currencyRepository * - * @return \Illuminate\Http\Response + * @return Response */ public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response { - $account = $repository->findNull((int)$request->get('account')); + $account = $repository->findNull((int) $request->get('account')); $currencyId = 0; if (null !== $account) { // TODO we can use getAccountCurrency() instead - $currencyId = (int)$repository->getMetaValue($account, 'currency_id'); + $currencyId = (int) $repository->getMetaValue($account, 'currency_id'); } /** @var TransactionCurrency $currency */ $currency = $currencyRepository->findNull($currencyId); diff --git a/app/Http/Controllers/Json/AutoCompleteController.php b/app/Http/Controllers/Json/AutoCompleteController.php index 8212f5d21f..820d4ed711 100644 --- a/app/Http/Controllers/Json/AutoCompleteController.php +++ b/app/Http/Controllers/Json/AutoCompleteController.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use Amount; use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; @@ -78,7 +79,7 @@ class AutoCompleteController extends Controller Log::debug(sprintf('Now in accounts("%s"). Filtering results.', $search), $filteredAccountTypes); $return = []; - $result = $repository->searchAccount((string)$search, $filteredAccountTypes); + $result = $repository->searchAccount((string) $search, $filteredAccountTypes); $defaultCurrency = app('amount')->getDefaultCurrency(); /** @var Account $account */ @@ -117,7 +118,7 @@ class AutoCompleteController extends Controller */ public function allJournals(Request $request): JsonResponse { - $search = (string)$request->get('search'); + $search = (string) $request->get('search'); /** @var JournalRepositoryInterface $repository */ $repository = app(JournalRepositoryInterface::class); $result = $repository->searchJournalDescriptions($search); @@ -132,7 +133,8 @@ class AutoCompleteController extends Controller $journal['name'] = $journal['description']; return $journal; - }, $array + }, + $array ); return response()->json(array_values($array)); @@ -150,7 +152,7 @@ class AutoCompleteController extends Controller */ public function allJournalsWithID(Request $request): JsonResponse { - $search = (string)$request->get('search'); + $search = (string) $request->get('search'); /** @var JournalRepositoryInterface $repository */ $repository = app(JournalRepositoryInterface::class); @@ -161,7 +163,7 @@ class AutoCompleteController extends Controller $array = []; if (is_numeric($search)) { // search for group, not journal. - $firstResult = $groupRepos->find((int)$search); + $firstResult = $groupRepos->find((int) $search); if (null !== $firstResult) { // group may contain multiple journals, each a result: foreach ($firstResult->transactionJournals as $journal) { @@ -201,7 +203,7 @@ class AutoCompleteController extends Controller Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes); $return = []; - $result = $repository->searchAccount((string)$search, $allowedAccountTypes); + $result = $repository->searchAccount((string) $search, $allowedAccountTypes); /** @var Account $account */ foreach ($result as $account) { @@ -223,7 +225,7 @@ class AutoCompleteController extends Controller */ public function bills(Request $request): JsonResponse { - $query = (string)$request->get('search'); + $query = (string) $request->get('search'); /** @var BillRepositoryInterface $repository */ $repository = app(BillRepositoryInterface::class); $result = $repository->searchBill($query); @@ -239,7 +241,7 @@ class AutoCompleteController extends Controller */ public function budgets(Request $request): JsonResponse { - $search = (string)$request->get('search'); + $search = (string) $request->get('search'); /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class); $result = $repository->searchBudget($search); @@ -255,7 +257,7 @@ class AutoCompleteController extends Controller */ public function categories(Request $request): JsonResponse { - $query = (string)$request->get('search'); + $query = (string) $request->get('search'); /** @var CategoryRepositoryInterface $repository */ $repository = app(CategoryRepositoryInterface::class); $result = $repository->searchCategory($query); @@ -297,7 +299,7 @@ class AutoCompleteController extends Controller */ public function currencyNames(Request $request): JsonResponse { - $query = (string)$request->get('search'); + $query = (string) $request->get('search'); /** @var CurrencyRepositoryInterface $repository */ $repository = app(CurrencyRepositoryInterface::class); $result = $repository->searchCurrency($query)->toArray(); @@ -326,7 +328,7 @@ class AutoCompleteController extends Controller Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes); $return = []; - $result = $repository->searchAccount((string)$search, $allowedAccountTypes); + $result = $repository->searchAccount((string) $search, $allowedAccountTypes); /** @var Account $account */ foreach ($result as $account) { @@ -353,7 +355,7 @@ class AutoCompleteController extends Controller $accountRepos = app(AccountRepositoryInterface::class); $piggies = $repository->getPiggyBanks(); - $defaultCurrency = \Amount::getDefaultCurrency(); + $defaultCurrency = Amount::getDefaultCurrency(); $response = []; /** @var PiggyBank $piggy */ foreach ($piggies as $piggy) { @@ -389,7 +391,7 @@ class AutoCompleteController extends Controller Log::debug('Now in revenueAccounts(). Filtering results.', $allowedAccountTypes); $return = []; - $result = $repository->searchAccount((string)$search, $allowedAccountTypes); + $result = $repository->searchAccount((string) $search, $allowedAccountTypes); /** @var Account $account */ foreach ($result as $account) { @@ -411,7 +413,7 @@ class AutoCompleteController extends Controller */ public function tags(Request $request): JsonResponse { - $search = (string)$request->get('search'); + $search = (string) $request->get('search'); /** @var TagRepositoryInterface $repository */ $repository = app(TagRepositoryInterface::class); $result = $repository->searchTags($search); @@ -432,7 +434,7 @@ class AutoCompleteController extends Controller */ public function transactionTypes(Request $request): JsonResponse { - $query = (string)$request->get('search'); + $query = (string) $request->get('search'); /** @var TransactionTypeRepositoryInterface $repository */ $repository = app(TransactionTypeRepositoryInterface::class); $array = $repository->searchTypes($query)->toArray(); @@ -444,5 +446,4 @@ class AutoCompleteController extends Controller return response()->json($array); } - } diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 7ec0f37d45..82ffa2086c 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -34,7 +34,6 @@ use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; -use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\CacheProperties; @@ -71,7 +70,7 @@ class BoxController extends Controller $end = session('end', Carbon::now()->endOfMonth()); $today = new Carbon; $display = 2; // see method docs. - $boxTitle = (string)trans('firefly.spent'); + $boxTitle = (string) trans('firefly.spent'); $cache = new CacheProperties; $cache->addProperty($start); @@ -98,19 +97,19 @@ class BoxController extends Controller // spent in this period, in budgets, for default currency. // also calculate spent per day. $spent = $opsRepository->sumExpenses($start, $end, null, null, $currency); - $spentAmount = $spent[(int)$currency->id]['sum'] ?? '0'; + $spentAmount = $spent[(int) $currency->id]['sum'] ?? '0'; $spentPerDay = '-1'; if ($availableBudgets->count() > 0) { - $display = 0; // assume user overspent - $boxTitle = (string)trans('firefly.overspent'); - $totalAvailableSum = (string)$availableBudgets->sum('amount'); + $display = 0; // assume user overspent + $boxTitle = (string) trans('firefly.overspent'); + $totalAvailableSum = (string) $availableBudgets->sum('amount'); // calculate with available budget. $leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount); if (1 === bccomp($leftToSpendAmount, '0')) { - $boxTitle = (string)trans('firefly.left_to_spend'); + $boxTitle = (string) trans('firefly.left_to_spend'); $days = $today->diffInDays($end) + 1; $display = 1; // not overspent - $leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$days); + $leftPerDayAmount = bcdiv($leftToSpendAmount, (string) $days); } } @@ -164,7 +163,7 @@ class BoxController extends Controller $set = $collector->getExtractedJournals(); /** @var array $journal */ foreach ($set as $journal) { - $currencyId = (int)$journal['currency_id']; + $currencyId = (int) $journal['currency_id']; $amount = $journal['amount'] ?? '0'; $incomes[$currencyId] = $incomes[$currencyId] ?? '0'; $incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount)); @@ -180,7 +179,7 @@ class BoxController extends Controller $set = $collector->getExtractedJournals(); /** @var array $journal */ foreach ($set as $journal) { - $currencyId = (int)$journal['currency_id']; + $currencyId = (int) $journal['currency_id']; $expenses[$currencyId] = $expenses[$currencyId] ?? '0'; $expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount'] ?? '0'); $sums[$currencyId] = $sums[$currencyId] ?? '0'; diff --git a/app/Http/Controllers/Json/ExchangeController.php b/app/Http/Controllers/Json/ExchangeController.php index 7266179755..41e85d2391 100644 --- a/app/Http/Controllers/Json/ExchangeController.php +++ b/app/Http/Controllers/Json/ExchangeController.php @@ -73,7 +73,7 @@ class ExchangeController extends Controller $return['amount'] = null; if (null !== $request->get('amount')) { // assume amount is in "from" currency: - $return['amount'] = bcmul($request->get('amount'), (string)$rate->rate, 12); + $return['amount'] = bcmul($request->get('amount'), (string) $rate->rate, 12); // round to toCurrency decimal places: $return['amount'] = round($return['amount'], $toCurrency->decimal_places); } diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php index 1f28f3a82a..f0c92f55bd 100644 --- a/app/Http/Controllers/Json/IntroController.php +++ b/app/Http/Controllers/Json/IntroController.php @@ -115,7 +115,7 @@ class IntroController app('preferences')->set($key, false); app('preferences')->mark(); - return response()->json(['message' => (string)trans('firefly.intro_boxes_after_refresh')]); + return response()->json(['message' => (string) trans('firefly.intro_boxes_after_refresh')]); } /** diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php index 4b9a4decb0..f4da7395fe 100644 --- a/app/Http/Controllers/Json/ReconcileController.php +++ b/app/Http/Controllers/Json/ReconcileController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; - use Carbon\Carbon; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; @@ -56,6 +55,7 @@ class ReconcileController extends Controller /** * ReconcileController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -66,7 +66,7 @@ class ReconcileController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(JournalRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); @@ -81,8 +81,8 @@ class ReconcileController extends Controller * * @param Request $request * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return JsonResponse */ @@ -141,11 +141,22 @@ class ReconcileController extends Controller try { $view = view( - 'accounts.reconcile.overview', compact( - 'account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount', - 'startBalance', 'endBalance', 'amount', - 'route', 'countCleared', 'reconSum', 'selectedIds' - ) + 'accounts.reconcile.overview', + compact( + 'account', + 'start', + 'diffCompare', + 'difference', + 'end', + 'clearedAmount', + 'startBalance', + 'endBalance', + 'amount', + 'route', + 'countCleared', + 'reconSum', + 'selectedIds' + ) )->render(); // @codeCoverageIgnoreStart } catch (Throwable $e) { @@ -168,8 +179,8 @@ class ReconcileController extends Controller * Returns a list of transactions in a modal. * * @param Account $account - * @param Carbon $start - * @param Carbon $end + * @param Carbon $start + * @param Carbon $end * * @return mixed * @@ -231,8 +242,10 @@ class ReconcileController extends Controller } try { - $html = view('accounts.reconcile.transactions', - compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd'))->render(); + $html = view( + 'accounts.reconcile.transactions', + compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd') + )->render(); // @codeCoverageIgnoreStart } catch (Throwable $e) { Log::debug(sprintf('Could not render: %s', $e->getMessage())); @@ -245,10 +258,11 @@ class ReconcileController extends Controller } /** - * @param Account $account + * @param Account $account * @param TransactionCurrency $currency - * @param array $journal - * @param string $amount + * @param array $journal + * @param string $amount + * * @return string */ private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string diff --git a/app/Http/Controllers/Json/RecurrenceController.php b/app/Http/Controllers/Json/RecurrenceController.php index 6e68511e84..e8ffc0e795 100644 --- a/app/Http/Controllers/Json/RecurrenceController.php +++ b/app/Http/Controllers/Json/RecurrenceController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; - use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -65,9 +64,9 @@ class RecurrenceController extends Controller * * @param Request $request * + * @throws FireflyException * @return JsonResponse * - * @throws FireflyException */ public function events(Request $request): JsonResponse { @@ -75,10 +74,10 @@ class RecurrenceController extends Controller $start = Carbon::createFromFormat('Y-m-d', $request->get('start')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end')); $firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date')); - $endDate = '' !== (string)$request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null; - $endsAt = (string)$request->get('ends'); + $endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null; + $endsAt = (string) $request->get('ends'); $repetitionType = explode(',', $request->get('type'))[0]; - $repetitions = (int)$request->get('reps'); + $repetitions = (int) $request->get('reps'); $repetitionMoment = ''; $start->startOfDay(); @@ -101,8 +100,8 @@ class RecurrenceController extends Controller $repetition = new RecurrenceRepetition; $repetition->repetition_type = $repetitionType; $repetition->repetition_moment = $repetitionMoment; - $repetition->repetition_skip = (int)$request->get('skip'); - $repetition->weekend = (int)$request->get('weekend'); + $repetition->repetition_skip = (int) $request->get('skip'); + $repetition->weekend = (int) $request->get('weekend'); $actualEnd = clone $end; $occurrences = []; switch ($endsAt) { @@ -150,30 +149,31 @@ class RecurrenceController extends Controller { $string = $request->get('date') ?? date('Y-m-d'); $today = Carbon::now()->startOfDay(); - $date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay();; - $preSelected = (string)$request->get('pre_select'); + $date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay(); + $preSelected = (string) $request->get('pre_select'); - Log::debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true) )); - Log::debug(sprintf('past = true? %s', var_export('true' === (string)$request->get('past'), true))); + Log::debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true))); + Log::debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true))); - $result = []; - if ($date > $today || 'true' === (string)$request->get('past')) { + $result = []; + if ($date > $today || 'true' === (string) $request->get('past')) { Log::debug('Will fill dropdown.'); $weekly = sprintf('weekly,%s', $date->dayOfWeekIso); $monthly = sprintf('monthly,%s', $date->day); - $dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso)); + $dayOfWeek = (string) trans(sprintf('config.dow_%s', $date->dayOfWeekIso)); $ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso); $yearly = sprintf('yearly,%s', $date->format('Y-m-d')); - $yearlyDate = $date->formatLocalized((string)trans('config.month_and_day_no_year')); + $yearlyDate = $date->formatLocalized((string) trans('config.month_and_day_no_year')); $result = [ - 'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => 0 === strpos($preSelected, 'daily')], - $weekly => ['label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]), + 'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => 0 === strpos($preSelected, 'daily')], + $weekly => ['label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]), 'selected' => 0 === strpos($preSelected, 'weekly')], - $monthly => ['label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]), + $monthly => ['label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]), 'selected' => 0 === strpos($preSelected, 'monthly')], - $ndom => ['label' => (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]), + $ndom => ['label' => (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]), 'selected' => 0 === strpos($preSelected, 'ndom')], - $yearly => ['label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]), 'selected' => 0 === strpos($preSelected, 'yearly')], + $yearly => ['label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]), + 'selected' => 0 === strpos($preSelected, 'yearly')], ]; } Log::debug('Dropdown is', $result); @@ -181,5 +181,4 @@ class RecurrenceController extends Controller return response()->json($result); } - } diff --git a/app/Http/Controllers/Json/RuleController.php b/app/Http/Controllers/Json/RuleController.php index f69add2944..28fc13736d 100644 --- a/app/Http/Controllers/Json/RuleController.php +++ b/app/Http/Controllers/Json/RuleController.php @@ -44,11 +44,11 @@ class RuleController extends Controller */ public function action(Request $request): JsonResponse { - $count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1; + $count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1; $keys = array_keys(config('firefly.rule-actions')); $actions = []; foreach ($keys as $key) { - $actions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice'); + $actions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice'); } try { $view = view('rules.partials.action', compact('actions', 'count'))->render(); @@ -72,12 +72,12 @@ class RuleController extends Controller */ public function trigger(Request $request): JsonResponse { - $count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1; + $count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1; $keys = array_keys(config('firefly.rule-triggers')); $triggers = []; foreach ($keys as $key) { if ('user_action' !== $key) { - $triggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice'); + $triggers[$key] = (string) trans('firefly.rule_trigger_' . $key . '_choice'); } } asort($triggers); diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 186e28c4d8..6735072772 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -26,6 +26,8 @@ use FireflyIII\Http\Requests\NewUserFormRequest; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Support\Http\Controllers\CreateStuff; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use View; /** @@ -56,11 +58,11 @@ class NewUserController extends Controller /** * Form the user gets when he has no data in the system. * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function index() { - app('view')->share('title', (string)trans('firefly.welcome')); + app('view')->share('title', (string) trans('firefly.welcome')); app('view')->share('mainTitleIcon', 'fa-fire'); $types = config('firefly.accountTypesByIdentifier.asset'); @@ -81,7 +83,7 @@ class NewUserController extends Controller * @param NewUserFormRequest $request * @param CurrencyRepositoryInterface $currencyRepository * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function submit(NewUserFormRequest $request, CurrencyRepositoryInterface $currencyRepository) { @@ -94,7 +96,7 @@ class NewUserController extends Controller // set language preference: app('preferences')->set('language', $language); // Store currency preference from input: - $currency = $currencyRepository->findNull((int)$request->input('amount_currency_id_bank_balance')); + $currency = $currencyRepository->findNull((int) $request->input('amount_currency_id_bank_balance')); // if is null, set to EUR: if (null === $currency) { @@ -115,7 +117,7 @@ class NewUserController extends Controller 'invoice_date' => false, 'internal_reference' => false, 'notes' => true, 'attachments' => true,]; app('preferences')->set('transaction_journal_optional_fields', $visibleFields); - session()->flash('success', (string)trans('firefly.stored_new_accounts_new_user')); + session()->flash('success', (string) trans('firefly.stored_new_accounts_new_user')); app('preferences')->mark(); return redirect(route('index')); diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index cc02d9b6b8..c2a14d6e04 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -30,11 +30,14 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Transformers\AccountTransformer; use FireflyIII\Transformers\PiggyBankTransformer; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; use Symfony\Component\HttpFoundation\ParameterBag; @@ -54,6 +57,7 @@ class PiggyBankController extends Controller /** * PiggyBankController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -62,7 +66,7 @@ class PiggyBankController 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-sort-amount-asc'); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); @@ -79,7 +83,7 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function add(PiggyBank $piggyBank) { @@ -99,7 +103,7 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function addMobile(PiggyBank $piggyBank) { @@ -117,11 +121,11 @@ class PiggyBankController extends Controller /** * Create a piggy bank. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ 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"). @@ -138,11 +142,11 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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->rememberPreviousUri('piggy-banks.delete.uri'); @@ -159,7 +163,7 @@ class PiggyBankController extends Controller */ 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); @@ -171,11 +175,11 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(PiggyBank $piggyBank) { - $subTitle = (string)trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); + $subTitle = (string) trans('firefly.update_piggy_title', ['name' => $piggyBank->name]); $subTitleIcon = 'fa-pencil'; $targetDate = null; $startDate = null; @@ -211,15 +215,15 @@ class PiggyBankController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(Request $request) { $this->piggyRepos->correctOrder(); $collection = $this->piggyRepos->getPiggyBanks(); $total = $collection->count(); - $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; $accounts = []; /** @var Carbon $end */ $end = session('end', Carbon::now()->endOfMonth()); @@ -240,7 +244,7 @@ class PiggyBankController extends Controller foreach ($collection as $piggy) { $array = $transformer->transform($piggy); $account = $accountTransformer->transform($piggy->account); - $accountId = (int)$account['id']; + $accountId = (int) $account['id']; if (!isset($accounts[$accountId])) { // create new: $accounts[$accountId] = $account; @@ -288,7 +292,7 @@ class PiggyBankController 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] ) @@ -301,7 +305,7 @@ class PiggyBankController extends Controller 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)] ) @@ -330,7 +334,7 @@ class PiggyBankController 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] ) @@ -340,11 +344,11 @@ class PiggyBankController extends Controller return redirect(route('piggy-banks.index')); } - $amount = (string)round($request->get('amount'), 12); + $amount = (string) round($request->get('amount'), 12); session()->flash( 'error', - (string)trans( + (string) trans( 'firefly.cannot_remove_from_piggy', ['amount' => app('amount')->formatAnything($currency, $amount, false), 'name' => e($piggyBank->name)] ) @@ -358,12 +362,12 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function remove(PiggyBank $piggyBank) { $repetition = $this->piggyRepos->getRepetition($piggyBank); - $currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency(); return view('piggy-banks.remove', compact('piggyBank', 'repetition', 'currency')); } @@ -373,12 +377,12 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function removeMobile(PiggyBank $piggyBank) { $repetition = $this->piggyRepos->getRepetition($piggyBank); - $currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency(); + $currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency(); return view('piggy-banks.remove-mobile', compact('piggyBank', 'repetition', 'currency')); } @@ -393,7 +397,7 @@ class PiggyBankController extends Controller */ public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse { - $newOrder = (int)$request->get('order'); + $newOrder = (int) $request->get('order'); $this->piggyRepos->setOrder($piggyBank, $newOrder); return response()->json(['data' => 'OK']); @@ -404,7 +408,7 @@ class PiggyBankController extends Controller * * @param PiggyBank $piggyBank * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function show(PiggyBank $piggyBank) { @@ -429,7 +433,7 @@ class PiggyBankController extends Controller * * @param PiggyBankFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(PiggyBankFormRequest $request) { @@ -439,12 +443,12 @@ class PiggyBankController 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(); $redirect = redirect($this->getPreviousUri('piggy-banks.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart session()->put('piggy-banks.create.fromStore', true); @@ -461,19 +465,19 @@ class PiggyBankController extends Controller * @param PiggyBankFormRequest $request * @param PiggyBank $piggyBank * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function update(PiggyBankFormRequest $request, PiggyBank $piggyBank) { $data = $request->getPiggyBankData(); $piggyBank = $this->piggyRepos->update($piggyBank, $data); - session()->flash('success', (string)trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name])); + session()->flash('success', (string) trans('firefly.updated_piggy_bank', ['name' => $piggyBank->name])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('piggy-banks.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart session()->put('piggy-banks.edit.fromUpdate', true); diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index 50b5aea822..bd5d8f9a58 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -26,7 +26,11 @@ use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\Preference; 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; /** * Class PreferencesController. @@ -35,6 +39,7 @@ class PreferencesController extends Controller { /** * PreferencesController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -43,7 +48,7 @@ class PreferencesController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.preferences')); + app('view')->share('title', (string) trans('firefly.preferences')); app('view')->share('mainTitleIcon', 'fa-gear'); return $next($request); @@ -56,7 +61,7 @@ class PreferencesController extends Controller * * @param AccountRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(AccountRepositoryInterface $repository) { @@ -70,13 +75,13 @@ class PreferencesController extends Controller $role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role')); if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) { - $role = sprintf('opt_group_l_%s',$type); + $role = sprintf('opt_group_l_%s', $type); } if ('' === $role || 'opt_group_' === $role) { $role = 'opt_group_defaultAsset'; } - $groupedAccounts[trans(sprintf('firefly.%s',$role))][$account->id] = $account->name; + $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account->name; } ksort($groupedAccounts); @@ -122,7 +127,7 @@ class PreferencesController extends Controller * * @param Request $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector * */ public function postIndex(Request $request) @@ -131,7 +136,7 @@ class PreferencesController extends Controller $frontPageAccounts = []; if (is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) { foreach ($request->get('frontPageAccounts') as $id) { - $frontPageAccounts[] = (int)$id; + $frontPageAccounts[] = (int) $id; } app('preferences')->set('frontPageAccounts', $frontPageAccounts); } @@ -144,14 +149,14 @@ class PreferencesController extends Controller session()->forget('range'); // custom fiscal year - $customFiscalYear = 1 === (int)$request->get('customFiscalYear'); - $fiscalYearStart = date('m-d', strtotime((string)$request->get('fiscalYearStart'))); + $customFiscalYear = 1 === (int) $request->get('customFiscalYear'); + $fiscalYearStart = date('m-d', strtotime((string) $request->get('fiscalYearStart'))); app('preferences')->set('customFiscalYear', $customFiscalYear); app('preferences')->set('fiscalYearStart', $fiscalYearStart); // save page size: app('preferences')->set('listPageSize', 50); - $listPageSize = (int)$request->get('listPageSize'); + $listPageSize = (int) $request->get('listPageSize'); if ($listPageSize > 0 && $listPageSize < 1337) { app('preferences')->set('listPageSize', $listPageSize); } @@ -182,7 +187,7 @@ class PreferencesController extends Controller ]; app('preferences')->set('transaction_journal_optional_fields', $optionalTj); - session()->flash('success', (string)trans('firefly.saved_preferences')); + session()->flash('success', (string) trans('firefly.saved_preferences')); app('preferences')->mark(); return redirect(route('preferences.index')); diff --git a/app/Http/Controllers/Profile/DataController.php b/app/Http/Controllers/Profile/DataController.php index 35250c2080..12121b4251 100644 --- a/app/Http/Controllers/Profile/DataController.php +++ b/app/Http/Controllers/Profile/DataController.php @@ -21,7 +21,6 @@ namespace FireflyIII\Http\Controllers\Profile; - use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; @@ -86,4 +85,4 @@ class DataController extends Controller return redirect(route('profile.index')); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index f95586cb6c..ac640b2115 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -41,8 +41,12 @@ use FireflyIII\User; use Google2FA; use Hash; use Illuminate\Contracts\Auth\Guard; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use Laravel\Passport\ClientRepository; use Log; use PragmaRX\Recovery\Recovery; @@ -59,6 +63,7 @@ class ProfileController extends Controller /** * ProfileController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -67,7 +72,7 @@ class ProfileController extends Controller $this->middleware( static function ($request, $next) { - app('view')->share('title', (string)trans('firefly.profile')); + app('view')->share('title', (string) trans('firefly.profile')); app('view')->share('mainTitleIcon', 'fa-user'); return $next($request); @@ -83,7 +88,7 @@ class ProfileController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function changeEmail(Request $request) { @@ -98,7 +103,7 @@ class ProfileController extends Controller $title = auth()->user()->email; $email = auth()->user()->email; - $subTitle = (string)trans('firefly.change_your_email'); + $subTitle = (string) trans('firefly.change_your_email'); $subTitleIcon = 'fa-envelope'; return view('profile.change-email', compact('title', 'subTitle', 'subTitleIcon', 'email')); @@ -109,7 +114,7 @@ class ProfileController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function changePassword(Request $request) { @@ -123,7 +128,7 @@ class ProfileController extends Controller } $title = auth()->user()->email; - $subTitle = (string)trans('firefly.change_your_password'); + $subTitle = (string) trans('firefly.change_your_password'); $subTitleIcon = 'fa-key'; return view('profile.change-password', compact('title', 'subTitle', 'subTitleIcon')); @@ -132,7 +137,7 @@ class ProfileController extends Controller /** * View that generates a 2FA code for the user. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function code() { @@ -172,7 +177,7 @@ class ProfileController extends Controller $image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret); - return view('profile.code', compact('image', 'secret','codes')); + return view('profile.code', compact('image', 'secret', 'codes')); } /** @@ -181,9 +186,9 @@ class ProfileController extends Controller * @param UserRepositoryInterface $repository * @param string $token * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * * @throws FireflyException + * @return RedirectResponse|Redirector + * */ public function confirmEmailChange(UserRepositoryInterface $repository, string $token) { @@ -214,7 +219,7 @@ class ProfileController extends Controller $repository->unblockUser($user); // return to login. - session()->flash('success', (string)trans('firefly.login_with_new_email')); + session()->flash('success', (string) trans('firefly.login_with_new_email')); return redirect(route('login')); } @@ -224,7 +229,7 @@ class ProfileController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function deleteAccount(Request $request) { @@ -235,7 +240,7 @@ class ProfileController extends Controller // @codeCoverageIgnoreEnd } $title = auth()->user()->email; - $subTitle = (string)trans('firefly.delete_account'); + $subTitle = (string) trans('firefly.delete_account'); $subTitleIcon = 'fa-trash'; return view('profile.delete-account', compact('title', 'subTitle', 'subTitleIcon')); @@ -244,7 +249,7 @@ class ProfileController extends Controller /** * Delete 2FA routine. * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function deleteCode() { @@ -255,8 +260,8 @@ class ProfileController extends Controller $user = auth()->user(); $repository->setMFACode($user, null); - session()->flash('success', (string)trans('firefly.pref_two_factor_auth_disabled')); - session()->flash('info', (string)trans('firefly.pref_two_factor_auth_remove_it')); + session()->flash('success', (string) trans('firefly.pref_two_factor_auth_disabled')); + session()->flash('info', (string) trans('firefly.pref_two_factor_auth_remove_it')); return redirect(route('profile.index')); } @@ -264,7 +269,7 @@ class ProfileController extends Controller /** * Enable 2FA screen. * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function enable2FA() { @@ -279,7 +284,7 @@ class ProfileController extends Controller // If FF3 already has a secret, just set the two factor auth enabled to 1, // and let the user continue with the existing secret. - session()->flash('info', (string)trans('firefly.2fa_already_enabled')); + session()->flash('info', (string) trans('firefly.2fa_already_enabled')); return redirect(route('profile.index')); } @@ -287,7 +292,7 @@ class ProfileController extends Controller /** * Index for profile. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { @@ -320,7 +325,7 @@ class ProfileController extends Controller } /** - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function newBackupCodes() { @@ -335,6 +340,7 @@ class ProfileController extends Controller app('preferences')->set('mfa_recovery', $recoveryCodes); app('preferences')->mark(); + return view('profile.new-backup-codes', compact('codes')); } @@ -344,7 +350,7 @@ class ProfileController extends Controller * @param EmailFormRequest $request * @param UserRepositoryInterface $repository * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function postChangeEmail(EmailFormRequest $request, UserRepositoryInterface $repository) { @@ -362,7 +368,7 @@ class ProfileController extends Controller $newEmail = $request->string('email'); $oldEmail = $user->email; if ($newEmail === $user->email) { - session()->flash('error', (string)trans('firefly.email_not_changed')); + session()->flash('error', (string) trans('firefly.email_not_changed')); return redirect(route('profile.change-email'))->withInput(); } @@ -372,7 +378,7 @@ class ProfileController extends Controller Auth::guard()->logout(); $request->session()->invalidate(); - session()->flash('success', (string)trans('firefly.email_changed')); + session()->flash('success', (string) trans('firefly.email_changed')); return redirect(route('index')); } @@ -387,7 +393,7 @@ class ProfileController extends Controller // force user logout. Auth::guard()->logout(); $request->session()->invalidate(); - session()->flash('success', (string)trans('firefly.email_changed')); + session()->flash('success', (string) trans('firefly.email_changed')); return redirect(route('index')); } @@ -398,7 +404,7 @@ class ProfileController extends Controller * @param ProfileFormRequest $request * @param UserRepositoryInterface $repository * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function postChangePassword(ProfileFormRequest $request, UserRepositoryInterface $repository) { @@ -425,7 +431,7 @@ class ProfileController extends Controller } $repository->changePassword($user, $request->get('new_password')); - session()->flash('success', (string)trans('firefly.password_changed')); + session()->flash('success', (string) trans('firefly.password_changed')); return redirect(route('profile.index')); } @@ -436,7 +442,7 @@ class ProfileController extends Controller * * @param TokenFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function postCode(TokenFormRequest $request) { @@ -448,7 +454,7 @@ class ProfileController extends Controller $secret = session()->get('two-factor-secret'); $repository->setMFACode($user, $secret); - session()->flash('success', (string)trans('firefly.saved_preferences')); + session()->flash('success', (string) trans('firefly.saved_preferences')); app('preferences')->mark(); // also save the code so replay attack is prevented. @@ -475,12 +481,12 @@ class ProfileController extends Controller * @param UserRepositoryInterface $repository * @param DeleteAccountFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function postDeleteAccount(UserRepositoryInterface $repository, DeleteAccountFormRequest $request) { if (!Hash::check($request->get('password'), auth()->user()->password)) { - session()->flash('error', (string)trans('firefly.invalid_password')); + session()->flash('error', (string) trans('firefly.invalid_password')); return redirect(route('profile.delete-account')); } @@ -498,7 +504,7 @@ class ProfileController extends Controller /** * Regenerate access token. * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function regenerate() { @@ -506,7 +512,7 @@ class ProfileController extends Controller $user = auth()->user(); $token = $user->generateAccessToken(); app('preferences')->set('access_token', $token); - session()->flash('success', (string)trans('firefly.token_regenerated')); + session()->flash('success', (string) trans('firefly.token_regenerated')); return redirect(route('profile.index')); } @@ -518,9 +524,9 @@ class ProfileController extends Controller * @param string $token * @param string $hash * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * * @throws FireflyException + * @return RedirectResponse|Redirector + * */ public function undoEmailChange(UserRepositoryInterface $repository, string $token, string $hash) { @@ -564,7 +570,7 @@ class ProfileController extends Controller $repository->unblockUser($user); // return to login. - session()->flash('success', (string)trans('firefly.login_with_old_email')); + session()->flash('success', (string) trans('firefly.login_with_old_email')); return redirect(route('login')); } diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index 2db99b6225..f2c45d1ac3 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Recurring; - use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -31,7 +30,11 @@ use FireflyIII\Http\Requests\RecurrenceFormRequest; use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * @@ -46,6 +49,7 @@ class CreateController extends Controller /** * CreateController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -56,8 +60,8 @@ class CreateController 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.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->budgets = app(BudgetRepositoryInterface::class); @@ -72,7 +76,7 @@ class CreateController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request) { @@ -88,15 +92,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'), ]; @@ -104,13 +108,14 @@ class CreateController extends Controller $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); return view( - 'recurring.create', compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets') + 'recurring.create', + compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets') ); } @@ -120,7 +125,7 @@ class CreateController extends Controller * * @param RecurrenceFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(RecurrenceFormRequest $request) { @@ -129,13 +134,14 @@ class CreateController extends Controller $recurrence = $this->recurring->store($data); } catch (FireflyException $e) { session()->flash('error', $e->getMessage()); + 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(); $redirect = redirect($this->getPreviousUri('recurring.create.uri')); - 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); @@ -144,7 +150,5 @@ class CreateController extends Controller // redirect to previous URL. return $redirect; - } - } diff --git a/app/Http/Controllers/Recurring/DeleteController.php b/app/Http/Controllers/Recurring/DeleteController.php index e0c7e1e50f..1fa3304f5e 100644 --- a/app/Http/Controllers/Recurring/DeleteController.php +++ b/app/Http/Controllers/Recurring/DeleteController.php @@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\Recurring; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Recurrence; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class DeleteController @@ -39,6 +43,7 @@ class DeleteController extends Controller /** * DeleteController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -49,7 +54,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); @@ -63,11 +68,11 @@ class DeleteController extends Controller * * @param Recurrence $recurrence * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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->rememberPreviousUri('recurrences.delete.uri'); @@ -80,15 +85,15 @@ class DeleteController extends Controller * Destroy the recurring transaction. * * @param RecurringRepositoryInterface $repository - * @param Request $request - * @param Recurrence $recurrence + * @param Request $request + * @param Recurrence $recurrence * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @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->getPreviousUri('recurrences.delete.uri')); diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index 807eded1bc..fad9ef560c 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Recurring; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RecurrenceFormRequest; use FireflyIII\Models\Recurrence; @@ -31,7 +32,11 @@ use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Transformers\RecurrenceTransformer; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -47,6 +52,7 @@ class EditController extends Controller /** * EditController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -57,8 +63,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->budgets = app(BudgetRepositoryInterface::class); @@ -71,12 +77,12 @@ class EditController extends Controller /** * Edit a recurring transaction. * - * @param Request $request + * @param Request $request * @param Recurrence $recurrence * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException * + * @return Factory|View */ public function edit(Request $request, Recurrence $recurrence) { @@ -100,11 +106,11 @@ class EditController extends Controller } $request->session()->forget('recurrences.edit.fromUpdate'); - $repetitionEnd = 'forever'; + $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'; // @codeCoverageIgnore @@ -114,17 +120,17 @@ 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 = [ + $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'], ]; @@ -141,10 +147,10 @@ class EditController extends Controller * Update the recurring transaction. * * @param RecurrenceFormRequest $request - * @param Recurrence $recurrence + * @param Recurrence $recurrence * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException + * @return RedirectResponse|Redirector */ public function update(RecurrenceFormRequest $request, Recurrence $recurrence) { @@ -152,10 +158,10 @@ class EditController extends Controller $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])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); - 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 5f21c4c812..8311f20d94 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -25,14 +25,17 @@ namespace FireflyIII\Http\Controllers\Recurring; use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Recurrence; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Support\Http\Controllers\GetConfigurationData; use FireflyIII\Transformers\RecurrenceTransformer; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; +use Illuminate\View\View; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -58,7 +61,7 @@ class IndexController 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); @@ -73,14 +76,14 @@ class IndexController extends Controller * * @param Request $request * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException * + * @return Factory|View */ 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->recurring->get(); // split collection @@ -95,19 +98,19 @@ class IndexController extends Controller $recurring = []; /** @var Recurrence $recurrence */ foreach ($recurrences as $recurrence) { - $today = new Carbon; - $year = new Carbon; + $today = new Carbon; + $year = new Carbon; $year->addYear(); - if($recurrence->first_date > $today) { - $today =clone $recurrence->first_date; - $year = clone $today; + if ($recurrence->first_date > $today) { + $today = clone $recurrence->first_date; + $year = clone $today; $year->addYear(); } $array = $transformer->transform($recurrence); $array['first_date'] = new Carbon($array['first_date']); $array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']); $array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']); - $array['occurrences'] = array_slice($this->recurring->getOccurrencesInRange($recurrence->recurrenceRepetitions->first(), $today, $year),0,1); + $array['occurrences'] = array_slice($this->recurring->getOccurrencesInRange($recurrence->recurrenceRepetitions->first(), $today, $year), 0, 1); $recurring[] = $array; } $paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page); diff --git a/app/Http/Controllers/Recurring/ShowController.php b/app/Http/Controllers/Recurring/ShowController.php index b4da5e4436..23ddd02444 100644 --- a/app/Http/Controllers/Recurring/ShowController.php +++ b/app/Http/Controllers/Recurring/ShowController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Recurring; - use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -31,6 +30,8 @@ use FireflyIII\Models\Recurrence; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Support\Http\Controllers\GetConfigurationData; use FireflyIII\Transformers\RecurrenceTransformer; +use Illuminate\Contracts\View\Factory; +use Illuminate\View\View; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -45,6 +46,7 @@ class ShowController extends Controller /** * IndexController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -56,7 +58,7 @@ class ShowController 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); @@ -71,8 +73,8 @@ class ShowController extends Controller * * @param Recurrence $recurrence * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws FireflyException + * @return Factory|View */ public function show(Recurrence $recurrence) { @@ -90,8 +92,8 @@ class ShowController extends Controller } } - $subTitle = (string)trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]); + $subTitle = (string) trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]); return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups')); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php index b7eb005984..76f0c283fe 100644 --- a/app/Http/Controllers/Report/BudgetController.php +++ b/app/Http/Controllers/Report/BudgetController.php @@ -118,7 +118,8 @@ class BudgetController extends Controller = $report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budget['id']] ?? '0'; $report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budget['id']] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budget['id']], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budget['id']], + $journal['amount'] ); } } @@ -172,7 +173,8 @@ class BudgetController extends Controller 'sum' => '0', ]; $report[$sourceAccountId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']); } @@ -214,8 +216,8 @@ class BudgetController extends Controller ]; $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']; } } } @@ -295,11 +297,11 @@ class BudgetController extends Controller $pct = '0'; if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) { $pct = round(bcmul(bcdiv($sum, $total), '100')); - } $report[$budgetId]['currencies'][$currencyId]['sum_pct'] = $pct; } } + return view('reports.budget.partials.budgets', compact('sums', 'report')); } @@ -323,7 +325,7 @@ class BudgetController extends Controller $defaultCurrency = app('amount')->getDefaultCurrency(); /** @var Budget $budget */ foreach ($budgets as $budget) { - $budgetId = (int)$budget->id; + $budgetId = (int) $budget->id; $report['budgets'][$budgetId] = $report['budgets'][$budgetId] ?? [ 'budget_id' => $budgetId, 'budget_name' => $budget->name, @@ -335,9 +337,9 @@ class BudgetController extends Controller $limits = $this->blRepository->getBudgetLimits($budget, $start, $end); /** @var BudgetLimit $limit */ foreach ($limits as $limit) { - $limitId = (int)$limit->id; + $limitId = (int) $limit->id; $currency = $limit->transactionCurrency ?? $defaultCurrency; - $currencyId = (int)$currency->id; + $currencyId = (int) $currency->id; $expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $accounts, new Collection([$budget])); $spent = $expenses[$currencyId]['sum'] ?? '0'; $left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent); @@ -392,7 +394,7 @@ class BudgetController extends Controller foreach ($noBudget as $noBudgetEntry) { // currency information: - $nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $defaultCurrency->id); + $nbCurrencyId = (int) ($noBudgetEntry['currency_id'] ?? $defaultCurrency->id); $nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $defaultCurrency->code; $nbCurrencyName = $noBudgetEntry['currency_name'] ?? $defaultCurrency->name; $nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $defaultCurrency->symbol; @@ -426,14 +428,13 @@ class BudgetController extends Controller $report['sums'][$nbCurrencyId]['overspent'] = $report['sums'][$nbCurrencyId]['overspent'] ?? '0'; $report['sums'][$nbCurrencyId]['left'] = $report['sums'][$nbCurrencyId]['left'] ?? '0'; $report['sums'][$nbCurrencyId]['budgeted'] = $report['sums'][$nbCurrencyId]['budgeted'] ?? '0'; - } // make percentages based on total amount. foreach ($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 = $report['sums'][$currencyId]['spent'] ?? '0'; $spentPct = '0'; @@ -504,8 +505,8 @@ class BudgetController extends Controller ]; $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); + $report[$key]['sum'] = bcadd($report[$key] ['sum'], $journal['amount']); + $report[$key]['avg'] = bcdiv($report[$key]['sum'], (string) $count); } } } @@ -541,7 +542,7 @@ class BudgetController 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']->formatLocalized($this->monthAndDayFormat), 'destination_account_name' => $journal['destination_account_name'], @@ -571,5 +572,4 @@ class BudgetController extends Controller return $result; } - } diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php index 96b7feb93a..8219a43d44 100644 --- a/app/Http/Controllers/Report/CategoryController.php +++ b/app/Http/Controllers/Report/CategoryController.php @@ -114,10 +114,12 @@ class CategoryController extends Controller 'sum' => '0', ]; $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['spent'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['spent'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['spent'], + $journal['amount'] ); $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['sum'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['sum'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['sum'], + $journal['amount'] ); } } @@ -152,10 +154,12 @@ class CategoryController extends Controller 'sum' => '0', ]; $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['earned'] = bcadd( - $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['earned'], $journal['amount'] + $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['earned'], + $journal['amount'] ); $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['sum'] = bcadd( - $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['sum'], $journal['amount'] + $report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['sum'], + $journal['amount'] ); } } @@ -214,10 +218,12 @@ class CategoryController extends Controller 'sum' => '0', ]; $report[$sourceAccountId]['currencies'][$currencyId]['spent'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['spent'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['spent'], + $journal['amount'] ); $report[$sourceAccountId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']); $sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']); @@ -250,10 +256,12 @@ class CategoryController extends Controller 'sum' => '0', ]; $report[$destinationAccountId]['currencies'][$currencyId]['earned'] = bcadd( - $report[$destinationAccountId]['currencies'][$currencyId]['earned'], $journal['amount'] + $report[$destinationAccountId]['currencies'][$currencyId]['earned'], + $journal['amount'] ); $report[$destinationAccountId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$destinationAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$destinationAccountId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']); $sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']); @@ -296,8 +304,8 @@ class CategoryController extends Controller ]; $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']; } } } @@ -349,8 +357,8 @@ class CategoryController extends Controller ]; $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']; } } } @@ -420,10 +428,12 @@ class CategoryController extends Controller 'currency_decimal_places' => $currency['currency_decimal_places'], ]; $report[$categoryId]['currencies'][$currencyId]['spent'] = bcadd( - $report[$categoryId]['currencies'][$currencyId]['spent'], $journal['amount'] + $report[$categoryId]['currencies'][$currencyId]['spent'], + $journal['amount'] ); $report[$categoryId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$categoryId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$categoryId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']); @@ -459,10 +469,12 @@ class CategoryController extends Controller 'currency_decimal_places' => $currency['currency_decimal_places'], ]; $report[$categoryId]['currencies'][$currencyId]['earned'] = bcadd( - $report[$categoryId]['currencies'][$currencyId]['earned'], $journal['amount'] + $report[$categoryId]['currencies'][$currencyId]['earned'], + $journal['amount'] ); $report[$categoryId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$categoryId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$categoryId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']); @@ -517,31 +529,31 @@ class CategoryController extends Controller $data = []; $with = $opsRepository->listExpenses($start, $end, $accounts); $without = $noCatRepos->listExpenses($start, $end, $accounts); - foreach([$with, $without] as $set) { - foreach ($set as $currencyId => $currencyRow) { - 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' => [], + foreach ([$with, $without] as $set) { + foreach ($set as $currencyId => $currencyRow) { + 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' => [], - ]; - foreach ($categoryRow['transaction_journals'] as $journalId => $journal) { - $date = $journal['date']->format($format); - $data[$key]['entries'][$date] = $data[$key]['entries'][$date] ?? '0'; - $data[$key]['entries'][$date] = bcadd($data[$key]['entries'][$date], $journal['amount']); - $data[$key]['sum'] = bcadd($data[$key]['sum'], $journal['amount']); + ]; + foreach ($categoryRow['transaction_journals'] as $journalId => $journal) { + $date = $journal['date']->format($format); + $data[$key]['entries'][$date] = $data[$key]['entries'][$date] ?? '0'; + $data[$key]['entries'][$date] = bcadd($data[$key]['entries'][$date], $journal['amount']); + $data[$key]['sum'] = bcadd($data[$key]['sum'], $journal['amount']); + } } } } - } $cache->store($data); @@ -603,7 +615,7 @@ class CategoryController extends Controller $data = []; $with = $opsRepository->listIncome($start, $end, $accounts); $without = $noCatRepos->listIncome($start, $end, $accounts); - foreach([$with, $without] as $set) { + foreach ([$with, $without] as $set) { foreach ($set as $currencyId => $currencyRow) { foreach ($currencyRow['categories'] as $categoryId => $categoryRow) { $key = sprintf('%d-%d', $currencyId, $categoryId); @@ -722,22 +734,26 @@ class CategoryController extends Controller $report['sums'][$currencyId]['sum'] = bcadd($report['sums'][$currencyId]['sum'], $journal['amount']); // sum of spent: $report['sums'][$currencyId]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd( - $report['sums'][$currencyId]['spent'], $journal['amount'] + $report['sums'][$currencyId]['spent'], + $journal['amount'] ) : $report['sums'][$currencyId]['spent']; // sum of earned $report['sums'][$currencyId]['earned'] = 1 === bccomp($journal['amount'], '0') ? bcadd( - $report['sums'][$currencyId]['earned'], $journal['amount'] + $report['sums'][$currencyId]['earned'], + $journal['amount'] ) : $report['sums'][$currencyId]['earned']; // sum of category $report['categories'][$key]['sum'] = bcadd($report['categories'][$key]['sum'], $journal['amount']); // total spent in category $report['categories'][$key]['spent'] = -1 === bccomp($journal['amount'], '0') ? bcadd( - $report['categories'][$key]['spent'], $journal['amount'] + $report['categories'][$key]['spent'], + $journal['amount'] ) : $report['categories'][$key]['spent']; // total earned in category $report['categories'][$key]['earned'] = 1 === bccomp($journal['amount'], '0') ? bcadd( - $report['categories'][$key]['earned'], $journal['amount'] + $report['categories'][$key]['earned'], + $journal['amount'] ) : $report['categories'][$key]['earned']; } } @@ -777,7 +793,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']->formatLocalized($this->monthAndDayFormat), 'destination_account_name' => $journal['destination_account_name'], @@ -827,7 +843,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']->formatLocalized($this->monthAndDayFormat), 'source_account_name' => $journal['source_account_name'], @@ -871,6 +887,4 @@ class CategoryController extends Controller return false; } - - } diff --git a/app/Http/Controllers/Report/DoubleController.php b/app/Http/Controllers/Report/DoubleController.php index c08b6f800f..f1d399cb8a 100644 --- a/app/Http/Controllers/Report/DoubleController.php +++ b/app/Http/Controllers/Report/DoubleController.php @@ -100,8 +100,8 @@ class DoubleController extends Controller ]; $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 @@ -152,8 +152,8 @@ class DoubleController extends Controller ]; $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 @@ -410,7 +410,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']->formatLocalized($this->monthAndDayFormat), 'destination_account_name' => $journal['destination_account_name'], @@ -459,7 +459,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']->formatLocalized($this->monthAndDayFormat), 'destination_account_name' => $journal['destination_account_name'], @@ -773,10 +773,10 @@ class DoubleController extends Controller /** * TODO this method is double. * - * @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 */ diff --git a/app/Http/Controllers/Report/TagController.php b/app/Http/Controllers/Report/TagController.php index a2b8ca286c..ccba00cc66 100644 --- a/app/Http/Controllers/Report/TagController.php +++ b/app/Http/Controllers/Report/TagController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Report; - use Carbon\Carbon; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; @@ -112,10 +111,12 @@ class TagController extends Controller 'sum' => '0', ]; $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['spent'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['spent'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['spent'], + $journal['amount'] ); $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'], + $journal['amount'] ); } } @@ -150,10 +151,12 @@ class TagController extends Controller 'sum' => '0', ]; $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['earned'] = bcadd( - $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['earned'], $journal['amount'] + $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['earned'], + $journal['amount'] ); $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'] = bcadd( - $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'], $journal['amount'] + $report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['sum'], + $journal['amount'] ); } } @@ -212,10 +215,12 @@ class TagController extends Controller 'sum' => '0', ]; $report[$sourceAccountId]['currencies'][$currencyId]['spent'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['spent'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['spent'], + $journal['amount'] ); $report[$sourceAccountId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$sourceAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$sourceAccountId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']); $sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']); @@ -248,10 +253,12 @@ class TagController extends Controller 'sum' => '0', ]; $report[$destinationAccountId]['currencies'][$currencyId]['earned'] = bcadd( - $report[$destinationAccountId]['currencies'][$currencyId]['earned'], $journal['amount'] + $report[$destinationAccountId]['currencies'][$currencyId]['earned'], + $journal['amount'] ); $report[$destinationAccountId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$destinationAccountId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$destinationAccountId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']); $sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']); @@ -294,8 +301,8 @@ class TagController extends Controller ]; $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']; } } } @@ -347,8 +354,8 @@ class TagController extends Controller ]; $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']; } } } @@ -418,10 +425,12 @@ class TagController extends Controller 'currency_decimal_places' => $currency['currency_decimal_places'], ]; $report[$tagId]['currencies'][$currencyId]['spent'] = bcadd( - $report[$tagId]['currencies'][$currencyId]['spent'], $journal['amount'] + $report[$tagId]['currencies'][$currencyId]['spent'], + $journal['amount'] ); $report[$tagId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$tagId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$tagId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']); @@ -457,10 +466,12 @@ class TagController extends Controller 'currency_decimal_places' => $currency['currency_decimal_places'], ]; $report[$tagId]['currencies'][$currencyId]['earned'] = bcadd( - $report[$tagId]['currencies'][$currencyId]['earned'], $journal['amount'] + $report[$tagId]['currencies'][$currencyId]['earned'], + $journal['amount'] ); $report[$tagId]['currencies'][$currencyId]['sum'] = bcadd( - $report[$tagId]['currencies'][$currencyId]['sum'], $journal['amount'] + $report[$tagId]['currencies'][$currencyId]['sum'], + $journal['amount'] ); $sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']); @@ -491,7 +502,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']->formatLocalized($this->monthAndDayFormat), 'destination_account_name' => $journal['destination_account_name'], @@ -541,7 +552,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']->formatLocalized($this->monthAndDayFormat), 'source_account_name' => $journal['source_account_name'], @@ -571,5 +582,4 @@ class TagController extends Controller return $result; } - -} \ No newline at end of file +} diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 249c60a001..a089138782 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Generator\Report\ReportGeneratorFactory; use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Http\Requests\ReportFormRequest; @@ -32,8 +33,11 @@ use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Support\Http\Controllers\RenderPartialViews; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -59,7 +63,7 @@ class ReportController extends Controller $this->middleware( function ($request, $next) { - app('view')->share('title', (string)trans('firefly.reports')); + app('view')->share('title', (string) trans('firefly.reports')); app('view')->share('mainTitleIcon', 'fa-line-chart'); app('view')->share('subTitleIcon', 'fa-calendar'); $this->helper = app(ReportHelperInterface::class); @@ -70,39 +74,6 @@ class ReportController extends Controller ); } - /** - * Show account report. - * - * @param Collection $accounts - * @param Collection $expense - * @param Carbon $start - * @param Carbon $end - * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string - * @throws \FireflyIII\Exceptions\FireflyException - */ - public function doubleReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end) - { - if ($end < $start) { - [$start, $end] = [$end, $start]; - } - - $this->repository->cleanupBudgets(); - - app('view')->share( - 'subTitle', trans( - 'firefly.report_double', - ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] - ) - ); - - $generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end); - $generator->setAccounts($accounts); - $generator->setExpense($expense); - - return $generator->generate(); - } - /** * Show audit report. * @@ -110,14 +81,14 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string + * @throws FireflyException + * @return Factory|View|string * - * @throws \FireflyIII\Exceptions\FireflyException */ public function auditReport(Collection $accounts, Carbon $start, Carbon $end) { if ($end < $start) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); // @codeCoverageIgnore } $this->repository->cleanupBudgets(); @@ -138,7 +109,6 @@ class ReportController extends Controller return $generator->generate(); } - /** * Show budget report. * @@ -147,14 +117,14 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string + * @throws FireflyException + * @return Factory|View|string * - * @throws \FireflyIII\Exceptions\FireflyException */ public function budgetReport(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end) { if ($end < $start) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); // @codeCoverageIgnore } $this->repository->cleanupBudgets(); @@ -176,7 +146,6 @@ class ReportController extends Controller return $generator->generate(); } - /** * Show category report. * @@ -185,14 +154,14 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string + * @throws FireflyException + * @return Factory|View|string * - * @throws \FireflyIII\Exceptions\FireflyException */ public function categoryReport(Collection $accounts, Collection $categories, Carbon $start, Carbon $end) { if ($end < $start) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); // @codeCoverageIgnore } $this->repository->cleanupBudgets(); @@ -221,14 +190,14 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string + * @throws FireflyException + * @return Factory|View|string * - * @throws \FireflyIII\Exceptions\FireflyException */ public function defaultReport(Collection $accounts, Carbon $start, Carbon $end) { if ($end < $start) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); } $this->repository->cleanupBudgets(); @@ -250,12 +219,46 @@ class ReportController extends Controller return $generator->generate(); } + /** + * Show account report. + * + * @param Collection $accounts + * @param Collection $expense + * @param Carbon $start + * @param Carbon $end + * + * @throws FireflyException + * @return Factory|View|string + */ + public function doubleReport(Collection $accounts, Collection $expense, Carbon $start, Carbon $end) + { + if ($end < $start) { + [$start, $end] = [$end, $start]; + } + + $this->repository->cleanupBudgets(); + + app('view')->share( + 'subTitle', + trans( + 'firefly.report_double', + ['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] + ) + ); + + $generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end); + $generator->setAccounts($accounts); + $generator->setExpense($expense); + + return $generator->generate(); + } + /** * Show index. * * @param AccountRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(AccountRepositoryInterface $repository) { @@ -275,20 +278,20 @@ class ReportController extends Controller $role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role')); if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) { - $role = sprintf('opt_group_l_%s',$type); + $role = sprintf('opt_group_l_%s', $type); } if ('' === $role || 'opt_group_' === $role) { $role = 'opt_group_defaultAsset'; } - $groupedAccounts[trans(sprintf('firefly.%s',$role))][$account->id] = $account; + $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account; } ksort($groupedAccounts); - $accountList = implode(',', $accounts->pluck('id')->toArray()); + $accountList = implode(',', $accounts->pluck('id')->toArray()); $this->repository->cleanupBudgets(); - return view('reports.index', compact('months', 'accounts', 'start', 'accountList','groupedAccounts', 'customFiscalYear')); + return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'groupedAccounts', 'customFiscalYear')); } /** @@ -327,9 +330,9 @@ class ReportController extends Controller * * @param ReportFormRequest $request * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @throws FireflyException * - * @throws \FireflyIII\Exceptions\FireflyException + * @return RedirectResponse|Redirector * */ public function postIndex(ReportFormRequest $request) @@ -342,42 +345,42 @@ class ReportController extends Controller $categories = implode(',', $request->getCategoryList()->pluck('id')->toArray()); $budgets = implode(',', $request->getBudgetList()->pluck('id')->toArray()); $tags = implode(',', $request->getTagList()->pluck('id')->toArray()); - $double = implode(',', $request->getDoubleList()->pluck('id')->toArray()); + $double = implode(',', $request->getDoubleList()->pluck('id')->toArray()); $uri = route('reports.index'); if (0 === $request->getAccountList()->count()) { Log::debug('Account count is zero'); - session()->flash('error', (string)trans('firefly.select_at_least_one_account')); + session()->flash('error', (string) trans('firefly.select_at_least_one_account')); return redirect(route('reports.index')); } if ('category' === $reportType && 0 === $request->getCategoryList()->count()) { - session()->flash('error', (string)trans('firefly.select_at_least_one_category')); + session()->flash('error', (string) trans('firefly.select_at_least_one_category')); return redirect(route('reports.index')); } if ('budget' === $reportType && 0 === $request->getBudgetList()->count()) { - session()->flash('error', (string)trans('firefly.select_at_least_one_budget')); + session()->flash('error', (string) trans('firefly.select_at_least_one_budget')); return redirect(route('reports.index')); } if ('tag' === $reportType && 0 === $request->getTagList()->count()) { - session()->flash('error', (string)trans('firefly.select_at_least_one_tag')); + session()->flash('error', (string) trans('firefly.select_at_least_one_tag')); return redirect(route('reports.index')); } if ('double' === $reportType && 0 === $request->getDoubleList()->count()) { - session()->flash('error', (string)trans('firefly.select_at_least_one_expense')); + session()->flash('error', (string) trans('firefly.select_at_least_one_expense')); return redirect(route('reports.index')); } if ($request->getEndDate() < $request->getStartDate()) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); } switch ($reportType) { @@ -413,13 +416,13 @@ class ReportController extends Controller * @param Carbon $start * @param Carbon $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string - * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException + * @return Factory|View|string */ public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) { if ($end < $start) { - return view('error')->with('message', (string)trans('firefly.end_after_start_date')); // @codeCoverageIgnore + return view('error')->with('message', (string) trans('firefly.end_after_start_date')); // @codeCoverageIgnore } $this->repository->cleanupBudgets(); @@ -440,6 +443,4 @@ class ReportController extends Controller return $generator->generate(); } - - } diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php index 561d41a3cf..e7a50340fd 100644 --- a/app/Http/Controllers/Rule/CreateController.php +++ b/app/Http/Controllers/Rule/CreateController.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Rule; - use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleFormRequest; use FireflyIII\Models\Bill; @@ -33,8 +32,11 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Support\Http\Controllers\ModelInformation; use FireflyIII\Support\Http\Controllers\RuleManagement; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class CreateController @@ -56,7 +58,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); @@ -72,7 +74,7 @@ class CreateController extends Controller * @param Request $request * @param RuleGroup $ruleGroup * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request, RuleGroup $ruleGroup = null) { @@ -95,9 +97,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 @@ -110,43 +112,29 @@ class CreateController extends Controller session()->forget('rules.create.fromStore'); return view( - 'rules.rule.create', compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'ruleGroup', 'subTitle') + 'rules.rule.create', + compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'ruleGroup', 'subTitle') ); } - /** - * @param Rule $rule - * - * @return RedirectResponse - */ - public function duplicate(Rule $rule): RedirectResponse - { - /** @var Rule $newRule */ - $newRule = $this->ruleRepos->duplicate($rule); - - session()->flash('success', trans('firefly.duplicated_rule', ['title' => $rule->title,'newTitle' => $newRule->title])); - - return redirect(route('rules.index')); - } - /** * Create a new rule. It will be stored under the given $ruleGroup. * * @param Request $request * @param Bill $bill * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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(); $this->createDefaultRule(); $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. @@ -160,7 +148,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); @@ -172,7 +160,8 @@ class CreateController extends Controller session()->forget('rules.create.fromStore'); return view( - 'rules.rule.create', compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'subTitle') + 'rules.rule.create', + compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'subTitle') ); } @@ -182,14 +171,14 @@ class CreateController extends Controller */ public function createFromJournal(Request $request, TransactionJournal $journal) { - $request->session()->flash('info', (string)trans('firefly.instructions_rule_from_journal', ['name' => e($journal->name)])); + $request->session()->flash('info', (string) trans('firefly.instructions_rule_from_journal', ['name' => e($journal->name)])); $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); - $oldActions = []; + $oldTriggers = $this->getTriggersForJournal($journal); + $oldActions = []; $triggerCount = count($oldTriggers); $actionCount = count($oldActions); @@ -199,8 +188,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]), ]; // flash old data @@ -213,9 +202,24 @@ class CreateController extends Controller session()->forget('rules.create.fromStore'); return view( - 'rules.rule.create', compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'subTitle') + 'rules.rule.create', + compact('subTitleIcon', 'oldTriggers', 'preFilled', 'oldActions', 'triggerCount', 'actionCount', 'subTitle') ); + } + /** + * @param Rule $rule + * + * @return RedirectResponse + */ + public function duplicate(Rule $rule): RedirectResponse + { + /** @var Rule $newRule */ + $newRule = $this->ruleRepos->duplicate($rule); + + session()->flash('success', trans('firefly.duplicated_rule', ['title' => $rule->title, 'newTitle' => $newRule->title])); + + return redirect(route('rules.index')); } /** @@ -223,29 +227,29 @@ class CreateController extends Controller * * @param RuleFormRequest $request * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector * */ public function store(RuleFormRequest $request) { $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')])); // @codeCoverageIgnore + if ('true' === $request->get('return_to_bill') && (int) $request->get('bill_id') > 0) { + return redirect(route('bills.show', [(int) $request->get('bill_id')])); // @codeCoverageIgnore } // redirect to new bill creation. - if ((int)$request->get('bill_id') > 0) { + if ((int) $request->get('bill_id') > 0) { return redirect($this->getPreviousUri('bills.create.uri')); // @codeCoverageIgnore } $redirect = redirect($this->getPreviousUri('rules.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart session()->put('rules.create.fromStore', true); $redirect = redirect(route('rules.create', [$data['rule_group_id']]))->withInput(); @@ -254,5 +258,4 @@ class CreateController extends Controller return $redirect; } - } diff --git a/app/Http/Controllers/Rule/DeleteController.php b/app/Http/Controllers/Rule/DeleteController.php index 15ccb723c1..212631438d 100644 --- a/app/Http/Controllers/Rule/DeleteController.php +++ b/app/Http/Controllers/Rule/DeleteController.php @@ -27,7 +27,9 @@ namespace FireflyIII\Http\Controllers\Rule; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Rule; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; +use Illuminate\View\View; /** * Class DeleteController @@ -39,6 +41,7 @@ class DeleteController extends Controller /** * RuleController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -47,7 +50,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,11 +65,11 @@ class DeleteController extends Controller * * @param Rule $rule * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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->rememberPreviousUri('rules.delete.uri'); @@ -86,7 +89,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->getPreviousUri('rules.delete.uri')); diff --git a/app/Http/Controllers/Rule/EditController.php b/app/Http/Controllers/Rule/EditController.php index 017bc3236f..bdeea2771b 100644 --- a/app/Http/Controllers/Rule/EditController.php +++ b/app/Http/Controllers/Rule/EditController.php @@ -30,8 +30,11 @@ use FireflyIII\Models\Rule; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Support\Http\Controllers\RenderPartialViews; use FireflyIII\Support\Http\Controllers\RuleManagement; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class EditController @@ -45,6 +48,7 @@ class EditController extends Controller /** * RuleController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -53,7 +57,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); @@ -69,7 +73,7 @@ class EditController extends Controller * @param Request $request * @param Rule $rule * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(Request $request, Rule $rule) { @@ -95,15 +99,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')) { @@ -122,17 +126,17 @@ class EditController extends Controller * @param RuleFormRequest $request * @param Rule $rule * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function update(RuleFormRequest $request, Rule $rule) { $data = $request->getRuleData(); $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->getPreviousUri('rules.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart session()->put('rules.edit.fromUpdate', true); diff --git a/app/Http/Controllers/Rule/IndexController.php b/app/Http/Controllers/Rule/IndexController.php index b5da7dbed2..0233337bc4 100644 --- a/app/Http/Controllers/Rule/IndexController.php +++ b/app/Http/Controllers/Rule/IndexController.php @@ -28,9 +28,12 @@ use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Support\Http\Controllers\RuleManagement; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class IndexController @@ -45,6 +48,7 @@ class IndexController extends Controller /** * RuleController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -52,7 +56,7 @@ class IndexController extends Controller parent::__construct(); $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->ruleGroupRepos = app(RuleGroupRepositoryInterface::class); $this->ruleRepos = app(RuleRepositoryInterface::class); @@ -67,7 +71,7 @@ class IndexController extends Controller * * @param Rule $rule * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function down(Rule $rule) { @@ -79,7 +83,7 @@ class IndexController extends Controller /** * Index of all rules and groups. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index() { @@ -134,7 +138,7 @@ class IndexController extends Controller * * @param Rule $rule * - * @return RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function up(Rule $rule) { diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index 90df0060e0..807b6588fb 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -38,9 +38,11 @@ use FireflyIII\Support\Http\Controllers\RuleManagement; use FireflyIII\TransactionRules\Engine\RuleEngine; use FireflyIII\TransactionRules\TransactionMatcher; use FireflyIII\User; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; use Throwable; @@ -63,7 +65,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'); $this->accountRepos = app(AccountRepositoryInterface::class); @@ -77,7 +79,7 @@ class SelectController extends Controller * Execute the given rule on a set of existing transactions. * * @param SelectTransactionsRequest $request - * @param Rule $rule + * @param Rule $rule * * @return RedirectResponse */ @@ -89,7 +91,7 @@ class SelectController extends Controller $accounts = $this->accountRepos->getAccountsById($request->get('accounts')); $startDate = new Carbon($request->get('start_date')); $endDate = new Carbon($request->get('end_date')); - $rules = [$rule->id]; + $rules = [$rule->id]; /** @var RuleEngine $ruleEngine */ $ruleEngine = app(RuleEngine::class); @@ -111,7 +113,7 @@ class SelectController extends Controller } // Tell the user that the job is queued - session()->flash('success', (string)trans('firefly.applied_rule_selection', ['title' => $rule->title])); + session()->flash('success', (string) trans('firefly.applied_rule_selection', ['title' => $rule->title])); return redirect()->route('rules.index'); } @@ -122,14 +124,14 @@ class SelectController extends Controller * * @param Rule $rule * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function selectTransactions(Rule $rule) { // 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')); } @@ -153,11 +155,11 @@ class SelectController extends Controller $triggers = $this->getValidTriggerList($request); if (0 === count($triggers)) { - return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore + return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore } - $limit = (int)config('firefly.test-triggers.limit'); - $range = (int)config('firefly.test-triggers.range'); + $limit = (int) config('firefly.test-triggers.limit'); + $range = (int) config('firefly.test-triggers.range'); $matchingTransactions = new Collection; $strict = '1' === $request->get('strict'); /** @var TransactionMatcher $matcher */ @@ -179,10 +181,10 @@ class SelectController extends Controller // Warn the user if only a subset of transactions is returned $warning = ''; if (count($matchingTransactions) === $limit) { - $warning = (string)trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore + $warning = (string) trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore } if (0 === count($matchingTransactions)) { - $warning = (string)trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore + $warning = (string) trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore } // Return json response @@ -219,11 +221,11 @@ class SelectController extends Controller $triggers = $rule->ruleTriggers; if (0 === count($triggers)) { - return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore + return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore } - $limit = (int)config('firefly.test-triggers.limit'); - $range = (int)config('firefly.test-triggers.range'); + $limit = (int) config('firefly.test-triggers.limit'); + $range = (int) config('firefly.test-triggers.range'); $matchingTransactions = new Collection; /** @var TransactionMatcher $matcher */ @@ -243,10 +245,10 @@ class SelectController extends Controller // Warn the user if only a subset of transactions is returned $warning = ''; if (count($matchingTransactions) === $limit) { - $warning = (string)trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore + $warning = (string) trans('firefly.warning_transaction_subset', ['max_num_transactions' => $limit]); // @codeCoverageIgnore } if (0 === count($matchingTransactions)) { - $warning = (string)trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore + $warning = (string) trans('firefly.warning_no_matching_transactions', ['num_transactions' => $range]); // @codeCoverageIgnore } // Return json response diff --git a/app/Http/Controllers/RuleGroup/CreateController.php b/app/Http/Controllers/RuleGroup/CreateController.php index 5c6cbed640..d2edd4df2c 100644 --- a/app/Http/Controllers/RuleGroup/CreateController.php +++ b/app/Http/Controllers/RuleGroup/CreateController.php @@ -27,6 +27,10 @@ namespace FireflyIII\Http\Controllers\RuleGroup; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleGroupFormRequest; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class CreateController @@ -38,6 +42,7 @@ class CreateController extends Controller /** * CreateController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -46,7 +51,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); @@ -59,12 +64,12 @@ class CreateController extends Controller /** * Create a new rule group. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ 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')) { @@ -80,18 +85,18 @@ class CreateController extends Controller * * @param RuleGroupFormRequest $request * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(RuleGroupFormRequest $request) { $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->getPreviousUri('rule-groups.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart session()->put('rule-groups.create.fromStore', true); diff --git a/app/Http/Controllers/RuleGroup/DeleteController.php b/app/Http/Controllers/RuleGroup/DeleteController.php index 0f35f290c5..a06fadf159 100644 --- a/app/Http/Controllers/RuleGroup/DeleteController.php +++ b/app/Http/Controllers/RuleGroup/DeleteController.php @@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\RuleGroup; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class DeleteController @@ -39,6 +43,7 @@ class DeleteController extends Controller /** * DeleteController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -47,7 +52,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); @@ -63,11 +68,11 @@ class DeleteController extends Controller * * @param RuleGroup $ruleGroup * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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->rememberPreviousUri('rule-groups.delete.uri'); @@ -78,20 +83,20 @@ class DeleteController extends Controller /** * Actually destroy the rule group. * - * @param Request $request + * @param Request $request * @param RuleGroup $ruleGroup * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(Request $request, RuleGroup $ruleGroup) { $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->getPreviousUri('rule-groups.delete.uri')); diff --git a/app/Http/Controllers/RuleGroup/EditController.php b/app/Http/Controllers/RuleGroup/EditController.php index 4e7963b768..7ace86699b 100644 --- a/app/Http/Controllers/RuleGroup/EditController.php +++ b/app/Http/Controllers/RuleGroup/EditController.php @@ -27,7 +27,11 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleGroupFormRequest; use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class EditController @@ -39,6 +43,7 @@ class EditController extends Controller /** * EditController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -47,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); @@ -62,7 +67,7 @@ class EditController extends Controller * * @param RuleGroup $ruleGroup * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function down(RuleGroup $ruleGroup) { @@ -75,18 +80,18 @@ class EditController extends Controller /** * Edit a rule group. * - * @param Request $request + * @param Request $request * @param RuleGroup $ruleGroup * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @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, + $preFilled = [ + 'active' => $hasOldInput ? (bool) $request->old('active') : $ruleGroup->active, ]; @@ -105,7 +110,7 @@ class EditController extends Controller * * @param RuleGroup $ruleGroup * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector * */ public function up(RuleGroup $ruleGroup) @@ -119,24 +124,24 @@ class EditController extends Controller * Update the rule group. * * @param RuleGroupFormRequest $request - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * - * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return $this|RedirectResponse|Redirector */ public function update(RuleGroupFormRequest $request, RuleGroup $ruleGroup) { $data = [ 'title' => $request->string('title'), 'description' => $request->nlString('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->getPreviousUri('rule-groups.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart session()->put('rule-groups.edit.fromUpdate', true); diff --git a/app/Http/Controllers/RuleGroup/ExecutionController.php b/app/Http/Controllers/RuleGroup/ExecutionController.php index 1deac6a443..fdece519f2 100644 --- a/app/Http/Controllers/RuleGroup/ExecutionController.php +++ b/app/Http/Controllers/RuleGroup/ExecutionController.php @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\RuleGroup; use Carbon\Carbon; +use Exception; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\SelectTransactionsRequest; @@ -33,7 +34,9 @@ use FireflyIII\Models\RuleGroup; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\TransactionRules\Engine\RuleEngine; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; +use Illuminate\View\View; use Log; /** @@ -49,6 +52,7 @@ class ExecutionController extends Controller /** * ExecutionController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -57,7 +61,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->repository = app(AccountRepositoryInterface::class); @@ -73,10 +77,10 @@ class ExecutionController extends Controller * Execute the given rulegroup on a set of existing transactions. * * @param SelectTransactionsRequest $request - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * + * @throws Exception * @return RedirectResponse - * @throws \Exception */ public function execute(SelectTransactionsRequest $request, RuleGroup $ruleGroup): RedirectResponse { @@ -113,7 +117,7 @@ class ExecutionController extends Controller } // 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'); } @@ -123,13 +127,13 @@ class ExecutionController extends Controller * * @param RuleGroup $ruleGroup * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function selectTransactions(RuleGroup $ruleGroup) { $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/SearchController.php b/app/Http/Controllers/SearchController.php index faafb73e10..992579db8a 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -23,8 +23,10 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; use FireflyIII\Support\Search\SearchInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\View\View; use Log; use Throwable; @@ -43,7 +45,7 @@ class SearchController extends Controller $this->middleware( static function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-search'); - app('view')->share('title', (string)trans('firefly.search')); + app('view')->share('title', (string) trans('firefly.search')); return $next($request); } @@ -56,19 +58,19 @@ class SearchController extends Controller * @param Request $request * @param SearchInterface $searcher * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(Request $request, SearchInterface $searcher) { - $fullQuery = (string)$request->get('search'); - $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); + $fullQuery = (string) $request->get('search'); + $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); // parse search terms: $searcher->parseQuery($fullQuery); $query = $searcher->getWordsAsString(); $modifiers = $searcher->getModifiers(); - $subTitle = (string)trans('breadcrumbs.search_result', ['query' => $query]); + $subTitle = (string) trans('breadcrumbs.search_result', ['query' => $query]); - return view('search.index', compact('query', 'modifiers', 'page','fullQuery', 'subTitle')); + return view('search.index', compact('query', 'modifiers', 'page', 'fullQuery', 'subTitle')); } /** @@ -77,16 +79,16 @@ class SearchController extends Controller * @param Request $request * @param SearchInterface $searcher * - * @return \Illuminate\Http\JsonResponse + * @return JsonResponse */ public function search(Request $request, SearchInterface $searcher): JsonResponse { - $fullQuery = (string)$request->get('query'); - $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); + $fullQuery = (string) $request->get('query'); + $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page'); $searcher->parseQuery($fullQuery); $searcher->setPage($page); - $searcher->setLimit((int)config('firefly.search_result_limit')); + $searcher->setLimit((int) config('firefly.search_result_limit')); $groups = $searcher->searchTransactions(); $hasPages = $groups->hasPages(); $searchTime = round($searcher->searchTime(), 3); // in seconds diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 57970c23e9..725fa72a80 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -31,7 +31,9 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Support\Facades\Preferences; use FireflyIII\Support\Http\Controllers\GetConfigurationData; use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Illuminate\Support\Arr; use Laravel\Passport\Passport; use Log; @@ -113,15 +115,15 @@ class InstallController extends Controller /** * Show index. * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function index() { // index will set FF3 version. - app('fireflyconfig')->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'); } @@ -154,7 +156,7 @@ class InstallController extends Controller */ public function runCommand(Request $request): JsonResponse { - $requestIndex = (int)$request->get('index'); + $requestIndex = (int) $request->get('index'); $response = [ 'hasNextCommand' => false, 'done' => true, diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 4567d48ba8..36a4f4f4a5 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -29,8 +29,10 @@ use FireflyIII\Http\Requests\TagFormRequest; use FireflyIII\Models\Tag; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\View\View; use Log; /** @@ -54,7 +56,7 @@ class TagController extends Controller $this->middleware( function ($request, $next) { $this->repository = app(TagRepositoryInterface::class); - app('view')->share('title', (string)trans('firefly.tags')); + app('view')->share('title', (string) trans('firefly.tags')); app('view')->share('mainTitleIcon', 'fa-tags'); return $next($request); @@ -62,39 +64,14 @@ class TagController extends Controller ); } - /** - * - */ - public function massDestroy(Request $request) - { - $tags = $request->get('tags'); - if (null === $tags || !is_array($tags)) { - session()->flash('info', (string)trans('firefly.select_tags_to_delete')); - - return redirect(route('tags.index')); - } - $count = 0; - foreach ($tags as $tagId) { - $tagId = (int)$tagId; - $tag = $this->repository->findNull($tagId); - if (null !== $tag) { - $this->repository->destroy($tag); - $count++; - } - } - session()->flash('success', (string)trans('firefly.deleted_x_tags', ['count' => $count])); - - return redirect(route('tags.index')); - } - /** * Create a new tag. * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function create(Request $request) { - $subTitle = (string)trans('firefly.new_tag'); + $subTitle = (string) trans('firefly.new_tag'); $subTitleIcon = 'fa-tag'; // location info: @@ -122,11 +99,11 @@ class TagController extends Controller * * @param Tag $tag * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function delete(Tag $tag) { - $subTitle = (string)trans('breadcrumbs.delete_tag', ['tag' => $tag->tag]); + $subTitle = (string) trans('breadcrumbs.delete_tag', ['tag' => $tag->tag]); // put previous url in session $this->rememberPreviousUri('tags.delete.uri'); @@ -146,7 +123,7 @@ class TagController extends Controller $tagName = $tag->tag; $this->repository->destroy($tag); - session()->flash('success', (string)trans('firefly.deleted_tag', ['tag' => $tagName])); + session()->flash('success', (string) trans('firefly.deleted_tag', ['tag' => $tagName])); app('preferences')->mark(); return redirect($this->getPreviousUri('tags.delete.uri')); @@ -157,19 +134,19 @@ class TagController extends Controller * * @param Tag $tag * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(Tag $tag) { - $subTitle = (string)trans('firefly.edit_tag', ['tag' => $tag->tag]); + $subTitle = (string) trans('firefly.edit_tag', ['tag' => $tag->tag]); $subTitleIcon = 'fa-tag'; - $location = $this->repository->getLocation($tag); - $latitude = $location ? $location->latitude : config('firefly.default_location.latitude'); - $longitude = $location ? $location->longitude : config('firefly.default_location.longitude'); - $zoomLevel = $location ? $location->zoom_level : config('firefly.default_location.zoom_level'); - $hasLocation = null !== $location; - $locations = [ + $location = $this->repository->getLocation($tag); + $latitude = $location ? $location->latitude : config('firefly.default_location.latitude'); + $longitude = $location ? $location->longitude : config('firefly.default_location.longitude'); + $zoomLevel = $location ? $location->zoom_level : config('firefly.default_location.zoom_level'); + $hasLocation = null !== $location; + $locations = [ 'location' => [ 'latitude' => old('location_latitude') ?? $latitude, 'longitude' => old('location_longitude') ?? $longitude, @@ -184,7 +161,7 @@ class TagController extends Controller } session()->forget('tags.edit.fromUpdate'); - return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon','locations')); + return view('tags.edit', compact('tag', 'subTitle', 'subTitleIcon', 'locations')); } /** @@ -192,7 +169,7 @@ class TagController extends Controller * * @param TagRepositoryInterface $repository * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function index(TagRepositoryInterface $repository) { @@ -205,7 +182,7 @@ class TagController extends Controller $tags['no-date'] = $repository->getTagsInYear(null); while ($newestTagDate > $oldestTagDate) { - $year = $newestTagDate->year; + $year = $newestTagDate->year; $tags[$year] = $repository->getTagsInYear($year); $newestTagDate->subYear(); } @@ -214,36 +191,62 @@ class TagController extends Controller return view('tags.index', compact('tags', 'count')); } + /** + * + */ + public function massDestroy(Request $request) + { + $tags = $request->get('tags'); + if (null === $tags || !is_array($tags)) { + session()->flash('info', (string) trans('firefly.select_tags_to_delete')); + + return redirect(route('tags.index')); + } + $count = 0; + foreach ($tags as $tagId) { + $tagId = (int) $tagId; + $tag = $this->repository->findNull($tagId); + if (null !== $tag) { + $this->repository->destroy($tag); + $count++; + } + } + session()->flash('success', (string) trans('firefly.deleted_x_tags', ['count' => $count])); + + return redirect(route('tags.index')); + } + /** * Show a single tag. * - * @param Request $request - * @param Tag $tag + * @param Request $request + * @param Tag $tag * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View * */ public function show(Request $request, Tag $tag, Carbon $start = null, Carbon $end = null) { // default values: $subTitleIcon = 'fa-tag'; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $start = $start ?? session('start'); $end = $end ?? session('end'); $location = $this->repository->getLocation($tag); $subTitle = trans( - 'firefly.journals_in_period_for_tag', ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), - 'end' => $end->formatLocalized($this->monthAndDayFormat),] + 'firefly.journals_in_period_for_tag', + ['tag' => $tag->tag, 'start' => $start->formatLocalized($this->monthAndDayFormat), + 'end' => $end->formatLocalized($this->monthAndDayFormat),] ); $startPeriod = $this->repository->firstUseDate($tag); - $startPeriod = $startPeriod ?? new Carbon; - $endPeriod = clone $end; - $periods = $this->getTagPeriodOverview($tag, $startPeriod, $endPeriod); - $path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); + $startPeriod = $startPeriod ?? new Carbon; + $endPeriod = clone $end; + $periods = $this->getTagPeriodOverview($tag, $startPeriod, $endPeriod); + $path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); @@ -261,19 +264,19 @@ class TagController extends Controller * Show a single tag over all time. * * @param Request $request - * @param Tag $tag + * @param Tag $tag * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View * */ public function showAll(Request $request, Tag $tag) { // default values: $subTitleIcon = 'fa-tag'; - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $periods = []; - $subTitle = (string)trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]); + $subTitle = (string) trans('firefly.all_journals_for_tag', ['tag' => $tag->tag]); $start = $this->repository->firstUseDate($tag) ?? new Carbon; $end = new Carbon; $path = route('tags.show', [$tag->id, 'all']); @@ -304,11 +307,11 @@ class TagController extends Controller $result = $this->repository->store($data); Log::debug('Data after storage', $result->toArray()); - session()->flash('success', (string)trans('firefly.created_tag', ['tag' => $data['tag']])); + session()->flash('success', (string) trans('firefly.created_tag', ['tag' => $data['tag']])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('tags.create.uri')); - if (1 === (int)$request->get('create_another')) { + if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart session()->put('tags.create.fromStore', true); @@ -317,14 +320,13 @@ class TagController extends Controller } return $redirect; - } /** * Update a tag. * * @param TagFormRequest $request - * @param Tag $tag + * @param Tag $tag * * @return RedirectResponse */ @@ -333,11 +335,11 @@ class TagController extends Controller $data = $request->collectTagData(); $this->repository->update($tag, $data); - session()->flash('success', (string)trans('firefly.updated_tag', ['tag' => $data['tag']])); + session()->flash('success', (string) trans('firefly.updated_tag', ['tag' => $data['tag']])); app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('tags.edit.uri')); - if (1 === (int)$request->get('return_to_edit')) { + if (1 === (int) $request->get('return_to_edit')) { // @codeCoverageIgnoreStart session()->put('tags.edit.fromUpdate', true); @@ -348,6 +350,4 @@ class TagController extends Controller // redirect to previous URL. return $redirect; } - - } diff --git a/app/Http/Controllers/Transaction/BulkController.php b/app/Http/Controllers/Transaction/BulkController.php index 822e124fac..9a526b44fa 100644 --- a/app/Http/Controllers/Transaction/BulkController.php +++ b/app/Http/Controllers/Transaction/BulkController.php @@ -29,7 +29,9 @@ use FireflyIII\Http\Requests\BulkEditJournalRequest; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; +use Illuminate\Contracts\View\Factory; use Illuminate\Support\Collection; +use Illuminate\View\View; use Log; /** @@ -43,6 +45,7 @@ class BulkController extends Controller /** * BulkController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -52,7 +55,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-repeat'); return $next($request); @@ -67,11 +70,11 @@ class BulkController extends Controller * * @param Collection $journals * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ public function edit(array $journals) { - $subTitle = (string)trans('firefly.mass_bulk_journals'); + $subTitle = (string) trans('firefly.mass_bulk_journals'); $this->rememberPreviousUri('transactions.bulk-edit.uri'); @@ -97,13 +100,13 @@ 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'); - $ignoreTags = 1 === (int)$request->get('ignore_tags'); + $ignoreCategory = 1 === (int) $request->get('ignore_category'); + $ignoreBudget = 1 === (int) $request->get('ignore_budget'); + $ignoreTags = 1 === (int) $request->get('ignore_tags'); $count = 0; foreach ($journalIds as $journalId) { - $journalId = (int)$journalId; + $journalId = (int) $journalId; $journal = $this->repository->findNull($journalId); if (null !== $journal) { $resultA = $this->updateJournalBudget($journal, $ignoreBudget, $request->integer('budget_id')); @@ -115,7 +118,7 @@ class BulkController extends Controller } } app('preferences')->mark(); - $request->session()->flash('success', (string)trans('firefly.mass_edited_transactions_success', ['amount' => $count])); + $request->session()->flash('success', (string) trans('firefly.mass_edited_transactions_success', ['amount' => $count])); // redirect to previous URL: return redirect($this->getPreviousUri('transactions.bulk-edit.uri')); @@ -123,26 +126,27 @@ class BulkController extends Controller /** * @param TransactionJournal $journal - * @param bool $ignoreUpdate - * @param array $tags + * @param bool $ignoreUpdate + * @param int $budgetId + * * @return bool */ - private function updateJournalTags(TransactionJournal $journal, bool $ignoreUpdate, array $tags): bool + private function updateJournalBudget(TransactionJournal $journal, bool $ignoreUpdate, int $budgetId): bool { - if (true === $ignoreUpdate) { return false; } - Log::debug(sprintf('Set tags to %s', implode(',', $tags))); - $this->repository->updateTags($journal, $tags); + Log::debug(sprintf('Set budget to %d', $budgetId)); + $this->repository->updateBudget($journal, $budgetId); return true; } /** * @param TransactionJournal $journal - * @param bool $ignoreUpdate - * @param string $category + * @param bool $ignoreUpdate + * @param string $category + * * @return bool */ private function updateJournalCategory(TransactionJournal $journal, bool $ignoreUpdate, string $category): bool @@ -158,17 +162,19 @@ class BulkController extends Controller /** * @param TransactionJournal $journal - * @param bool $ignoreUpdate - * @param int $budgetId + * @param bool $ignoreUpdate + * @param array $tags + * * @return bool */ - private function updateJournalBudget(TransactionJournal $journal, bool $ignoreUpdate, int $budgetId): bool + private function updateJournalTags(TransactionJournal $journal, bool $ignoreUpdate, array $tags): bool { + if (true === $ignoreUpdate) { return false; } - Log::debug(sprintf('Set budget to %d', $budgetId)); - $this->repository->updateBudget($journal, $budgetId); + Log::debug(sprintf('Set tags to %s', implode(',', $tags))); + $this->repository->updateTags($journal, $tags); return true; } diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php index 3598b1359b..ea21ca6376 100644 --- a/app/Http/Controllers/Transaction/ConvertController.php +++ b/app/Http/Controllers/Transaction/ConvertController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Transaction; use Carbon\Carbon; +use Exception; use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -38,11 +39,12 @@ use FireflyIII\Support\Http\Controllers\ModelInformation; use FireflyIII\Support\Http\Controllers\UserNavigation; use FireflyIII\Transformers\TransactionGroupTransformer; use FireflyIII\Validation\AccountValidator; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Routing\Redirector; use Log; use View; - /** * Class ConvertController. * @@ -57,6 +59,7 @@ class ConvertController extends Controller /** * ConvertController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -68,7 +71,7 @@ class ConvertController extends Controller 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); @@ -80,11 +83,11 @@ class ConvertController extends Controller /** * Show overview of a to be converted transaction. * - * @param TransactionType $destinationType + * @param TransactionType $destinationType * @param TransactionGroup $group * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View - * @throws \Exception + * @throws Exception + * @return RedirectResponse|Redirector|View */ public function index(TransactionType $destinationType, TransactionGroup $group) { @@ -101,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: @@ -117,31 +120,40 @@ 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])); } return view( - 'transactions.convert', compact( - 'sourceType', 'destinationType', - 'group', 'groupTitle', 'groupArray', 'assets', 'validDepositSources', 'liabilities', - 'validWithdrawalDests', 'preFilled', - 'subTitle', 'subTitleIcon' - ) + 'transactions.convert', + compact( + 'sourceType', + 'destinationType', + 'group', + 'groupTitle', + 'groupArray', + 'assets', + 'validDepositSources', + 'liabilities', + 'validWithdrawalDests', + 'preFilled', + 'subTitle', + 'subTitleIcon' + ) ); } /** * Do the conversion. * - * @param Request $request - * @param TransactionType $destinationType + * @param Request $request + * @param TransactionType $destinationType * @param TransactionGroup $group * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * * @throws FireflyException + * @return RedirectResponse|Redirector + * */ public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group) { @@ -165,156 +177,19 @@ class ConvertController extends Controller $group->refresh(); $this->correctTransfer($group); - session()->flash('success', (string)trans('firefly.converted_to_' . $destinationType->type)); + session()->flash('success', (string) trans('firefly.converted_to_' . $destinationType->type)); event(new UpdatedTransactionGroup($group)); return redirect(route('transactions.show', [$group->id])); } - /** - * @return array - * @throws \Exception - */ - private function getAssetAccounts(): array - { - // make repositories - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - $accountList = $repository->getActiveAccountsByType([AccountType::ASSET]); - $defaultCurrency = app('amount')->getDefaultCurrency(); - $grouped = []; - // group accounts: - /** @var Account $account */ - foreach ($accountList as $account) { - $balance = app('steam')->balance($account, new Carbon); - $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency; - $role = (string)$repository->getMetaValue($account, 'account_role'); - if ('' === $role) { - $role = 'no_account_type'; // @codeCoverageIgnore - } - - $key = (string)trans('firefly.opt_group_' . $role); - $grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')'; - } - - return $grouped; - } - - /** - * @return array - * @throws \Exception - */ - private function getLiabilities(): array - { - // make repositories - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - $accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); - $defaultCurrency = app('amount')->getDefaultCurrency(); - $grouped = []; - // group accounts: - /** @var Account $account */ - foreach ($accountList as $account) { - $balance = app('steam')->balance($account, new Carbon); - $currency = $repository->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) . ')'; - } - - return $grouped; - } - - /** - * @return array - */ - private function getValidDepositSources(): array - { - // make repositories - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; - $accountList = $repository - ->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); - $grouped = []; - // group accounts: - /** @var Account $account */ - foreach ($accountList as $account) { - $role = (string)$repository->getMetaValue($account, 'account_role'); - $name = $account->name; - if ('' === $role) { - $role = 'no_account_type'; // @codeCoverageIgnore - } - - // maybe it's a liability thing: - if (in_array($account->accountType->type, $liabilityTypes, true)) { - $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore - } - if (AccountType::CASH === $account->accountType->type) { - // @codeCoverageIgnoreStart - $role = 'cash_account'; - $name = sprintf('(%s)', trans('firefly.cash')); - // @codeCoverageIgnoreEnd - } - if (AccountType::REVENUE === $account->accountType->type) { - $role = 'revenue_account'; // @codeCoverageIgnore - } - - $key = (string)trans('firefly.opt_group_' . $role); - $grouped[$key][$account->id] = $name; - } - - return $grouped; - } - - /** - * @return array - */ - private function getValidWithdrawalDests(): array - { - // make repositories - /** @var AccountRepositoryInterface $repository */ - $repository = app(AccountRepositoryInterface::class); - $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; - $accountList = $repository - ->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); - $grouped = []; - // group accounts: - /** @var Account $account */ - foreach ($accountList as $account) { - $role = (string)$repository->getMetaValue($account, 'account_role'); - $name = $account->name; - if ('' === $role) { - $role = 'no_account_type'; // @codeCoverageIgnore - } - - // maybe it's a liability thing: - if (in_array($account->accountType->type, $liabilityTypes, true)) { - $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore - } - if (AccountType::CASH === $account->accountType->type) { - // @codeCoverageIgnoreStart - $role = 'cash_account'; - $name = sprintf('(%s)', trans('firefly.cash')); - // @codeCoverageIgnoreEnd - } - if (AccountType::EXPENSE === $account->accountType->type) { - $role = 'expense_account'; // @codeCoverageIgnore - } - - $key = (string)trans('firefly.opt_group_' . $role); - $grouped[$key][$account->id] = $name; - } - - return $grouped; - } - /** * @param TransactionJournal $journal - * @param TransactionType $transactionType - * @param array $data - * @return TransactionJournal + * @param TransactionType $transactionType + * @param array $data + * * @throws FireflyException + * @return TransactionJournal */ private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal { @@ -329,9 +204,9 @@ 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; + $sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId; $sourceName = '' === $sourceName ? null : $sourceName; - $destinationId = '' === $destinationId || null === $destinationId ? null : (int)$destinationId; + $destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId; $destinationName = '' === $destinationName ? null : $destinationName; $validSource = $validator->validateSource($sourceId, $sourceName); $validDestination = $validator->validateDestination($destinationId, $destinationName); @@ -366,4 +241,142 @@ class ConvertController extends Controller private function correctTransfer(TransactionGroup $group): void { } + + /** + * @throws Exception + * @return array + */ + private function getAssetAccounts(): array + { + // make repositories + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $accountList = $repository->getActiveAccountsByType([AccountType::ASSET]); + $defaultCurrency = app('amount')->getDefaultCurrency(); + $grouped = []; + // group accounts: + /** @var Account $account */ + foreach ($accountList as $account) { + $balance = app('steam')->balance($account, new Carbon); + $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency; + $role = (string) $repository->getMetaValue($account, 'account_role'); + if ('' === $role) { + $role = 'no_account_type'; // @codeCoverageIgnore + } + + $key = (string) trans('firefly.opt_group_' . $role); + $grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')'; + } + + return $grouped; + } + + /** + * @throws Exception + * @return array + */ + private function getLiabilities(): array + { + // make repositories + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); + $defaultCurrency = app('amount')->getDefaultCurrency(); + $grouped = []; + // group accounts: + /** @var Account $account */ + foreach ($accountList as $account) { + $balance = app('steam')->balance($account, new Carbon); + $currency = $repository->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) . ')'; + } + + return $grouped; + } + + /** + * @return array + */ + private function getValidDepositSources(): array + { + // make repositories + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; + $accountList = $repository + ->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); + $grouped = []; + // group accounts: + /** @var Account $account */ + foreach ($accountList as $account) { + $role = (string) $repository->getMetaValue($account, 'account_role'); + $name = $account->name; + if ('' === $role) { + $role = 'no_account_type'; // @codeCoverageIgnore + } + + // maybe it's a liability thing: + if (in_array($account->accountType->type, $liabilityTypes, true)) { + $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore + } + if (AccountType::CASH === $account->accountType->type) { + // @codeCoverageIgnoreStart + $role = 'cash_account'; + $name = sprintf('(%s)', trans('firefly.cash')); + // @codeCoverageIgnoreEnd + } + if (AccountType::REVENUE === $account->accountType->type) { + $role = 'revenue_account'; // @codeCoverageIgnore + } + + $key = (string) trans('firefly.opt_group_' . $role); + $grouped[$key][$account->id] = $name; + } + + return $grouped; + } + + /** + * @return array + */ + private function getValidWithdrawalDests(): array + { + // make repositories + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class); + $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; + $accountList = $repository + ->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); + $grouped = []; + // group accounts: + /** @var Account $account */ + foreach ($accountList as $account) { + $role = (string) $repository->getMetaValue($account, 'account_role'); + $name = $account->name; + if ('' === $role) { + $role = 'no_account_type'; // @codeCoverageIgnore + } + + // maybe it's a liability thing: + if (in_array($account->accountType->type, $liabilityTypes, true)) { + $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore + } + if (AccountType::CASH === $account->accountType->type) { + // @codeCoverageIgnoreStart + $role = 'cash_account'; + $name = sprintf('(%s)', trans('firefly.cash')); + // @codeCoverageIgnoreEnd + } + if (AccountType::EXPENSE === $account->accountType->type) { + $role = 'expense_account'; // @codeCoverageIgnore + } + + $key = (string) trans('firefly.opt_group_' . $role); + $grouped[$key][$account->id] = $name; + } + + return $grouped; + } } diff --git a/app/Http/Controllers/Transaction/CreateController.php b/app/Http/Controllers/Transaction/CreateController.php index 6fa54509d9..5617a4a6ae 100644 --- a/app/Http/Controllers/Transaction/CreateController.php +++ b/app/Http/Controllers/Transaction/CreateController.php @@ -23,11 +23,14 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Transaction; - use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionGroup; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Services\Internal\Update\GroupCloneService; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; +use Illuminate\View\View; /** * Class CreateController @@ -49,8 +52,7 @@ class CreateController extends Controller app('view')->share('uploadSize', $uploadSize); $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-repeat'); return $next($request); @@ -61,7 +63,7 @@ class CreateController extends Controller /** * @param TransactionGroup $group * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function cloneGroup(TransactionGroup $group) { @@ -84,20 +86,20 @@ class CreateController extends Controller * * @param string|null objectType * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @return Factory|View */ 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 $repository */ $repository = app(AccountRepositoryInterface::class); $cash = $repository->getCashAccount(); $preFilled = session()->has('preFilled') ? session('preFilled') : []; - $subTitle = (string)trans('breadcrumbs.create_new_transaction'); + $subTitle = (string) trans('breadcrumbs.create_new_transaction'); $subTitleIcon = 'fa-plus'; $optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data; $allowedOpposingTypes = config('firefly.allowed_opposing_types'); @@ -112,11 +114,21 @@ class CreateController extends Controller return view( - 'transactions.create', compact( - 'subTitleIcon', 'cash', 'objectType', 'subTitle', 'defaultCurrency', 'previousUri', 'optionalFields', 'preFilled', - 'allowedOpposingTypes', - 'accountToTypes','sourceId','destinationId' - ) + 'transactions.create', + compact( + 'subTitleIcon', + 'cash', + 'objectType', + 'subTitle', + 'defaultCurrency', + 'previousUri', + 'optionalFields', + 'preFilled', + 'allowedOpposingTypes', + 'accountToTypes', + 'sourceId', + 'destinationId' + ) ); } } diff --git a/app/Http/Controllers/Transaction/DeleteController.php b/app/Http/Controllers/Transaction/DeleteController.php index 163431dc1b..585bc0a198 100644 --- a/app/Http/Controllers/Transaction/DeleteController.php +++ b/app/Http/Controllers/Transaction/DeleteController.php @@ -26,10 +26,10 @@ namespace FireflyIII\Http\Controllers\Transaction; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionGroup; -use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface; use FireflyIII\Support\Http\Controllers\UserNavigation; use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use URL; @@ -45,6 +45,7 @@ class DeleteController extends Controller /** * IndexController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -54,7 +55,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-repeat'); $this->repository = app(TransactionGroupRepositoryInterface::class); @@ -69,7 +70,7 @@ class DeleteController extends Controller * * @param TransactionGroup $group * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View + * @return RedirectResponse|Redirector|View */ public function delete(TransactionGroup $group) { @@ -84,7 +85,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 = URL::previous(route('index')); // put previous url in session Log::debug('Will try to remember previous URI'); @@ -111,7 +112,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])); $this->repository->destroy($group); diff --git a/app/Http/Controllers/Transaction/EditController.php b/app/Http/Controllers/Transaction/EditController.php index 1e99818055..eb749b8cd3 100644 --- a/app/Http/Controllers/Transaction/EditController.php +++ b/app/Http/Controllers/Transaction/EditController.php @@ -28,6 +28,8 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionGroup; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Support\Http\Controllers\UserNavigation; +use Illuminate\Contracts\View\Factory; +use Illuminate\View\View; /** * Class EditController @@ -35,8 +37,10 @@ use FireflyIII\Support\Http\Controllers\UserNavigation; class EditController extends Controller { use UserNavigation; + /** * EditController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -54,7 +58,7 @@ class EditController extends Controller $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-repeat'); return $next($request); @@ -65,7 +69,8 @@ class EditController extends Controller /** * @param TransactionGroup $transactionGroup - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * + * @return Factory|View */ public function edit(TransactionGroup $transactionGroup) { diff --git a/app/Http/Controllers/Transaction/IndexController.php b/app/Http/Controllers/Transaction/IndexController.php index 3f2ffa3704..46b42ad72d 100644 --- a/app/Http/Controllers/Transaction/IndexController.php +++ b/app/Http/Controllers/Transaction/IndexController.php @@ -25,11 +25,14 @@ namespace FireflyIII\Http\Controllers\Transaction; use Carbon\Carbon; +use Exception; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use Illuminate\Contracts\View\Factory; use Illuminate\Http\Request; +use Illuminate\View\View; /** * Class IndexController @@ -43,6 +46,7 @@ class IndexController extends Controller /** * IndexController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -53,7 +57,7 @@ class IndexController extends Controller $this->middleware( function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-credit-card'); - app('view')->share('title', (string)trans('firefly.accounts')); + app('view')->share('title', (string) trans('firefly.accounts')); $this->repository = app(JournalRepositoryInterface::class); @@ -65,20 +69,20 @@ class IndexController extends Controller /** * Index for a range of transactions. * - * @param Request $request - * @param string $objectType + * @param Request $request + * @param string $objectType * @param Carbon|null $start * @param Carbon|null $end * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \Exception + * @throws Exception + * @return Factory|View */ public function index(Request $request, string $objectType, Carbon $start = null, Carbon $end = null) { $subTitleIcon = config('firefly.transactionIconsByType.' . $objectType); $types = config('firefly.transactionTypesByType.' . $objectType); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; if (null === $start) { $start = session('start'); $end = session('end'); @@ -91,7 +95,7 @@ class IndexController extends Controller $path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]); $startStr = $start->formatLocalized($this->monthAndDayFormat); $endStr = $end->formatLocalized($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; @@ -119,9 +123,10 @@ class IndexController extends Controller * Index for ALL transactions. * * @param Request $request - * @param string $objectType - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \Exception + * @param string $objectType + * + * @throws Exception + * @return Factory|View */ public function indexAll(Request $request, string $objectType) { @@ -131,13 +136,13 @@ class IndexController extends Controller $subTitleIcon = config('firefly.transactionIconsByWhat.' . $objectType); $types = config('firefly.transactionTypesByWhat.' . $objectType); - $page = (int)$request->get('page'); - $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; + $page = (int) $request->get('page'); + $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $path = route('transactions.index.all', [$objectType]); $first = $repository->firstNull(); $start = null === $first ? new Carbon : $first->date; $end = new Carbon; - $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 f1ff8362a2..c9df232c4b 100644 --- a/app/Http/Controllers/Transaction/LinkController.php +++ b/app/Http/Controllers/Transaction/LinkController.php @@ -29,6 +29,8 @@ use FireflyIII\Models\TransactionJournalLink; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use Illuminate\Contracts\View\Factory; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use Illuminate\View\View; use Log; use URL; @@ -45,6 +47,7 @@ class LinkController extends Controller /** * LinkController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -53,7 +56,7 @@ class LinkController extends Controller // some useful repositories: $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-repeat'); $this->journalRepository = app(JournalRepositoryInterface::class); @@ -64,17 +67,6 @@ class LinkController extends Controller ); } - /** - * @param TransactionJournal $journal - * @return Factory|View - */ - public function modal(TransactionJournal $journal) - { - $linkTypes = $this->repository->get(); - - return view('transactions.links.modal', compact('journal', 'linkTypes')); - } - /** * Delete a link. * @@ -85,7 +77,7 @@ class LinkController extends Controller public function delete(TransactionJournalLink $link) { $subTitleIcon = 'fa-link'; - $subTitle = (string)trans('breadcrumbs.delete_journal_link'); + $subTitle = (string) trans('breadcrumbs.delete_journal_link'); $this->rememberPreviousUri('journal_links.delete.uri'); return view('transactions.links.delete', compact('link', 'subTitle', 'subTitleIcon')); @@ -96,16 +88,28 @@ class LinkController extends Controller * * @param TransactionJournalLink $link * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function destroy(TransactionJournalLink $link) { $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.uri')); + return redirect((string) session('journal_links.delete.uri')); + } + + /** + * @param TransactionJournal $journal + * + * @return Factory|View + */ + public function modal(TransactionJournal $journal) + { + $linkTypes = $this->repository->get(); + + return view('transactions.links.modal', compact('journal', 'linkTypes')); } /** @@ -114,16 +118,16 @@ class LinkController extends Controller * @param JournalLinkRequest $request * @param TransactionJournal $journal * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function store(JournalLinkRequest $request, TransactionJournal $journal) { $linkInfo = $request->getLinkInfo(); Log::debug('We are here (store)'); - $other = $this->journalRepository->findNull($linkInfo['transaction_journal_id']); + $other = $this->journalRepository->findNull($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])); } @@ -131,19 +135,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,7 +157,7 @@ class LinkController extends Controller * * @param TransactionJournalLink $link * - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @return RedirectResponse|Redirector */ public function switchLink(TransactionJournalLink $link) { diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index bfa0f2194e..977028bdb3 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -35,6 +35,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Services\Internal\Update\JournalUpdateService; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; use Illuminate\View\View as IlluminateView; use InvalidArgumentException; use Log; @@ -50,6 +52,7 @@ class MassController extends Controller /** * MassController constructor. + * * @codeCoverageIgnore */ public function __construct() @@ -58,9 +61,10 @@ class MassController 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-repeat'); $this->repository = app(JournalRepositoryInterface::class); + return $next($request); } ); @@ -75,7 +79,7 @@ class MassController extends Controller */ 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->rememberPreviousUri('transactions.mass-delete.uri'); @@ -100,8 +104,8 @@ class MassController extends Controller foreach ($ids as $journalId) { /** @var TransactionJournal $journal */ - $journal = $this->repository->findNull((int)$journalId); - if (null !== $journal && (int)$journalId === $journal->id) { + $journal = $this->repository->findNull((int) $journalId); + if (null !== $journal && (int) $journalId === $journal->id) { $this->repository->destroyJournal($journal); ++$count; } @@ -110,7 +114,7 @@ class MassController extends Controller app('preferences')->mark(); - session()->flash('success', (string)trans('firefly.mass_deleted_transactions_success', ['amount' => $count])); + session()->flash('success', (string) trans('firefly.mass_deleted_transactions_success', ['amount' => $count])); // redirect to previous URL: return redirect($this->getPreviousUri('transactions.mass-delete.uri')); @@ -125,7 +129,7 @@ class MassController extends Controller */ public function edit(array $journals): IlluminateView { - $subTitle = (string)trans('firefly.mass_edit_journals'); + $subTitle = (string) trans('firefly.mass_edit_journals'); /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); @@ -158,8 +162,9 @@ class MassController extends Controller * Mass update of journals. * * @param MassEditJournalRequest $request - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * * @throws FireflyException + * @return RedirectResponse|Redirector */ public function update(MassEditJournalRequest $request) { @@ -171,7 +176,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 +188,86 @@ class MassController extends Controller } app('preferences')->mark(); - session()->flash('success', (string)trans('firefly.mass_edited_transactions_success', ['amount' => $count])); + session()->flash('success', (string) trans('firefly.mass_edited_transactions_success', ['amount' => $count])); // redirect to previous URL: return redirect($this->getPreviousUri('transactions.mass-edit.uri')); } /** - * @param int $journalId * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $string + * + * @return Carbon|null + * @codeCoverageIgnore + */ + private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon + { + $value = $request->get($string); + if (!is_array($value)) { + return null; + } + if (!isset($value[$journalId])) { + return null; + } + try { + $carbon = Carbon::parse($value[$journalId]); + } catch (InvalidArgumentException $e) { + $e->getMessage(); + + return null; + } + + return $carbon; + } + + /** + * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $string + * + * @return int|null + * @codeCoverageIgnore + */ + private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int + { + $value = $request->get($string); + if (!is_array($value)) { + return null; + } + if (!isset($value[$journalId])) { + return null; + } + + return (int) $value[$journalId]; + } + + /** + * @param MassEditJournalRequest $request + * @param int $journalId + * @param string $string + * + * @return string|null + * @codeCoverageIgnore + */ + private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string + { + $value = $request->get($string); + if (!is_array($value)) { + return null; + } + if (!isset($value[$journalId])) { + return null; + } + + return (string) $value[$journalId]; + } + + /** + * @param int $journalId + * @param MassEditJournalRequest $request + * * @throws FireflyException */ private function updateJournal(int $journalId, MassEditJournalRequest $request): void @@ -224,71 +300,4 @@ class MassController extends Controller // trigger rules event(new UpdatedTransactionGroup($journal->transactionGroup)); } - - /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $string - * @return int|null - * @codeCoverageIgnore - */ - private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int - { - $value = $request->get($string); - if (!is_array($value)) { - return null; - } - if (!isset($value[$journalId])) { - return null; - } - - return (int)$value[$journalId]; - } - - /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $string - * @return string|null - * @codeCoverageIgnore - */ - private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string - { - $value = $request->get($string); - if (!is_array($value)) { - return null; - } - if (!isset($value[$journalId])) { - return null; - } - - return (string)$value[$journalId]; - } - - /** - * @param MassEditJournalRequest $request - * @param int $journalId - * @param string $string - * @return Carbon|null - * @codeCoverageIgnore - */ - private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon - { - $value = $request->get($string); - if (!is_array($value)) { - return null; - } - if (!isset($value[$journalId])) { - return null; - } - try { - $carbon = Carbon::parse($value[$journalId]); - } catch (InvalidArgumentException $e) { - $e->getMessage(); - - return null; - } - - return $carbon; - } } diff --git a/app/Http/Controllers/Transaction/ShowController.php b/app/Http/Controllers/Transaction/ShowController.php index e2aa0acc25..82d5710481 100644 --- a/app/Http/Controllers/Transaction/ShowController.php +++ b/app/Http/Controllers/Transaction/ShowController.php @@ -29,8 +29,11 @@ use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface; use FireflyIII\Transformers\TransactionGroupTransformer; +use Illuminate\Contracts\View\Factory; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Str; +use Illuminate\View\View; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -53,7 +56,7 @@ class ShowController extends Controller function ($request, $next) { $this->repository = app(TransactionGroupRepositoryInterface::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); @@ -64,7 +67,7 @@ class ShowController extends Controller /** * @param TransactionGroup $transactionGroup * - * @return \Illuminate\Http\JsonResponse + * @return JsonResponse */ public function debugShow(TransactionGroup $transactionGroup) { @@ -74,14 +77,14 @@ class ShowController extends Controller /** * @param TransactionGroup $transactionGroup * - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws FireflyException + * @return Factory|View */ public function show(Request $request, TransactionGroup $transactionGroup) { /** @var TransactionJournal $first */ - $first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']); - $splits = $transactionGroup->transactionJournals()->count(); + $first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']); + $splits = $transactionGroup->transactionJournals()->count(); if (null === $first) { throw new FireflyException('This transaction is broken :(.'); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index f56b7ec0f2..2c538f94d0 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -71,7 +71,7 @@ class Kernel extends HttpKernel TrimStrings::class, ConvertEmptyStringsToNull::class, TrustProxies::class, - InstallationId::class + InstallationId::class, ]; /**