From 406fa44b1bb35a484175705960e956f79ced0aed Mon Sep 17 00:00:00 2001 From: "Oscar Sanchez S." Date: Fri, 17 Jan 2025 17:48:59 +0800 Subject: [PATCH] Fix linting errors in plugin files --- includes/classes/Command.php | 5 ++--- .../classes/Feature/RelatedPosts/RelatedPosts.php | 12 ++++++------ includes/classes/Feature/Search/Weighting.php | 11 +++-------- .../Feature/WooCommerce/OrdersAutosuggest.php | 5 ++--- includes/classes/IndexHelper.php | 10 +++++----- includes/classes/Indexable/Post/QueryIntegration.php | 5 ++--- includes/classes/Indexables.php | 8 ++++---- includes/classes/Installer.php | 5 ++--- includes/classes/REST/MetaKeys.php | 3 +-- includes/classes/REST/Sync.php | 6 ++---- includes/classes/REST/Taxonomies.php | 3 +-- includes/classes/REST/Token.php | 3 +-- includes/compat.php | 6 +++--- tests/php/screen/TestStatusReport.php | 2 +- 14 files changed, 35 insertions(+), 49 deletions(-) diff --git a/includes/classes/Command.php b/includes/classes/Command.php index 0ae7e9bcd8..a3fbfe814c 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -1114,14 +1114,13 @@ private function maybe_change_host( $assoc_args ) { if ( isset( $assoc_args['ep-host'] ) ) { add_filter( 'ep_host', - function ( $host ) use ( $assoc_args ) { + function ( $host ) use ( $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found return $assoc_args['ep-host']; } ); } } - /** * maybe change index prefix on the fly * @@ -1133,7 +1132,7 @@ private function maybe_change_index_prefix( $assoc_args ) { if ( isset( $assoc_args['ep-prefix'] ) ) { add_filter( 'ep_index_prefix', - function ( $prefix ) use ( $assoc_args ) { + function ( $prefix ) use ( $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found return $assoc_args['ep-prefix']; } ); diff --git a/includes/classes/Feature/RelatedPosts/RelatedPosts.php b/includes/classes/Feature/RelatedPosts/RelatedPosts.php index e3806d95cf..a2a237636b 100644 --- a/includes/classes/Feature/RelatedPosts/RelatedPosts.php +++ b/includes/classes/Feature/RelatedPosts/RelatedPosts.php @@ -114,14 +114,14 @@ public function formatted_args( $formatted_args, $args ) { * Search Elasticsearch for related content * * @param int $post_id Post ID - * @param int $return Return code + * @param int $post_return Number of posts to return * @since 4.1.0 * @return WP_Query */ - public function get_related_query( $post_id, $return = 5 ) { + public function get_related_query( $post_id, $post_return = 5 ) { $args = array( 'more_like' => $post_id, - 'posts_per_page' => $return, + 'posts_per_page' => $post_return, 'ep_integrate' => true, 'ignore_sticky_posts' => true, ); @@ -141,15 +141,15 @@ public function get_related_query( $post_id, $return = 5 ) { * Search Elasticsearch for related content * * @param int $post_id Post ID - * @param int $return Return code + * @param int $post_return Number of posts to return * * @since 2.1 * @uses get_related_query * * @return array|bool */ - public function find_related( $post_id, $return = 5 ) { - $query = $this->get_related_query( $post_id, $return ); + public function find_related( $post_id, $post_return = 5 ) { + $query = $this->get_related_query( $post_id, $post_return ); if ( ! $query->have_posts() ) { return false; diff --git a/includes/classes/Feature/Search/Weighting.php b/includes/classes/Feature/Search/Weighting.php index f7d582b9fc..ef923c5441 100644 --- a/includes/classes/Feature/Search/Weighting.php +++ b/includes/classes/Feature/Search/Weighting.php @@ -348,12 +348,9 @@ public function render_settings_page() { /** * Recursively renders each settings section and its children. * - * @param string $post_type Current post type we're rendering - * @param array $field Current field to render - * @param array $current_values Current stored weighting values * @deprecated */ - public function render_settings_section( $post_type, $field, $current_values ) { + public function render_settings_section() { _doing_it_wrong( __METHOD__, esc_html( 'Weighting sections display are now handled via React components.' ), @@ -378,10 +375,9 @@ public function handle_save() { /** * We need this method to test handle_save properly. * - * @param string $redirect_url Redirect URL. * @deprecated */ - protected function redirect( $redirect_url ) { + protected function redirect() { _doing_it_wrong( __METHOD__, esc_html( 'Weighting settings are now updated using the REST API, and do not redirect server-side.' ), @@ -392,12 +388,11 @@ protected function redirect( $redirect_url ) { /** * Save weighting configuration for each searchable post_type. * - * @param array $settings weighting settings * @return void * @since 3.4.1 * @deprecated */ - public function save_weighting_configuration( $settings ) { + public function save_weighting_configuration() { _doing_it_wrong( __METHOD__, esc_html( 'Weighting sections display are now handled via React components.' ), diff --git a/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php b/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php index ef2c9036a4..f38ca3f9dc 100644 --- a/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php +++ b/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php @@ -312,7 +312,7 @@ public function get_search_template() { add_filter( 'ep_bypass_exclusion_from_search', '__return_true', 10 ); add_filter( 'ep_intercept_remote_request', '__return_true' ); - add_filter( 'ep_do_intercept_request', [ $this, 'intercept_search_request' ], 10, 4 ); + add_filter( 'ep_do_intercept_request', [ $this, 'intercept_search_request' ], 10, 3 ); add_filter( 'ep_is_integrated_request', [ $this, 'is_integrated_request' ], 10, 2 ); $query = new \WP_Query( @@ -363,10 +363,9 @@ public function is_integrated_request( $is_integrated, $context ) { * @param object $response Response * @param array $query Query * @param array $args WP_Query argument array - * @param int $failures Count of failures in request loop * @return object $response Response */ - public function intercept_search_request( $response, $query = [], $args = [], $failures = 0 ) { + public function intercept_search_request( $response, $query = [], $args = [] ) { $this->search_template = $query['args']['body']; return wp_remote_request( $query['url'], $args ); diff --git a/includes/classes/IndexHelper.php b/includes/classes/IndexHelper.php index ffc761b582..143dee551e 100644 --- a/includes/classes/IndexHelper.php +++ b/includes/classes/IndexHelper.php @@ -1168,21 +1168,21 @@ public function get_last_sync(): array { * We used to have two different filters for this (one for the dashboard, another for CLI), * this method combines both. * - * @param {stdClass} $object Object to be checked + * @param {stdClass} $indexable_object Object to be checked * @param {Indexable} $indexable Indexable * @return boolean */ - protected function should_skip_object_index( $object, $indexable ) { + protected function should_skip_object_index( $indexable_object, $indexable ) { /** * Filter whether to not sync specific item in dashboard or not * * @since 2.1 * @hook ep_item_sync_kill * @param {boolean} $kill False means dont sync - * @param {array} $object Object to sync + * @param {array} $indexable_object Object to sync * @return {Indexable} Indexable that object belongs to */ - $ep_item_sync_kill = apply_filters( 'ep_item_sync_kill', false, $object, $indexable ); + $ep_item_sync_kill = apply_filters( 'ep_item_sync_kill', false, $indexable_object, $indexable ); /** * Conditionally kill indexing for a post @@ -1192,7 +1192,7 @@ protected function should_skip_object_index( $object, $indexable ) { * @param {int} $object_id Object ID * @return {bool} New value */ - $ep_indexable_sync_kill = apply_filters( 'ep_' . $indexable->slug . '_index_kill', false, $object->ID ); + $ep_indexable_sync_kill = apply_filters( 'ep_' . $indexable->slug . '_index_kill', false, $indexable_object->ID ); return $ep_item_sync_kill || $ep_indexable_sync_kill; } diff --git a/includes/classes/Indexable/Post/QueryIntegration.php b/includes/classes/Indexable/Post/QueryIntegration.php index 06d78c9781..6dd9e1d7eb 100644 --- a/includes/classes/Indexable/Post/QueryIntegration.php +++ b/includes/classes/Indexable/Post/QueryIntegration.php @@ -64,7 +64,7 @@ public function __construct( $indexable_slug = 'post' ) { add_filter( 'posts_pre_query', array( $this, 'get_es_posts' ), 10, 2 ); // Properly restore blog if necessary - add_action( 'loop_end', array( $this, 'maybe_restore_blog' ), 10, 1 ); + add_action( 'loop_end', array( $this, 'maybe_restore_blog' ), 10, 0 ); // Properly switch to blog if necessary add_action( 'the_post', array( $this, 'maybe_switch_to_blog' ), 10, 2 ); @@ -194,10 +194,9 @@ public function maybe_switch_to_blog( $post, $query = null ) { /** * Make sure the correct blog is restored * - * @param WP_Query $query WP_Query instance * @since 0.9 */ - public function maybe_restore_blog( $query ) { + public function maybe_restore_blog() { if ( ! is_multisite() ) { // @codeCoverageIgnoreStart return; diff --git a/includes/classes/Indexables.php b/includes/classes/Indexables.php index a2011c616a..c405f1edc3 100644 --- a/includes/classes/Indexables.php +++ b/includes/classes/Indexables.php @@ -118,24 +118,24 @@ public function is_active( string $slug ): bool { /** * Get all indexable instances * - * @param boolean $global If true or false, will only get Indexables with that global property. + * @param boolean $global_property If true or false, will only get Indexables with that global property. * @param boolean $slug_only True returns an array of only string slugs. * @param string $status Whether to return active indexables or all registered. * @since 3.0, 4.5.0 Added $status * @return array */ - public function get_all( $global = null, $slug_only = false, $status = 'active' ) { + public function get_all( $global_property = null, $slug_only = false, $status = 'active' ) { $indexables = []; $list = ( 'active' === $status ) ? $this->active_indexables : $this->registered_indexables; foreach ( $list as $slug => $indexable ) { - if ( null === $global ) { + if ( null === $global_property ) { if ( $slug_only ) { $indexables[] = $slug; } else { $indexables[] = $indexable; } - } elseif ( $global === $indexable->global ) { + } elseif ( $global_property === $indexable->global ) { if ( $slug_only ) { $indexables[] = $slug; } else { diff --git a/includes/classes/Installer.php b/includes/classes/Installer.php index c5a54bb4f5..c62235059d 100644 --- a/includes/classes/Installer.php +++ b/includes/classes/Installer.php @@ -33,18 +33,17 @@ class Installer { */ public function setup() { add_action( 'admin_init', [ $this, 'calculate_install_status' ], 9 ); - add_filter( 'admin_title', [ $this, 'filter_admin_title' ], 10, 2 ); + add_filter( 'admin_title', [ $this, 'filter_admin_title' ], 10 ); } /** * Filter admin title for install page * * @param string $admin_title Current title - * @param string $title Original title * @since 3.0 * @return string */ - public function filter_admin_title( $admin_title, $title ) { + public function filter_admin_title( $admin_title ) { if ( 'install' === Screen::factory()->get_current_screen() ) { // translators: Site Name return sprintf( esc_html__( 'ElasticPress Setup ‹ %s — WordPress', 'elasticpress' ), esc_html( get_bloginfo( 'name' ) ) ); diff --git a/includes/classes/REST/MetaKeys.php b/includes/classes/REST/MetaKeys.php index ae75cd595a..f7c8d56f40 100644 --- a/includes/classes/REST/MetaKeys.php +++ b/includes/classes/REST/MetaKeys.php @@ -50,10 +50,9 @@ public function check_permission() { /** * Get indexed meta keys. * - * @param \WP_REST_Request $request Full details about the request. * @return array */ - public function get_meta_keys( \WP_REST_Request $request ) { + public function get_meta_keys() { $post_indexable = Indexables::factory()->get( 'post' ); try { diff --git a/includes/classes/REST/Sync.php b/includes/classes/REST/Sync.php index 41280bdddc..7c16fe0fbe 100644 --- a/includes/classes/REST/Sync.php +++ b/includes/classes/REST/Sync.php @@ -177,10 +177,9 @@ public function output( array $message ) { /** * Get the status of a sync in progress. * - * @param \WP_REST_Request $request Full details about the request. * @return void */ - public function get_sync_status( \WP_REST_Request $request ) { + public function get_sync_status() { nocache_headers(); $index_meta = Utils\get_indexing_status(); @@ -211,10 +210,9 @@ public function get_sync_status( \WP_REST_Request $request ) { /** * Cancel a sync in progress. * - * @param \WP_REST_Request $request Full details about the request. * @return void */ - public function cancel_sync( \WP_REST_Request $request ) { + public function cancel_sync() { nocache_headers(); $index_meta = Utils\get_indexing_status(); diff --git a/includes/classes/REST/Taxonomies.php b/includes/classes/REST/Taxonomies.php index 582cccb333..92caf0af73 100644 --- a/includes/classes/REST/Taxonomies.php +++ b/includes/classes/REST/Taxonomies.php @@ -49,10 +49,9 @@ public function check_permission() { /** * Get filterable taxonomies. * - * @param \WP_REST_Request $request Full details about the request. * @return array */ - public function get_taxonomies( \WP_REST_Request $request ) { + public function get_taxonomies() { $filterable_taxonomies = Features::factory()->get_registered_feature( 'facets' )->types['taxonomy']->get_facetable_taxonomies(); $taxonomies = []; diff --git a/includes/classes/REST/Token.php b/includes/classes/REST/Token.php index a999de8de6..3afe88bf73 100644 --- a/includes/classes/REST/Token.php +++ b/includes/classes/REST/Token.php @@ -81,10 +81,9 @@ public function get_token( \WP_REST_Request $request ) { /** * Refresh the temporary token. * - * @param \WP_REST_Request $request Full details about the request. * @return string|false */ - public function refresh_token( \WP_REST_Request $request ) { + public function refresh_token() { $user_id = get_current_user_id(); $endpoint = $this->get_token_endpoint(); diff --git a/includes/compat.php b/includes/compat.php index 173db48b06..4fa0ce9437 100644 --- a/includes/compat.php +++ b/includes/compat.php @@ -51,16 +51,16 @@ public function __construct( $code, $message = null ) { * Search Elasticsearch for related content * * @param int $post_id Post ID - * @param int $return Number of posts to get + * @param int $post_return Number of posts to get * @since 2.1 * @return array|bool */ -function ep_find_related( $post_id, $return = 5 ) { +function ep_find_related( $post_id, $post_return = 5 ) { _deprecated_function( __FUNCTION__, '3.0', 'ElasticPress\Features::factory()->get_registered_feature' ); $feature = \ElasticPress\Features::factory()->get_registered_feature( 'related_posts' ); - return ( ! empty( $feature ) ) ? $feature->find_related( $post_id, $return ) : false; + return ( ! empty( $feature ) ) ? $feature->find_related( $post_id, $post_return ) : false; } /** diff --git a/tests/php/screen/TestStatusReport.php b/tests/php/screen/TestStatusReport.php index cebc284d67..4049a69eab 100644 --- a/tests/php/screen/TestStatusReport.php +++ b/tests/php/screen/TestStatusReport.php @@ -60,7 +60,7 @@ public function testGetReportsFilter() { public function testGetReportsSkipped() { $status_report = new StatusReport(); - parse_str( 'ep-skip-reports[]=wordpress&ep-skip-reports[]=indexable', $_GET ); // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled + parse_str( 'ep-skip-reports[]=wordpress&ep-skip-reports[]=indexable', $_GET ); // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText $reports = $status_report->get_reports(); $this->assertSame(