Skip to content

Commit

Permalink
refactor: ECS code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 31, 2024
1 parent 8c8a2cd commit 4b43009
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 86 deletions.
38 changes: 19 additions & 19 deletions src/Retour.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,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 +257,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 +296,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,7 +306,7 @@ 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) {
Expand All @@ -327,7 +327,7 @@ function (Event $event) {
}
};

$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 +345,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 +357,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 +369,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 +381,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 +393,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 +410,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 +430,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 +445,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 +467,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 +505,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 +539,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 +550,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 +566,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/console/controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class StatsController extends Controller
public function options($actionID): array
{
return [
'limit'
'limit',
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FileController extends Controller

protected const DOCUMENTATION_URL = 'https://github.com/nystudio107/craft-retour/';

const LOG_FILE_NAME = 'retour-csv-import-errors';
public const LOG_FILE_NAME = 'retour-csv-import-errors';

protected const EXPORT_REDIRECTS_CSV_FIELDS = [
'redirectSrcUrl' => 'Legacy URL Pattern',
Expand Down Expand Up @@ -174,7 +174,7 @@ protected function importCsvApi8(AbstractCsv $csv, array $columns, array $header
$csv->setOffset(1);
$columns = ArrayHelper::filterEmptyStringsFromArray($columns);
$rowIndex = 1;
$csv->each(function ($row) use ($headers, $columns, &$rowIndex, &$hasErrors) {
$csv->each(function($row) use ($headers, $columns, &$rowIndex, &$hasErrors) {
$redirectConfig = [
'id' => 0,
];
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/RedirectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ public function actionEditRedirect(
int $redirectId = 0,
string $defaultUrl = '',
int $siteId = 0,
StaticRedirectsModel $redirect = null
): Response
{
StaticRedirectsModel $redirect = null,
): Response {
$variables = [];
PermissionHelper::controllerPermissionCheck('retour:redirects');

Expand Down
12 changes: 5 additions & 7 deletions src/controllers/TablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ public function actionDashboard(
int $per_page = 20,
$filter = '',
$siteId = 0,
$handled = 'all'
): Response
{
$handled = 'all',
): Response {
PermissionHelper::controllerPermissionCheck('retour:dashboard');
$data = [];
$sortField = 'hitCount';
Expand Down Expand Up @@ -149,7 +148,7 @@ public function actionDashboard(
}
$stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [
'defaultUrl' => $encodedUrl,
'siteId' => $statSiteId
'siteId' => $statSiteId,
]);
}
}
Expand Down Expand Up @@ -190,9 +189,8 @@ public function actionRedirects(
int $per_page = 20,
$filter = '',
$siteId = 0,
$shortLinks = false
): Response
{
$shortLinks = false,
): Response {
PermissionHelper::controllerPermissionCheck('retour:redirects');
$data = [];
$sortField = 'hitCount';
Expand Down
5 changes: 2 additions & 3 deletions src/fields/ShortLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
*/
class ShortLink extends Field implements PreviewableFieldInterface
{

public string $redirectSrcMatch = 'pathonly';
public int $redirectHttpCode = 301;

static protected bool $allowShortLinkUpdates = true;
protected static bool $allowShortLinkUpdates = true;

// Static Methods
// =========================================================================
Expand Down Expand Up @@ -108,7 +107,7 @@ public function afterElementSave(ElementInterface $element, bool $isNew): void
if ($this->translationMethod === Field::TRANSLATION_METHOD_NONE && ($element->propagating || $parentElement->propagating)) {
return;
}
} else if (!empty($value) && !StringHelper::startsWith($value, 'http')) {
} elseif (!empty($value) && !StringHelper::startsWith($value, 'http')) {
$value = UrlHelper::siteUrl($value, null, null, $element->siteId);
}

Expand Down
6 changes: 3 additions & 3 deletions src/gql/arguments/RetourArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public static function getArguments(): array
'uri' => [
'name' => 'uri',
'type' => Type::string(),
'description' => 'The URI to resolve a redirect for.'
'description' => 'The URI to resolve a redirect for.',
],
'site' => [
'name' => 'site',
'type' => Type::string(),
'description' => 'The site handle to resolve a redirect for.'
'description' => 'The site handle to resolve a redirect for.',
],
'siteId' => [
'name' => 'siteId',
'type' => Type::int(),
'description' => 'The siteId to resolve a redirect for.'
'description' => 'The siteId to resolve a redirect for.',
],
];
}
Expand Down
11 changes: 5 additions & 6 deletions src/gql/interfaces/RetourInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@

namespace nystudio107\retour\gql\interfaces;

use nystudio107\retour\gql\types\generators\RetourGenerator;

use craft\gql\base\InterfaceType as BaseInterfaceType;
use craft\gql\TypeLoader;
use craft\gql\GqlEntityRegistry;

use craft\gql\GqlEntityRegistry;
use GraphQL\Type\Definition\InterfaceType;

use GraphQL\Type\Definition\Type;
use nystudio107\retour\gql\types\generators\RetourGenerator;

/**
* Class RetourInterface
Expand Down Expand Up @@ -50,7 +49,7 @@ public static function getType($fields = null): Type
'name' => static::getName(),
'fields' => self::class . '::getFieldDefinitions',
'description' => 'This is the interface implemented by Retour.',
'resolveType' => function (array $value) {
'resolveType' => function(array $value) {
return GqlEntityRegistry::getEntity(RetourGenerator::getName());
},
]));
Expand Down Expand Up @@ -81,7 +80,7 @@ public static function getFieldDefinitions(): array
'site' => [
'name' => 'site',
'type' => Type::string(),
'description' => 'The site handle of the redirect (or null for all sites).'
'description' => 'The site handle of the redirect (or null for all sites).',
],
'siteId' => [
'name' => 'siteId',
Expand Down
10 changes: 5 additions & 5 deletions src/gql/queries/RetourQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace nystudio107\retour\gql\queries;

use craft\gql\base\Query;
use GraphQL\Type\Definition\Type;
use nystudio107\retour\gql\arguments\RetourArguments;

use nystudio107\retour\gql\interfaces\RetourInterface;
use nystudio107\retour\gql\resolvers\RetourResolver;

use craft\gql\base\Query;
use GraphQL\Type\Definition\Type;
use nystudio107\retour\helpers\Gql as GqlHelper;

/**
Expand Down Expand Up @@ -57,12 +57,12 @@ public static function getQueries($checkToken = true): array
'site' => [
'name' => 'site',
'type' => Type::string(),
'description' => 'The site handle to list all redirects for.'
'description' => 'The site handle to list all redirects for.',
],
'siteId' => [
'name' => 'siteId',
'type' => Type::int(),
'description' => 'The siteId to list all redirects for.'
'description' => 'The siteId to list all redirects for.',
],
],
'resolve' => RetourResolver::class . '::resolveAll',
Expand Down
6 changes: 3 additions & 3 deletions src/gql/types/RetourType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace nystudio107\retour\gql\types;

use nystudio107\retour\gql\interfaces\RetourInterface;

use Craft;
use craft\gql\base\ObjectType;

use craft\gql\base\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;

use nystudio107\retour\gql\interfaces\RetourInterface;

/**
* Class RetourType
*
Expand Down
Loading

0 comments on commit 4b43009

Please sign in to comment.