From d25d0454fc41e8efee9e6e71b037af8387eefef4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 16 Sep 2016 12:15:58 +0200 Subject: [PATCH] Code clean up --- app/Exceptions/Handler.php | 5 +- app/Export/Collector/UploadCollector.php | 7 +-- .../Events/ConnectJournalToPiggyBank.php | 3 +- app/Handlers/Events/FireRulesForStore.php | 3 +- app/Handlers/Events/FireRulesForUpdate.php | 3 +- app/Helpers/Attachments/AttachmentHelper.php | 5 +- app/Helpers/Report/BalanceReportHelper.php | 57 +++++++++---------- app/Http/Controllers/AccountController.php | 5 +- .../Auth/ConfirmationController.php | 9 ++- .../Controllers/Auth/TwoFactorController.php | 5 +- app/Http/Controllers/BudgetController.php | 3 +- app/Http/Controllers/CategoryController.php | 3 +- app/Http/Controllers/CurrencyController.php | 11 ++-- app/Http/Controllers/NewUserController.php | 7 +-- .../Controllers/PreferencesController.php | 3 +- app/Http/Controllers/ProfileController.php | 21 ++++--- app/Http/Controllers/RuleController.php | 9 ++- app/Http/Controllers/RuleGroupController.php | 7 +-- app/Http/Controllers/TagController.php | 3 +- .../Transaction/MassController.php | 3 +- app/Http/Middleware/Authenticate.php | 2 +- app/Http/Middleware/AuthenticateTwoFactor.php | 2 +- app/Http/Middleware/IsAdmin.php | 2 +- app/Http/Requests/BillFormRequest.php | 3 +- app/Http/Requests/ConfigurationRequest.php | 4 +- app/Http/Requests/JournalFormRequest.php | 3 +- app/Models/Account.php | 3 +- app/Models/Attachment.php | 3 +- app/Models/Bill.php | 3 +- app/Models/Budget.php | 3 +- app/Models/Category.php | 3 +- app/Models/ExportJob.php | 3 +- app/Models/ImportJob.php | 3 +- app/Models/LimitRepetition.php | 3 +- app/Models/PiggyBank.php | 3 +- app/Models/Rule.php | 3 +- app/Models/RuleGroup.php | 3 +- app/Models/Tag.php | 3 +- app/Models/TransactionJournal.php | 3 +- app/Support/Binder/AccountList.php | 3 +- app/Support/Binder/BudgetList.php | 3 +- app/Support/Binder/CategoryList.php | 3 +- app/Support/Binder/Date.php | 3 +- app/Support/Binder/JournalList.php | 3 +- app/Support/Binder/UnfinishedJournal.php | 3 +- app/Support/CacheProperties.php | 3 +- app/Support/FireflyConfig.php | 5 +- app/Support/Preferences.php | 13 ++--- app/Support/Search/Search.php | 11 ++-- app/Support/Steam.php | 9 ++- app/Support/Twig/Budget.php | 17 +++--- app/Validation/FireflyValidator.php | 17 +++--- 52 files changed, 135 insertions(+), 185 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 84662c20ba..4812dbaceb 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -10,7 +10,6 @@ declare(strict_types = 1); namespace FireflyIII\Exceptions; -use Auth; use ErrorException; use Exception; use FireflyIII\Jobs\MailError; @@ -82,8 +81,8 @@ class Handler extends ExceptionHandler 'email' => 'unknown@example.com', ]; if (auth()->check()) { - $userData['id'] = Auth::user()->id; - $userData['email'] = Auth::user()->email; + $userData['id'] = auth()->user()->id; + $userData['email'] = auth()->user()->email; } $data = [ 'class' => get_class($exception), diff --git a/app/Export/Collector/UploadCollector.php b/app/Export/Collector/UploadCollector.php index b5e4e29098..d2900e51ff 100644 --- a/app/Export/Collector/UploadCollector.php +++ b/app/Export/Collector/UploadCollector.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Export\Collector; -use Auth; use Crypt; use FireflyIII\Models\ExportJob; use Illuminate\Contracts\Encryption\DecryptException; @@ -50,7 +49,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface $this->exportDisk = Storage::disk('export'); // file names associated with the old import routine. - $this->expected = 'csv-upload-' . Auth::user()->id . '-'; + $this->expected = 'csv-upload-' . auth()->user()->id . '-'; // for the new import routine: $this->getImportKeys(); @@ -76,7 +75,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface */ private function getImportKeys() { - $set = Auth::user()->importJobs()->where('status', 'import_complete')->get(['import_jobs.*']); + $set = auth()->user()->importJobs()->where('status', 'import_complete')->get(['import_jobs.*']); if ($set->count() > 0) { $keys = $set->pluck('key')->toArray(); $this->importKeys = $keys; @@ -158,7 +157,7 @@ class UploadCollector extends BasicCollector implements CollectorInterface { // find job associated with import file: $name = str_replace('.upload', '', $entry); - $job = Auth::user()->importJobs()->where('key', $name)->first(); + $job = auth()->user()->importJobs()->where('key', $name)->first(); $content = ''; try { $content = Crypt::decrypt($this->uploadDisk->get($entry)); diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index b0c9daa9a2..ae1b0c6188 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Handlers\Events; -use Auth; use FireflyIII\Events\TransactionJournalStored; use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBankEvent; @@ -39,7 +38,7 @@ class ConnectJournalToPiggyBank $piggyBankId = $event->piggyBankId; /** @var PiggyBank $piggyBank */ - $piggyBank = Auth::user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); + $piggyBank = auth()->user()->piggyBanks()->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']); if (is_null($piggyBank)) { return true; diff --git a/app/Handlers/Events/FireRulesForStore.php b/app/Handlers/Events/FireRulesForStore.php index 7019b1b660..a789585bcd 100644 --- a/app/Handlers/Events/FireRulesForStore.php +++ b/app/Handlers/Events/FireRulesForStore.php @@ -17,7 +17,6 @@ use FireflyIII\Models\Rule; use FireflyIII\Models\RuleGroup; use FireflyIII\Rules\Processor; use FireflyIII\User; -use Illuminate\Support\Facades\Auth; /** * Class FireRulesForStore @@ -38,7 +37,7 @@ class FireRulesForStore { // get all the user's rule groups, with the rules, order by 'order'. /** @var User $user */ - $user = Auth::user(); + $user = auth()->user(); $groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); // /** @var RuleGroup $group */ diff --git a/app/Handlers/Events/FireRulesForUpdate.php b/app/Handlers/Events/FireRulesForUpdate.php index bbc6d2ce0d..e3c76bf9d0 100644 --- a/app/Handlers/Events/FireRulesForUpdate.php +++ b/app/Handlers/Events/FireRulesForUpdate.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Handlers\Events; -use Auth; use FireflyIII\Events\TransactionJournalUpdated; use FireflyIII\Models\Rule; use FireflyIII\Models\RuleGroup; @@ -36,7 +35,7 @@ class FireRulesForUpdate { // get all the user's rule groups, with the rules, order by 'order'. /** @var User $user */ - $user = Auth::user(); + $user = auth()->user(); $groups = $user->ruleGroups()->where('rule_groups.active', 1)->orderBy('order', 'ASC')->get(); // /** @var RuleGroup $group */ diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index b1045e4d78..25305f4dd5 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -10,7 +10,6 @@ declare(strict_types = 1); namespace FireflyIII\Helpers\Attachments; -use Auth; use Crypt; use FireflyIII\Models\Attachment; use Illuminate\Database\Eloquent\Model; @@ -112,7 +111,7 @@ class AttachmentHelper implements AttachmentHelperInterface $md5 = md5_file($file->getRealPath()); $name = $file->getClientOriginalName(); $class = get_class($model); - $count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); + $count = auth()->user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count(); if ($count > 0) { $msg = (string)trans('validation.file_already_attached', ['name' => $name]); @@ -139,7 +138,7 @@ class AttachmentHelper implements AttachmentHelperInterface } $attachment = new Attachment; // create Attachment object. - $attachment->user()->associate(Auth::user()); + $attachment->user()->associate(auth()->user()); $attachment->attachable()->associate($model); $attachment->md5 = md5_file($file->getRealPath()); $attachment->filename = $file->getClientOriginalName(); diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.php index 40cd5d9f0c..f8c26ce902 100644 --- a/app/Helpers/Report/BalanceReportHelper.php +++ b/app/Helpers/Report/BalanceReportHelper.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Helpers\Report; -use Auth; use Carbon\Carbon; use DB; use FireflyIII\Helpers\Collection\Balance; @@ -102,34 +101,34 @@ class BalanceReportHelper implements BalanceReportHelperInterface private function allCoveredByBalancingActs(Collection $accounts, Carbon $start, Carbon $end): Collection { $ids = $accounts->pluck('id')->toArray(); - $set = Auth::user()->tags() - ->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id') - ->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') - ->leftJoin( - 'transactions AS t_source', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 't_source.transaction_journal_id')->where('t_source.amount', '<', 0); - } - ) - ->leftJoin( - 'transactions AS t_destination', function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 't_destination.transaction_journal_id')->where('t_destination.amount', '>', 0); - } - ) - ->where('tags.tagMode', 'balancingAct') - ->where('transaction_types.type', TransactionType::TRANSFER) - ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) - ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) - ->whereNull('transaction_journals.deleted_at') - ->whereIn('t_source.account_id', $ids) - ->whereIn('t_destination.account_id', $ids) - ->groupBy('t_destination.account_id') - ->get( - [ - 't_destination.account_id', - DB::raw('SUM(`t_destination`.`amount`) as `sum`'), - ] - ); + $set = auth()->user()->tags() + ->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id') + ->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('transaction_types', 'transaction_journals.transaction_type_id', '=', 'transaction_types.id') + ->leftJoin( + 'transactions AS t_source', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 't_source.transaction_journal_id')->where('t_source.amount', '<', 0); + } + ) + ->leftJoin( + 'transactions AS t_destination', function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 't_destination.transaction_journal_id')->where('t_destination.amount', '>', 0); + } + ) + ->where('tags.tagMode', 'balancingAct') + ->where('transaction_types.type', TransactionType::TRANSFER) + ->where('transaction_journals.date', '>=', $start->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $end->format('Y-m-d')) + ->whereNull('transaction_journals.deleted_at') + ->whereIn('t_source.account_id', $ids) + ->whereIn('t_destination.account_id', $ids) + ->groupBy('t_destination.account_id') + ->get( + [ + 't_destination.account_id', + DB::raw('SUM(`t_destination`.`amount`) as `sum`'), + ] + ); return $set; } diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index ff47ecc5ec..f418fce394 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use Carbon\Carbon; use ExpandedForm; use FireflyIII\Crud\Account\AccountCrudInterface; @@ -301,7 +300,7 @@ class AccountController extends Controller 'virtualBalance' => round($request->input('virtualBalance'), 2), 'virtualBalanceCurrency' => intval($request->input('amount_currency_id_virtualBalance')), 'active' => true, - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'iban' => $request->input('iban'), 'accountNumber' => $request->input('accountNumber'), 'accountRole' => $request->input('accountRole'), @@ -347,7 +346,7 @@ class AccountController extends Controller $accountData = [ 'name' => $request->input('name'), 'active' => $request->input('active'), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'iban' => $request->input('iban'), 'accountNumber' => $request->input('accountNumber'), 'accountRole' => $request->input('accountRole'), diff --git a/app/Http/Controllers/Auth/ConfirmationController.php b/app/Http/Controllers/Auth/ConfirmationController.php index 2a07f9563b..9acdb32d43 100644 --- a/app/Http/Controllers/Auth/ConfirmationController.php +++ b/app/Http/Controllers/Auth/ConfirmationController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers\Auth; -use Auth; use FireflyIII\Events\ResendConfirmation; use FireflyIII\Events\UserIsConfirmed; use FireflyIII\Exceptions\FireflyException; @@ -55,10 +54,10 @@ class ConfirmationController extends Controller if ($database === $code && ($now - $time <= $maxDiff)) { // trigger user registration event: - event(new UserIsConfirmed(Auth::user(), $request->ip())); + event(new UserIsConfirmed(auth()->user(), $request->ip())); - Preferences::setForUser(Auth::user(), 'user_confirmed', true); - Preferences::setForUser(Auth::user(), 'user_confirmed_confirmed', time()); + Preferences::setForUser(auth()->user(), 'user_confirmed', true); + Preferences::setForUser(auth()->user(), 'user_confirmed_confirmed', time()); Session::flash('success', strval(trans('firefly.account_is_confirmed'))); return redirect(route('home')); @@ -79,7 +78,7 @@ class ConfirmationController extends Controller $owner = env('SITE_OWNER', 'mail@example.com'); $view = 'auth.confirmation.no-resent'; if ($now - $time > $maxDiff) { - event(new ResendConfirmation(Auth::user(), $request->ip())); + event(new ResendConfirmation(auth()->user(), $request->ip())); $view = 'auth.confirmation.resent'; } diff --git a/app/Http/Controllers/Auth/TwoFactorController.php b/app/Http/Controllers/Auth/TwoFactorController.php index 70f5a3e5ae..45b599b785 100644 --- a/app/Http/Controllers/Auth/TwoFactorController.php +++ b/app/Http/Controllers/Auth/TwoFactorController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers\Auth; -use Auth; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; @@ -34,7 +33,7 @@ class TwoFactorController extends Controller */ public function index() { - $user = Auth::user(); + $user = auth()->user(); // to make sure the validator in the next step gets the secret, we push it in session $secret = Preferences::get('twoFactorAuthSecret', '')->data; @@ -54,7 +53,7 @@ class TwoFactorController extends Controller */ public function lostTwoFactor() { - $user = Auth::user(); + $user = auth()->user(); $siteOwner = env('SITE_OWNER', ''); $title = strval(trans('firefly.two_factor_forgot_title')); diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index e99ba0530e..46b1082a2f 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; use Amount; -use Auth; use Carbon\Carbon; use Config; use FireflyIII\Crud\Account\AccountCrudInterface; @@ -359,7 +358,7 @@ class BudgetController extends Controller { $budgetData = [ 'name' => $request->input('name'), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, ]; $budget = $repository->store($budgetData); diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index c84cdd4e65..29e927f6e8 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use Carbon\Carbon; use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\CategoryFormRequest; @@ -265,7 +264,7 @@ class CategoryController extends Controller { $categoryData = [ 'name' => $request->input('name'), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, ]; $category = $repository->store($categoryData); diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 952ea79190..3d23396de4 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use Cache; use FireflyIII\Http\Requests\CurrencyFormRequest; use FireflyIII\Models\TransactionCurrency; @@ -119,7 +118,7 @@ class CurrencyController extends Controller } Session::flash('success', trans('firefly.deleted_currency', ['name' => $currency->name])); - if (Auth::user()->hasRole('owner')) { + if (auth()->user()->hasRole('owner')) { $currency->delete(); } @@ -160,7 +159,7 @@ class CurrencyController extends Controller $defaultCurrency = $repository->getCurrencyByPreference(Preferences::get('currencyPreference', env('DEFAULT_CURRENCY', 'EUR'))); - if (!Auth::user()->hasRole('owner')) { + if (!auth()->user()->hasRole('owner')) { Session::flash('warning', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); } @@ -177,8 +176,8 @@ class CurrencyController extends Controller */ public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository) { - if (!Auth::user()->hasRole('owner')) { - Log::error('User ' . Auth::user()->id . ' is not admin, but tried to store a currency.'); + if (!auth()->user()->hasRole('owner')) { + Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.'); return redirect(session('currency.create.url')); } @@ -209,7 +208,7 @@ class CurrencyController extends Controller public function update(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository, TransactionCurrency $currency) { $data = $request->getCurrencyData(); - if (Auth::user()->hasRole('owner')) { + if (auth()->user()->hasRole('owner')) { $currency = $repository->update($currency, $data); } Session::flash('success', trans('firefly.updated_currency', ['name' => $currency->name])); diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 0300d19207..adc053e65b 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -10,7 +10,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use Carbon\Carbon; use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\NewUserFormRequest; @@ -107,7 +106,7 @@ class NewUserController extends Controller 'accountType' => 'asset', 'virtualBalance' => 0, 'active' => true, - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'accountRole' => 'defaultAsset', 'openingBalance' => round($request->input('bank_balance'), 2), 'openingBalanceDate' => new Carbon, @@ -133,7 +132,7 @@ class NewUserController extends Controller 'accountType' => 'asset', 'virtualBalance' => 0, 'active' => true, - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'accountRole' => 'savingAsset', 'openingBalance' => round($request->input('savings_balance'), 2), 'openingBalanceDate' => new Carbon, @@ -158,7 +157,7 @@ class NewUserController extends Controller 'accountType' => 'asset', 'virtualBalance' => round($request->get('credit_card_limit'), 2), 'active' => true, - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'accountRole' => 'ccAsset', 'openingBalance' => null, 'openingBalanceDate' => null, diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index cdbbde9253..52411d7ed0 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -10,7 +10,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\TokenFormRequest; use FireflyIII\Models\AccountType; @@ -47,7 +46,7 @@ class PreferencesController extends Controller { $domain = $this->getDomain(); /** @noinspection PhpMethodParametersCountMismatchInspection */ - $secret = $google2fa->generateSecretKey(16, Auth::user()->id); + $secret = $google2fa->generateSecretKey(16, auth()->user()->id); Session::flash('two-factor-secret', $secret); $image = $google2fa->getQRCodeInline('Firefly III at ' . $domain, null, $secret, 150); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 5a58392aba..e51948dd3e 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use FireflyIII\Events\UserIsDeleted; use FireflyIII\Http\Requests\DeleteAccountFormRequest; use FireflyIII\Http\Requests\ProfileFormRequest; @@ -41,7 +40,7 @@ class ProfileController extends Controller */ public function changePassword() { - return view('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', trans('firefly.change_your_password'))->with( + return view('profile.change-password')->with('title', auth()->user()->email)->with('subTitle', trans('firefly.change_your_password'))->with( 'mainTitleIcon', 'fa-user' ); } @@ -51,7 +50,7 @@ class ProfileController extends Controller */ public function deleteAccount() { - return view('profile.delete-account')->with('title', Auth::user()->email)->with('subTitle', trans('firefly.delete_account'))->with( + return view('profile.delete-account')->with('title', auth()->user()->email)->with('subTitle', trans('firefly.delete_account'))->with( 'mainTitleIcon', 'fa-user' ); } @@ -62,7 +61,7 @@ class ProfileController extends Controller */ public function index() { - return view('profile.index')->with('title', trans('firefly.profile'))->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user'); + return view('profile.index')->with('title', trans('firefly.profile'))->with('subTitle', auth()->user()->email)->with('mainTitleIcon', 'fa-user'); } /** @@ -73,7 +72,7 @@ class ProfileController extends Controller public function postChangePassword(ProfileFormRequest $request) { // old, new1, new2 - if (!Hash::check($request->get('current_password'), Auth::user()->password)) { + if (!Hash::check($request->get('current_password'), auth()->user()->password)) { Session::flash('error', strval(trans('firefly.invalid_current_password'))); return redirect(route('profile.change-password')); @@ -86,8 +85,8 @@ class ProfileController extends Controller } // update the user with the new password. - Auth::user()->password = bcrypt($request->get('new_password')); - Auth::user()->save(); + auth()->user()->password = bcrypt($request->get('new_password')); + auth()->user()->save(); Session::flash('success', strval(trans('firefly.password_changed'))); @@ -103,22 +102,22 @@ class ProfileController extends Controller public function postDeleteAccount(DeleteAccountFormRequest $request) { // old, new1, new2 - if (!Hash::check($request->get('password'), Auth::user()->password)) { + if (!Hash::check($request->get('password'), auth()->user()->password)) { Session::flash('error', strval(trans('firefly.invalid_password'))); return redirect(route('profile.delete-account')); } // respond to deletion: - event(new UserIsDeleted(Auth::user(), $request->ip())); + event(new UserIsDeleted(auth()->user(), $request->ip())); // store some stuff for the future: $registration = Preferences::get('registration_ip_address')->data; $confirmation = Preferences::get('confirmation_ip_address')->data; // DELETE! - $email = Auth::user()->email; - Auth::user()->delete(); + $email = auth()->user()->email; + auth()->user()->delete(); Session::flush(); Session::flash('gaEventCategory', 'user'); Session::flash('gaEventAction', 'delete-account'); diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index 23c5bf7fac..1149c536f3 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use FireflyIII\Http\Requests\RuleFormRequest; use FireflyIII\Http\Requests\TestRuleFormRequest; use FireflyIII\Models\Rule; @@ -189,7 +188,7 @@ class RuleController extends Controller { $this->createDefaultRuleGroup(); $this->createDefaultRule(); - $ruleGroups = $repository->getRuleGroupsWithRules(Auth::user()); + $ruleGroups = $repository->getRuleGroupsWithRules(auth()->user()); return view('rules.index', compact('ruleGroups')); } @@ -243,7 +242,7 @@ class RuleController extends Controller $data = [ 'rule_group_id' => $ruleGroup->id, 'title' => $request->get('title'), - 'user_id' => Auth::user()->id, + 'user_id' => auth()->user()->id, 'trigger' => $request->get('trigger'), 'description' => $request->get('description'), 'rule-triggers' => $request->get('rule-trigger'), @@ -380,7 +379,7 @@ class RuleController extends Controller $data = [ 'rule_group_id' => $repository->getFirstRuleGroup()->id, 'stop_processing' => 0, - 'user_id' => Auth::user()->id, + 'user_id' => auth()->user()->id, 'title' => trans('firefly.default_rule_name'), 'description' => trans('firefly.default_rule_description'), 'trigger' => 'store-journal', @@ -413,7 +412,7 @@ class RuleController extends Controller if ($repository->count() === 0) { $data = [ - 'user_id' => Auth::user()->id, + 'user_id' => auth()->user()->id, 'title' => trans('firefly.default_rule_group_name'), 'description' => trans('firefly.default_rule_group_description'), ]; diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php index 9dc3f38d66..a2a6cb70d9 100644 --- a/app/Http/Controllers/RuleGroupController.php +++ b/app/Http/Controllers/RuleGroupController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use Carbon\Carbon; use ExpandedForm; use FireflyIII\Crud\Account\AccountCrudInterface; @@ -96,7 +95,7 @@ class RuleGroupController extends Controller { $title = $ruleGroup->title; - $moveTo = Auth::user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete'))); + $moveTo = auth()->user()->ruleGroups()->find(intval(Input::get('move_rules_before_delete'))); $repository->destroy($ruleGroup, $moveTo); @@ -163,7 +162,7 @@ class RuleGroupController extends Controller $job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup); // Apply parameters to the job - $job->setUser(Auth::user()); + $job->setUser(auth()->user()); $job->setAccounts($accounts); $job->setStartDate($startDate); $job->setEndDate($endDate); @@ -207,7 +206,7 @@ class RuleGroupController extends Controller $data = [ 'title' => $request->input('title'), 'description' => $request->input('description'), - 'user_id' => Auth::user()->id, + 'user_id' => auth()->user()->id, ]; $ruleGroup = $repository->store($data); diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 5f6982914c..7673602135 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers; -use Auth; use FireflyIII\Http\Requests\TagFormRequest; use FireflyIII\Models\Preference; use FireflyIII\Models\Tag; @@ -194,7 +193,7 @@ class TagController extends Controller foreach ($types as $type) { /** @var Collection $tags */ - $tags = Auth::user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get(); + $tags = auth()->user()->tags()->where('tagMode', $type)->orderBy('date', 'ASC')->get(); $tags = $tags->sortBy( function (Tag $tag) { $date = !is_null($tag->date) ? $tag->date->format('Ymd') : '000000'; diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.php index 8d981d79de..8b82048cb6 100644 --- a/app/Http/Controllers/Transaction/MassController.php +++ b/app/Http/Controllers/Transaction/MassController.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Controllers\Transaction; -use Auth; use Carbon\Carbon; use ExpandedForm; use FireflyIII\Http\Controllers\Controller; @@ -205,7 +204,7 @@ class MassController extends Controller 'destination_account_id' => $sourceAccountName, 'destination_account_name' => $destAccountName, 'amount' => round($request->get('amount')[$journal->id], 4), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'amount_currency_id_amount' => intval($request->get('amount_currency_id_amount_' . $journal->id)), 'date' => new Carbon($request->get('date')[$journal->id]), 'interest_date' => $journal->interest_date, diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index bf71bb329b..0c26c37041 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -41,7 +41,7 @@ class Authenticate return redirect()->guest('login'); } - if (intval(Auth::user()->blocked) === 1) { + if (intval(auth()->user()->blocked) === 1) { Auth::guard($guard)->logout(); Session::flash('logoutMessage', trans('firefly.block_account_logout')); diff --git a/app/Http/Middleware/AuthenticateTwoFactor.php b/app/Http/Middleware/AuthenticateTwoFactor.php index 265b55e8ef..6f4d3dcd26 100644 --- a/app/Http/Middleware/AuthenticateTwoFactor.php +++ b/app/Http/Middleware/AuthenticateTwoFactor.php @@ -45,7 +45,7 @@ class AuthenticateTwoFactor return redirect()->guest('login'); } - if (intval(Auth::user()->blocked) === 1) { + if (intval(auth()->user()->blocked) === 1) { Auth::guard($guard)->logout(); Session::flash('logoutMessage', trans('firefly.block_account_logout')); diff --git a/app/Http/Middleware/IsAdmin.php b/app/Http/Middleware/IsAdmin.php index a75420343c..11addec25f 100644 --- a/app/Http/Middleware/IsAdmin.php +++ b/app/Http/Middleware/IsAdmin.php @@ -43,7 +43,7 @@ class IsAdmin return redirect()->guest('login'); } /** @var User $user */ - $user = Auth::user(); + $user = auth()->user(); if (!$user->hasRole('owner')) { return redirect(route('home')); } diff --git a/app/Http/Requests/BillFormRequest.php b/app/Http/Requests/BillFormRequest.php index 5d9a975a02..02e7a2891e 100644 --- a/app/Http/Requests/BillFormRequest.php +++ b/app/Http/Requests/BillFormRequest.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Requests; -use Auth; use Carbon\Carbon; use Input; @@ -45,7 +44,7 @@ class BillFormRequest extends Request 'amount_currency_id_amount_max' => intval($this->get('amount_currency_id_amount_max')), 'amount_max' => round($this->get('amount_max'), 2), 'date' => new Carbon($this->get('date')), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'repeat_freq' => $this->get('repeat_freq'), 'skip' => intval($this->get('skip')), 'automatch' => intval($this->get('automatch')) === 1, diff --git a/app/Http/Requests/ConfigurationRequest.php b/app/Http/Requests/ConfigurationRequest.php index 74b26161f5..fedd9ff04b 100644 --- a/app/Http/Requests/ConfigurationRequest.php +++ b/app/Http/Requests/ConfigurationRequest.php @@ -11,8 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Requests; -use Auth; - /** * Class ConfigurationRequest * @@ -27,7 +25,7 @@ class ConfigurationRequest extends Request public function authorize() { // Only allow logged in users and admins - return auth()->check() && Auth::user()->hasRole('owner'); + return auth()->check() && auth()->user()->hasRole('owner'); } /** diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php index fa59a96cbd..51013ec45e 100644 --- a/app/Http/Requests/JournalFormRequest.php +++ b/app/Http/Requests/JournalFormRequest.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Http\Requests; -use Auth; use Carbon\Carbon; use Exception; use FireflyIII\Exceptions\FireflyException; @@ -50,7 +49,7 @@ class JournalFormRequest extends Request 'destination_account_id' => intval($this->get('destination_account_id')), 'destination_account_name' => $this->get('destination_account_name') ?? '', 'amount' => round($this->get('amount'), 2), - 'user' => Auth::user()->id, + 'user' => auth()->user()->id, 'amount_currency_id_amount' => intval($this->get('amount_currency_id_amount')), 'date' => new Carbon($this->get('date')), 'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null, diff --git a/app/Models/Account.php b/app/Models/Account.php index 429a0ced6f..ff3745af39 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use FireflyIII\Exceptions\FireflyException; use Illuminate\Contracts\Encryption\DecryptException; @@ -154,7 +153,7 @@ class Account extends Model { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index e92db070fb..3d299e4e0c 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -71,7 +70,7 @@ class Attachment extends Model { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Bill.php b/app/Models/Bill.php index e6262f58d9..4003278f8e 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -82,7 +81,7 @@ class Bill extends Model public static function routeBinder(Bill $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 3eccc9585a..656260bf47 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -95,7 +94,7 @@ class Budget extends Model public static function routeBinder(Budget $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Category.php b/app/Models/Category.php index df693cbc15..6ea3be8e99 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -90,7 +89,7 @@ class Category extends Model public static function routeBinder(Category $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/ExportJob.php b/app/Models/ExportJob.php index 095655bbf5..d82111ff62 100644 --- a/app/Models/ExportJob.php +++ b/app/Models/ExportJob.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -45,7 +44,7 @@ class ExportJob extends Model public static function routeBinder($value) { if (auth()->check()) { - $model = self::where('key', $value)->where('user_id', Auth::user()->id)->first(); + $model = self::where('key', $value)->where('user_id', auth()->user()->id)->first(); if (!is_null($model)) { return $model; } diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php index 053426411f..d04e126a24 100644 --- a/app/Models/ImportJob.php +++ b/app/Models/ImportJob.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Storage; @@ -63,7 +62,7 @@ class ImportJob extends Model public static function routeBinder($value) { if (auth()->check()) { - $model = self::where('key', $value)->where('user_id', Auth::user()->id)->first(); + $model = self::where('key', $value)->where('user_id', auth()->user()->id)->first(); if (!is_null($model)) { return $model; } diff --git a/app/Models/LimitRepetition.php b/app/Models/LimitRepetition.php index d9f8526d7a..888897357a 100644 --- a/app/Models/LimitRepetition.php +++ b/app/Models/LimitRepetition.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -58,7 +57,7 @@ class LimitRepetition extends Model $object = LimitRepetition::where('limit_repetitions.id', $value) ->leftJoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') - ->where('budgets.user_id', Auth::user()->id) + ->where('budgets.user_id', auth()->user()->id) ->first(['limit_repetitions.*']); if ($object) { return $object; diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 7b732999e7..a9b3b0b775 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -71,7 +70,7 @@ class PiggyBank extends Model public static function routeBinder(PiggyBank $value) { if (auth()->check()) { - if ($value->account->user_id == Auth::user()->id) { + if ($value->account->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Rule.php b/app/Models/Rule.php index c06661277b..c97e9f7f3b 100644 --- a/app/Models/Rule.php +++ b/app/Models/Rule.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -60,7 +59,7 @@ class Rule extends Model public static function routeBinder(Rule $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php index 1fd63e13f0..27a1621d14 100644 --- a/app/Models/RuleGroup.php +++ b/app/Models/RuleGroup.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -56,7 +55,7 @@ class RuleGroup extends Model public static function routeBinder(RuleGroup $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index da031b66ff..1d87311a3d 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Crypt; use FireflyIII\Support\Models\TagSupport; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -97,7 +96,7 @@ class Tag extends TagSupport public static function routeBinder(Tag $value) { if (auth()->check()) { - if ($value->user_id == Auth::user()->id) { + if ($value->user_id == auth()->user()->id) { return $value; } } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 09c7fb4d83..9765a008f7 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Models; -use Auth; use Carbon\Carbon; use Crypt; use FireflyIII\Support\CacheProperties; @@ -133,7 +132,7 @@ class TransactionJournal extends TransactionJournalSupport $object = TransactionJournal::where('transaction_journals.id', $value) ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->whereIn('transaction_types.type', $validTypes) - ->where('user_id', Auth::user()->id)->first(['transaction_journals.*']); + ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']); if ($object) { return $object; } diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.php index 525e9a3dbb..264cbea26a 100644 --- a/app/Support/Binder/AccountList.php +++ b/app/Support/Binder/AccountList.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use FireflyIII\Models\Account; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -43,7 +42,7 @@ class AccountList implements BinderInterface /** @var \Illuminate\Support\Collection $object */ $object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->whereIn('accounts.id', $ids) - ->where('user_id', Auth::user()->id) + ->where('user_id', auth()->user()->id) ->get(['accounts.*']); if ($object->count() > 0) { return $object; diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.php index 98a8b465a9..9f848304d7 100644 --- a/app/Support/Binder/BudgetList.php +++ b/app/Support/Binder/BudgetList.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use FireflyIII\Models\Budget; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -38,7 +37,7 @@ class BudgetList implements BinderInterface /** @var \Illuminate\Support\Collection $object */ $object = Budget::where('active', 1) ->whereIn('id', $ids) - ->where('user_id', Auth::user()->id) + ->where('user_id', auth()->user()->id) ->get(); // add empty budget if applicable. diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.php index d1fabdad84..ecaefd37a0 100644 --- a/app/Support/Binder/CategoryList.php +++ b/app/Support/Binder/CategoryList.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use FireflyIII\Models\Category; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -36,7 +35,7 @@ class CategoryList implements BinderInterface $ids = explode(',', $value); /** @var \Illuminate\Support\Collection $object */ $object = Category::whereIn('id', $ids) - ->where('user_id', Auth::user()->id) + ->where('user_id', auth()->user()->id) ->get(); // add empty category if applicable. diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index a5581de5f2..caecb1d7a2 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use Carbon\Carbon; use Exception; use FireflyIII\Helpers\FiscalHelper; @@ -42,7 +41,7 @@ class Date implements BinderInterface try { $date = new Carbon($value); } catch (Exception $e) { - Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id); + Log::error('Could not parse date "' . $value . '" for user #' . auth()->user()->id); throw new NotFoundHttpException; } diff --git a/app/Support/Binder/JournalList.php b/app/Support/Binder/JournalList.php index 9ef829c8c9..b1961fa3e3 100644 --- a/app/Support/Binder/JournalList.php +++ b/app/Support/Binder/JournalList.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use FireflyIII\Models\TransactionJournal; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -37,7 +36,7 @@ class JournalList implements BinderInterface /** @var \Illuminate\Support\Collection $object */ $object = TransactionJournal::whereIn('transaction_journals.id', $ids) ->expanded() - ->where('transaction_journals.user_id', Auth::user()->id) + ->where('transaction_journals.user_id', auth()->user()->id) ->get(TransactionJournal::queryFields()); if ($object->count() > 0) { diff --git a/app/Support/Binder/UnfinishedJournal.php b/app/Support/Binder/UnfinishedJournal.php index 61c413f3ba..727d865484 100644 --- a/app/Support/Binder/UnfinishedJournal.php +++ b/app/Support/Binder/UnfinishedJournal.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Binder; -use Auth; use FireflyIII\Models\TransactionJournal; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -36,7 +35,7 @@ class UnfinishedJournal implements BinderInterface $object = TransactionJournal::where('transaction_journals.id', $value) ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->where('completed', 0) - ->where('user_id', Auth::user()->id)->first(['transaction_journals.*']); + ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']); if ($object) { return $object; } diff --git a/app/Support/CacheProperties.php b/app/Support/CacheProperties.php index 6dfd62671d..90d469d476 100644 --- a/app/Support/CacheProperties.php +++ b/app/Support/CacheProperties.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace FireflyIII\Support; -use Auth; use Cache; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection as EloquentCollection; @@ -39,7 +38,7 @@ class CacheProperties { $this->properties = new Collection; if (auth()->check()) { - $this->addProperty(Auth::user()->id); + $this->addProperty(auth()->user()->id); $this->addProperty(Prefs::lastActivity()); } } diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index 1d8b32b0e2..2a82f03034 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support; -use Auth; use Cache; use FireflyIII\Models\Configuration; use FireflyIII\Models\Preference; @@ -32,11 +31,11 @@ class FireflyConfig */ public function delete($name): bool { - $fullName = 'preference' . Auth::user()->id . $name; + $fullName = 'preference' . auth()->user()->id . $name; if (Cache::has($fullName)) { Cache::forget($fullName); } - Preference::where('user_id', Auth::user()->id)->where('name', $name)->delete(); + Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); return true; } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index d505c4fd77..2f17d809eb 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support; -use Auth; use Cache; use FireflyIII\Models\Preference; use FireflyIII\User; @@ -31,11 +30,11 @@ class Preferences */ public function delete($name): bool { - $fullName = 'preference' . Auth::user()->id . $name; + $fullName = 'preference' . auth()->user()->id . $name; if (Cache::has($fullName)) { Cache::forget($fullName); } - Preference::where('user_id', Auth::user()->id)->where('name', $name)->delete(); + Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); return true; } @@ -48,12 +47,12 @@ class Preferences */ public function get($name, $default = null) { - $user = Auth::user(); + $user = auth()->user(); if (is_null($user)) { return $default; } - return $this->getForUser(Auth::user(), $name, $default); + return $this->getForUser(auth()->user(), $name, $default); } /** @@ -115,7 +114,7 @@ class Preferences */ public function set($name, $value): Preference { - $user = Auth::user(); + $user = auth()->user(); if (is_null($user)) { // make new preference, return it: $pref = new Preference; @@ -125,7 +124,7 @@ class Preferences return $pref; } - return $this->setForUser(Auth::user(), $name, $value); + return $this->setForUser(auth()->user(), $name, $value); } /** diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 2379dfd2bc..facd842df2 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -12,7 +12,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Search; -use Auth; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; use FireflyIII\Models\TransactionJournal; @@ -33,7 +32,7 @@ class Search implements SearchInterface */ public function searchAccounts(array $words): Collection { - return Auth::user()->accounts()->with('accounttype')->where( + return auth()->user()->accounts()->with('accounttype')->where( function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); @@ -50,7 +49,7 @@ class Search implements SearchInterface public function searchBudgets(array $words): Collection { /** @var Collection $set */ - $set = Auth::user()->budgets()->get(); + $set = auth()->user()->budgets()->get(); $newSet = $set->filter( function (Budget $b) use ($words) { $found = 0; @@ -75,7 +74,7 @@ class Search implements SearchInterface public function searchCategories(array $words): Collection { /** @var Collection $set */ - $set = Auth::user()->categories()->get(); + $set = auth()->user()->categories()->get(); $newSet = $set->filter( function (Category $c) use ($words) { $found = 0; @@ -111,7 +110,7 @@ class Search implements SearchInterface public function searchTransactions(array $words): Collection { // decrypted transaction journals: - $decrypted = Auth::user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 0)->where( + $decrypted = auth()->user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 0)->where( function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('transaction_journals.description', 'LIKE', '%' . e($word) . '%'); @@ -120,7 +119,7 @@ class Search implements SearchInterface )->get(TransactionJournal::queryFields()); // encrypted - $all = Auth::user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::queryFields()); + $all = auth()->user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::queryFields()); $set = $all->filter( function (TransactionJournal $journal) use ($words) { foreach ($words as $word) { diff --git a/app/Support/Steam.php b/app/Support/Steam.php index 390eaa1aab..8ffe548cd2 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support; -use Auth; use Carbon\Carbon; use DB; use FireflyIII\Models\Account; @@ -185,10 +184,10 @@ class Steam { $list = []; - $set = Auth::user()->transactions() - ->whereIn('transactions.account_id', $accounts) - ->groupBy(['transactions.account_id', 'transaction_journals.user_id']) - ->get(['transactions.account_id', DB::raw('MAX(`transaction_journals`.`date`) as `max_date`')]); + $set = auth()->user()->transactions() + ->whereIn('transactions.account_id', $accounts) + ->groupBy(['transactions.account_id', 'transaction_journals.user_id']) + ->get(['transactions.account_id', DB::raw('MAX(`transaction_journals`.`date`) as `max_date`')]); foreach ($set as $entry) { $list[intval($entry->account_id)] = new Carbon($entry->max_date); diff --git a/app/Support/Twig/Budget.php b/app/Support/Twig/Budget.php index 673ed156d7..dca3d1eaeb 100644 --- a/app/Support/Twig/Budget.php +++ b/app/Support/Twig/Budget.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Support\Twig; -use Auth; use FireflyIII\Models\LimitRepetition; use FireflyIII\Support\CacheProperties; use Twig_Extension; @@ -39,14 +38,14 @@ class Budget extends Twig_Extension return $cache->get(); } $sum - = Auth::user()->transactionJournals() - ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') - ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') - ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') - ->before($repetition->enddate) - ->after($repetition->startdate) - ->where('limit_repetitions.id', '=', $repetition->id) - ->get(['transaction_journals.*'])->sum('amount'); + = auth()->user()->transactionJournals() + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->before($repetition->enddate) + ->after($repetition->startdate) + ->where('limit_repetitions.id', '=', $repetition->id) + ->get(['transaction_journals.*'])->sum('amount'); $cache->store($sum); return $sum; diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index e6805b5ee0..8742ea9880 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -11,7 +11,6 @@ declare(strict_types = 1); namespace FireflyIII\Validation; -use Auth; use Config; use Crypt; use DB; @@ -85,7 +84,7 @@ class FireflyValidator extends Validator if (intval($value) === 0) { return true; } - $count = DB::table($parameters[0])->where('user_id', Auth::user()->id)->where($field, $value)->count(); + $count = DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count(); if ($count === 1) { return true; } @@ -256,7 +255,7 @@ class FireflyValidator extends Validator $query = AccountMeta:: leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') - ->where('accounts.user_id', Auth::user()->id) + ->where('accounts.user_id', auth()->user()->id) ->where('account_meta.name', 'accountNumber'); if (intval($accountId) > 0) { @@ -288,7 +287,7 @@ class FireflyValidator extends Validator public function validateUniqueForUser($attribute, $value, $parameters): bool { $query = DB::table($parameters[0])->where($parameters[1], $value); - $query->where('user_id', Auth::user()->id); + $query->where('user_id', auth()->user()->id); if (isset($parameters[2])) { $query->where('id', '!=', $parameters[2]); } @@ -324,7 +323,7 @@ class FireflyValidator extends Validator $exclude = $parameters[2] ?? 0; // get entries from table - $set = DB::table($table)->where('user_id', Auth::user()->id) + $set = DB::table($table)->where('user_id', auth()->user()->id) ->where('id', '!=', $exclude)->get([$field]); foreach ($set as $entry) { @@ -349,7 +348,7 @@ class FireflyValidator extends Validator { $exclude = $parameters[0] ?? null; $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') - ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id); + ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id); if (!is_null($exclude)) { $query->where('piggy_banks.id', '!=', $exclude); } @@ -444,7 +443,7 @@ class FireflyValidator extends Validator $ignore = $existingAccount->id; $value = $this->tryDecrypt($value); - $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name == $value) { @@ -468,7 +467,7 @@ class FireflyValidator extends Validator $ignore = $parameters[0] ?? 0; $value = $this->tryDecrypt($value); - $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name == $value) { @@ -492,7 +491,7 @@ class FireflyValidator extends Validator $type = AccountType::whereType($search)->first(); $ignore = $parameters[0] ?? 0; - $set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); + $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { if ($entry->name == $value) {