Skip to content

Commit

Permalink
refactor: PHPstan code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Feb 4, 2024
1 parent 8a02491 commit de8c4c5
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 241 deletions.
43 changes: 22 additions & 21 deletions src/Retour.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author nystudio107
* @package Retour
* @since 3.0.0
* @method Settings getSettings()
*/
class Retour extends Plugin
{
Expand Down Expand Up @@ -241,7 +242,7 @@ protected function installEventListeners(): void
Event::on(
ClearCaches::class,
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
function(RegisterCacheOptionsEvent $event) {
function (RegisterCacheOptionsEvent $event) {
Craft::debug(
'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
__METHOD__
Expand All @@ -257,7 +258,7 @@ function(RegisterCacheOptionsEvent $event) {
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function(PluginEvent $event) {
function (PluginEvent $event) {
if ($event->plugin === $this) {
// Invalidate our caches after we've been installed
$this->clearAllCaches();
Expand Down Expand Up @@ -296,7 +297,7 @@ protected function installGlobalEventListeners(): void
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function(Event $event) {
function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('retour', [
Expand All @@ -306,10 +307,10 @@ function(Event $event) {
}
);

$prepareRedirectOnElementChange = function(ElementEvent $event) {
$prepareRedirectOnElementChange = function (ElementEvent $event) {
/** @var Element $element */
$element = $event->element;
if ($element !== null && !$event->isNew && $element->getUrl() !== null && !$element->propagating) {
if (!$event->isNew && $element->getUrl() !== null && !$element->propagating) {
$checkElementSlug = true;
// If we're running Craft 3.2 or later, also check that isn't not a draft or revision
if (ElementHelper::isDraftOrRevision($element)) {
Expand All @@ -320,14 +321,14 @@ function(Event $event) {
if (self::$settings->createUriChangeRedirects && $checkElementSlug) {
// Make sure this isn't a transitioning temporary draft/revision and that it's
// not propagating to other sites
if (strpos($element->uri, '__temp_') === false && !$element->propagating) {
if (!str_contains($element->uri, '__temp_')) {
Retour::$plugin->events->stashElementUris($element);
}
}
}
};

$insertRedirectOnElementChange = function(ElementEvent $event) {
$insertRedirectOnElementChange = function (ElementEvent $event) {
/** @var Element $element */
$element = $event->element;
if ($element !== null && !$event->isNew && $element->getUrl() !== null) {
Expand All @@ -345,7 +346,7 @@ function(Event $event) {
Event::on(
Elements::class,
Elements::EVENT_BEFORE_SAVE_ELEMENT,
static function(ElementEvent $event) use ($prepareRedirectOnElementChange) {
static function (ElementEvent $event) use ($prepareRedirectOnElementChange) {
Craft::debug(
'Elements::EVENT_BEFORE_SAVE_ELEMENT',
__METHOD__
Expand All @@ -357,7 +358,7 @@ static function(ElementEvent $event) use ($prepareRedirectOnElementChange) {
Event::on(
Elements::class,
Elements::EVENT_AFTER_SAVE_ELEMENT,
static function(ElementEvent $event) use ($insertRedirectOnElementChange) {
static function (ElementEvent $event) use ($insertRedirectOnElementChange) {
Craft::debug(
'Elements::EVENT_AFTER_SAVE_ELEMENT',
__METHOD__
Expand All @@ -369,7 +370,7 @@ static function(ElementEvent $event) use ($insertRedirectOnElementChange) {
Event::on(
Elements::class,
Elements::EVENT_BEFORE_UPDATE_SLUG_AND_URI,
static function(ElementEvent $event) use ($prepareRedirectOnElementChange) {
static function (ElementEvent $event) use ($prepareRedirectOnElementChange) {
Craft::debug(
'Elements::EVENT_BEFORE_UPDATE_SLUG_AND_URI',
__METHOD__
Expand All @@ -381,7 +382,7 @@ static function(ElementEvent $event) use ($prepareRedirectOnElementChange) {
Event::on(
Elements::class,
Elements::EVENT_AFTER_UPDATE_SLUG_AND_URI,
static function(ElementEvent $event) use ($insertRedirectOnElementChange) {
static function (ElementEvent $event) use ($insertRedirectOnElementChange) {
Craft::debug(
'Elements::EVENT_AFTER_UPDATE_SLUG_AND_URI',
__METHOD__
Expand All @@ -393,7 +394,7 @@ static function(ElementEvent $event) use ($insertRedirectOnElementChange) {
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_LOAD_PLUGINS,
function() {
function () {
// Install these only after all other plugins have loaded
$request = Craft::$app->getRequest();
// Only respond to non-console site requests
Expand All @@ -410,15 +411,15 @@ function() {
Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
function(RegisterComponentTypesEvent $event) {
function (RegisterComponentTypesEvent $event) {
$event->types[] = ShortLinkField::class;
}
);
// Handler: Gql::EVENT_REGISTER_GQL_TYPES
Event::on(
Gql::class,
Gql::EVENT_REGISTER_GQL_TYPES,
static function(RegisterGqlTypesEvent $event) {
static function (RegisterGqlTypesEvent $event) {
Craft::debug(
'Gql::EVENT_REGISTER_GQL_TYPES',
__METHOD__
Expand All @@ -430,7 +431,7 @@ static function(RegisterGqlTypesEvent $event) {
Event::on(
Gql::class,
Gql::EVENT_REGISTER_GQL_QUERIES,
static function(RegisterGqlQueriesEvent $event) {
static function (RegisterGqlQueriesEvent $event) {
Craft::debug(
'Gql::EVENT_REGISTER_GQL_QUERIES',
__METHOD__
Expand All @@ -445,7 +446,7 @@ static function(RegisterGqlQueriesEvent $event) {
Event::on(
Gql::class,
Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS,
static function(RegisterGqlSchemaComponentsEvent $event) {
static function (RegisterGqlSchemaComponentsEvent $event) {
Craft::debug(
'Gql::EVENT_REGISTER_GQL_SCHEMA_COMPONENTS',
__METHOD__
Expand All @@ -467,7 +468,7 @@ protected function handleSiteRequest(): void
Event::on(
ErrorHandler::class,
ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
static function(ExceptionEvent $event) {
static function (ExceptionEvent $event) {
Craft::debug(
'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION',
__METHOD__
Expand Down Expand Up @@ -505,7 +506,7 @@ protected function installSiteEventListeners(): void
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function(RegisterUrlRulesEvent $event) {
function (RegisterUrlRulesEvent $event) {
Craft::debug(
'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
__METHOD__
Expand Down Expand Up @@ -539,7 +540,7 @@ protected function installCpEventListeners(): void
Event::on(
Dashboard::class,
Dashboard::EVENT_REGISTER_WIDGET_TYPES,
function(RegisterComponentTypesEvent $event) {
function (RegisterComponentTypesEvent $event) {
$currentUser = Craft::$app->getUser()->getIdentity();
if ($currentUser->can('accessPlugin-retour')) {
$event->types[] = RetourWidget::class;
Expand All @@ -550,7 +551,7 @@ function(RegisterComponentTypesEvent $event) {
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function(RegisterUrlRulesEvent $event) {
function (RegisterUrlRulesEvent $event) {
Craft::debug(
'UrlManager::EVENT_REGISTER_CP_URL_RULES',
__METHOD__
Expand All @@ -566,7 +567,7 @@ function(RegisterUrlRulesEvent $event) {
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function(RegisterUserPermissionsEvent $event) {
function (RegisterUserPermissionsEvent $event) {
Craft::debug(
'UserPermissions::EVENT_REGISTER_PERMISSIONS',
__METHOD__
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public function actionGetRedirects($siteId = null): Response
{
$redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId);

return $this->asJson($redirects ?? []);
return $this->asJson($redirects);
}
}
2 changes: 1 addition & 1 deletion src/controllers/ChartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ChartsController extends Controller
// =========================================================================

/**
* @var bool|array
* @inheritdoc
*/
protected array|bool|int $allowAnonymous = [
];
Expand Down
Loading

0 comments on commit de8c4c5

Please sign in to comment.