From 2f3b52e5810d78c8411e862808784ee86c7ac541 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sun, 4 Feb 2024 23:35:10 -0500 Subject: [PATCH] refactor: Use @var instead of instanceof --- src/Retour.php | 6 ++++-- src/controllers/RedirectsController.php | 18 ++++++++---------- src/controllers/SettingsController.php | 9 ++++----- src/helpers/Permission.php | 13 ++++++------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Retour.php b/src/Retour.php index 700ca188..8f353850 100644 --- a/src/Retour.php +++ b/src/Retour.php @@ -189,8 +189,9 @@ public function getCpNavItem() { $subNavs = []; $navItem = parent::getCpNavItem(); + /** @var User $user */ $user = Craft::$app->getUser(); - if (($user instanceof User) && $currentUser = $user->getIdentity()) { + if ($currentUser = $user->getIdentity()) { // Only show sub-navs the user has permission to view if ($currentUser->can('retour:dashboard')) { $subNavs['dashboard'] = [ @@ -535,8 +536,9 @@ protected function installCpEventListeners() Dashboard::class, Dashboard::EVENT_REGISTER_WIDGET_TYPES, function (RegisterComponentTypesEvent $event) { + /** @var User $user */ $user = Craft::$app->getUser(); - if (($user instanceof User) && $currentUser = $user->getIdentity()) { + if ($currentUser = $user->getIdentity()) { if ($currentUser->can('accessPlugin-retour')) { $event->types[] = RetourWidget::class; } diff --git a/src/controllers/RedirectsController.php b/src/controllers/RedirectsController.php index 1581739f..240fcf47 100644 --- a/src/controllers/RedirectsController.php +++ b/src/controllers/RedirectsController.php @@ -270,12 +270,11 @@ public function actionSaveRedirect() if (!$redirect->validate()) { Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings.")); // Send the redirect back to the template + /** @var UrlManager $urlManager */ $urlManager = Craft::$app->getUrlManager(); - if ($urlManager instanceof UrlManager) { - $urlManager->setRouteParams([ - 'redirect' => $redirect, - ]); - } + $urlManager->setRouteParams([ + 'redirect' => $redirect, + ]); return null; } @@ -290,12 +289,11 @@ public function actionSaveRedirect() if ($testRedirectConfig === null) { Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop.")); // Send the redirect back to the template + /** @var UrlManager $urlManager */ $urlManager = Craft::$app->getUrlManager(); - if ($urlManager instanceof UrlManager) { - $urlManager->setRouteParams([ - 'redirect' => $redirect, - ]); - } + $urlManager->setRouteParams([ + 'redirect' => $redirect, + ]); return null; } diff --git a/src/controllers/SettingsController.php b/src/controllers/SettingsController.php index 87389150..965d1351 100644 --- a/src/controllers/SettingsController.php +++ b/src/controllers/SettingsController.php @@ -123,12 +123,11 @@ public function actionSavePluginSettings() Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save plugin settings.")); // Send the plugin back to the template + /** @var UrlManager $urlManager */ $urlManager = Craft::$app->getUrlManager(); - if ($urlManager instanceof UrlManager) { - $urlManager->setRouteParams([ - 'plugin' => $plugin, - ]); - } + $urlManager->setRouteParams([ + 'plugin' => $plugin, + ]); return null; } diff --git a/src/helpers/Permission.php b/src/helpers/Permission.php index 97c1af13..8b313a9e 100644 --- a/src/helpers/Permission.php +++ b/src/helpers/Permission.php @@ -35,15 +35,14 @@ class Permission */ public static function controllerPermissionCheck(string $permission) { + /** @var User $user */ $user = Craft::$app->getUser(); - if ($user instanceof User) { - if (($currentUser = $user->getIdentity()) === null) { - throw new ForbiddenHttpException('Your account has no identity.'); - } + if (($currentUser = $user->getIdentity()) === null) { + throw new ForbiddenHttpException('Your account has no identity.'); + } - if (!$currentUser->can($permission)) { - throw new ForbiddenHttpException("Your account doesn't have permission to assign access this resource."); - } + if (!$currentUser->can($permission)) { + throw new ForbiddenHttpException("Your account doesn't have permission to assign access this resource."); } }