From 2d766af128230c68db5f8ae36dfd828d9d0239a1 Mon Sep 17 00:00:00 2001
From: Burhan Nasir ' .
- wp_is_block_theme()
+ ( wp_is_block_theme()
? sprintf(
/* translators: Site Editor URL */
- __( 'Adds filter blocks that administrators can add to the website’s templates and template parts, so that visitors can filter applicable content and search results by one or more taxonomy terms, metafields, and date ranges.', 'elasticpress' ),
+ __( ' Adds filter blocks that administrators can add to the website’s templates and template parts, so that visitors can filter applicable content and search results by one or more taxonomy terms, metafields, and date ranges.', 'elasticpress' ),
esc_url( admin_url( 'site-editor.php' ) )
)
: sprintf(
@@ -52,7 +52,7 @@ public function __construct() {
__( 'Adds filter widgets that administrators can add to the website’s sidebars (widgetized areas), so that visitors can filter applicable content and search results by one or more taxonomy terms, metafields, and date ranges.', 'elasticpress' ),
esc_url( admin_url( 'widgets.php' ) )
)
- . '
http://
or https://
. This address will be exposed to the public.', 'elasticpress' ) : '',
'key' => 'endpoint_url',
'label' => __( 'Endpoint URL', 'elasticpress' ),
'type' => 'url',
diff --git a/includes/classes/REST/Features.php b/includes/classes/REST/Features.php
index 9be6739e3..8d179d7a9 100644
--- a/includes/classes/REST/Features.php
+++ b/includes/classes/REST/Features.php
@@ -71,6 +71,10 @@ public function get_args() {
case 'toggle':
$property['type'] = 'boolean';
break;
+ case 'url':
+ $property['type'] = 'string';
+ $property['format'] = 'uri';
+ break;
}
$properties[ $schema['key'] ] = $property;
From f2454b05de707f7a8c64d180a872cf68d6d1d0bf Mon Sep 17 00:00:00 2001
From: Felipe Elia ' . __( 'Website search results will include popular document file types, using file names as well as their content. Supported file types include: ppt, pptx, doc, docx, xls, xlsx, pdf.', 'elasticpress' ) . '
'; + $this->summary = '' . __( 'Website search results will include popular document file types, using file names as well as their content. Supported file types include: ppt, pptx, doc, docx, xls, xlsx, pdf, csv, txt.', 'elasticpress' ) . '
'; $this->docs_url = __( 'https://www.elasticpress.io/documentation/article/configuring-elasticpress-via-the-plugin-dashboard/#documents', 'elasticpress' ); From 726be4066f44f5c5a8ba78013a6b2122c77f9823 Mon Sep 17 00:00:00 2001 From: Felipe Elia@@ -72,7 +72,7 @@ function() { * @since 2.6 */ spl_autoload_register( - function( $class ) { + function ( $class ) { // project-specific namespace prefix. $prefix = 'ElasticPress\\'; diff --git a/includes/classes/AdminNotices.php b/includes/classes/AdminNotices.php index 175d37d30..352f0bada 100644 --- a/includes/classes/AdminNotices.php +++ b/includes/classes/AdminNotices.php @@ -682,7 +682,6 @@ protected function process_maybe_wrong_mapping_notice() { ]; } - } /** diff --git a/includes/classes/BlockTemplateUtils.php b/includes/classes/BlockTemplateUtils.php index fe1ae40b4..bdc897cfc 100644 --- a/includes/classes/BlockTemplateUtils.php +++ b/includes/classes/BlockTemplateUtils.php @@ -43,7 +43,7 @@ public function regenerate_cache() { * @param string $block_name The block name, e.g., `elasticpress/facet-meta` * @return array */ - public function get_specific_block_in_all_templates( string $block_name ) : array { + public function get_specific_block_in_all_templates( string $block_name ): array { $blocks = array_filter( $this->get_all_blocks_in_all_templates(), function ( $block ) use ( $block_name ) { @@ -61,7 +61,7 @@ function ( $block ) use ( $block_name ) { * * @return array */ - public function get_all_blocks_in_all_templates() : array { + public function get_all_blocks_in_all_templates(): array { /** * Short-circuits the process of getting all blocks of a template. * @@ -114,7 +114,7 @@ public function get_all_blocks_in_all_templates() : array { * @param array $block Block to be analyzed now * @return array */ - protected function recursively_get_inner_blocks( array $all_blocks, array $block ) : array { + protected function recursively_get_inner_blocks( array $all_blocks, array $block ): array { if ( empty( $block['innerBlocks'] ) ) { return $all_blocks; } diff --git a/includes/classes/Command.php b/includes/classes/Command.php index b2f9eb51e..0c978a849 100644 --- a/includes/classes/Command.php +++ b/includes/classes/Command.php @@ -10,8 +10,8 @@ namespace ElasticPress; -use \WP_CLI_Command; -use \WP_CLI; +use WP_CLI_Command; +use WP_CLI; use ElasticPress\Features; use ElasticPress\Utils; use ElasticPress\Elasticsearch; @@ -1329,7 +1329,7 @@ public function index_output( $message, $args, $index_meta, $context ) { } if ( 'index_next_batch' === $context ) { - $counter++; + ++$counter; if ( ( $counter % 10 ) === 0 ) { $time_elapsed_diff = $time_elapsed > 0 ? ' (+' . (string) ( Utility::timer_stop() - $time_elapsed ) . ')' : ''; $time_elapsed = Utility::timer_stop( 2 ); diff --git a/includes/classes/Command/Utility.php b/includes/classes/Command/Utility.php index 1cd8ae642..183e24858 100644 --- a/includes/classes/Command/Utility.php +++ b/includes/classes/Command/Utility.php @@ -8,7 +8,7 @@ namespace ElasticPress\Command; -use \WP_CLI; +use WP_CLI; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. diff --git a/includes/classes/Container.php b/includes/classes/Container.php index 0db9531a6..9b575dcff 100644 --- a/includes/classes/Container.php +++ b/includes/classes/Container.php @@ -9,9 +9,9 @@ namespace ElasticPress; -use \ElasticPress\Vendor_Prefixed\Psr\Container\ContainerInterface; +use ElasticPress\Vendor_Prefixed\Psr\Container\ContainerInterface; -use \ElasticPress\Exception\NotFoundException; +use ElasticPress\Exception\NotFoundException; /** * PSR11 compliant container class @@ -49,7 +49,7 @@ public function get( $id ) { * * @return bool */ - public function has( $id ) : bool { + public function has( $id ): bool { return isset( $this->instances[ $id ] ); } diff --git a/includes/classes/DeprecatedCommand.php b/includes/classes/DeprecatedCommand.php index f838d8b11..a0e1dff15 100644 --- a/includes/classes/DeprecatedCommand.php +++ b/includes/classes/DeprecatedCommand.php @@ -8,7 +8,7 @@ namespace ElasticPress; -use \WP_CLI; +use WP_CLI; if ( ! defined( 'ABSPATH' ) ) { // @codeCoverageIgnoreStart @@ -274,5 +274,4 @@ public function stop_indexing( $args, $assoc_args ) { ); $this->stop_sync( $args, $assoc_args ); } - } diff --git a/includes/classes/ElasticPressIo.php b/includes/classes/ElasticPressIo.php index 84f60a037..e54303f2c 100644 --- a/includes/classes/ElasticPressIo.php +++ b/includes/classes/ElasticPressIo.php @@ -44,7 +44,7 @@ public static function factory() { * @param bool $skip_cache Whether to fetch the API or use the cached messages. Defaults to false, i.e., use cache. * @return array ElasticPress.io messages. */ - public function get_endpoint_messages( $skip_cache = false ) : array { + public function get_endpoint_messages( $skip_cache = false ): array { if ( ! Utils\is_epio() ) { return []; } diff --git a/includes/classes/Elasticsearch.php b/includes/classes/Elasticsearch.php index 40208710a..38abb2d99 100644 --- a/includes/classes/Elasticsearch.php +++ b/includes/classes/Elasticsearch.php @@ -8,7 +8,7 @@ namespace ElasticPress; -use \WP_Error; +use WP_Error; use ElasticPress\Indexables; use ElasticPress\Utils; @@ -1325,7 +1325,7 @@ public function remote_request( $path, $args = [], $query_args = [], $type = '' $is_non_blocking_request = ( 0 === $request_response_code ); if ( false === $request || is_wp_error( $request ) || ( ! $is_valid_res && ! $is_non_blocking_request ) ) { - $failures++; + ++$failures; /** * Filter max number of times to attempt remote requests @@ -1369,7 +1369,6 @@ public function remote_request( $path, $args = [], $query_args = [], $type = '' do_action( 'ep_remote_request', $query, $type ); return $request; - } /** @@ -1419,7 +1418,6 @@ public function parse_api_response( $response ) { 'status' => true, 'data' => $response->_all->primaries->indexing, ); - } /** @@ -1797,7 +1795,7 @@ public function get_index_names( $status = 'active' ) { * @since 4.4.0 * @return array Array of indices in Elasticsearch */ - public function get_cluster_indices() : array { + public function get_cluster_indices(): array { $path = '_cat/indices?format=json'; $response = $this->remote_request( $path ); diff --git a/includes/classes/Exception/NotFoundException.php b/includes/classes/Exception/NotFoundException.php index e510cf2c3..3470e4347 100644 --- a/includes/classes/Exception/NotFoundException.php +++ b/includes/classes/Exception/NotFoundException.php @@ -8,7 +8,7 @@ namespace ElasticPress\Exception; -use \ElasticPress\Vendor_Prefixed\Psr\Container\NotFoundExceptionInterface; +use ElasticPress\Vendor_Prefixed\Psr\Container\NotFoundExceptionInterface; /** * NotFoundException class diff --git a/includes/classes/Feature.php b/includes/classes/Feature.php index c85189284..43295b5b4 100644 --- a/includes/classes/Feature.php +++ b/includes/classes/Feature.php @@ -433,7 +433,7 @@ public function output_settings_box() { * @since 4.4.1 * @return string */ - public function get_epio_logo() : string { + public function get_epio_logo(): string { return sprintf( '', esc_url( plugins_url( '/images/logo-elasticpress-io.svg', EP_FILE ) ) ); } @@ -443,7 +443,7 @@ public function get_epio_logo() : string { * @since 4.4.1 * @return string */ - public function get_title() : string { + public function get_title(): string { return $this->title; } @@ -453,7 +453,7 @@ public function get_title() : string { * @since 4.4.1 * @return string */ - public function get_short_title() : string { + public function get_short_title(): string { if ( ! empty( $this->short_title ) ) { return $this->short_title; } @@ -501,7 +501,7 @@ public function is_visible() { * @since 4.5.0 * @return boolean */ - public function is_available() : bool { + public function is_available(): bool { $requirements_status = $this->requirements_status(); /** * Filter whether a feature is available or not. diff --git a/includes/classes/Feature/Autosuggest/Autosuggest.php b/includes/classes/Feature/Autosuggest/Autosuggest.php index 0b71a3929..b811965b1 100644 --- a/includes/classes/Feature/Autosuggest/Autosuggest.php +++ b/includes/classes/Feature/Autosuggest/Autosuggest.php @@ -349,12 +349,10 @@ public function enqueue_scripts() { if ( defined( 'EP_AUTOSUGGEST_ENDPOINT' ) && EP_AUTOSUGGEST_ENDPOINT ) { $endpoint_url = EP_AUTOSUGGEST_ENDPOINT; - } else { - if ( Utils\is_epio() ) { + } elseif ( Utils\is_epio() ) { $endpoint_url = trailingslashit( $host ) . Indexables::factory()->get( 'post' )->get_index_name() . '/autosuggest'; - } else { - $endpoint_url = $settings['endpoint_url']; - } + } else { + $endpoint_url = $settings['endpoint_url']; } if ( empty( $endpoint_url ) ) { @@ -933,7 +931,7 @@ public function delete_cached_query() { * @since 5.1.0 * @return array */ - protected function get_contexts() : array { + protected function get_contexts(): array { /** * Filter contexts for autosuggest. * diff --git a/includes/classes/Feature/Comments/Comments.php b/includes/classes/Feature/Comments/Comments.php index 6b2462406..302c24b48 100644 --- a/includes/classes/Feature/Comments/Comments.php +++ b/includes/classes/Feature/Comments/Comments.php @@ -171,7 +171,7 @@ public static function get_searchable_post_types() { $post_types = Features::factory()->get_registered_feature( 'search' )->get_searchable_post_types(); $post_types = array_filter( $post_types, - function( $post_type ) { + function ( $post_type ) { return post_type_supports( $post_type, 'comments' ); } ); diff --git a/includes/classes/Feature/DidYouMean/DidYouMean.php b/includes/classes/Feature/DidYouMean/DidYouMean.php index 5f32c771e..63e60d4e1 100644 --- a/includes/classes/Feature/DidYouMean/DidYouMean.php +++ b/includes/classes/Feature/DidYouMean/DidYouMean.php @@ -79,7 +79,7 @@ public function output_feature_box_long() { * * @param array $mapping Post mapping. */ - public function add_mapping( $mapping ) : array { + public function add_mapping( $mapping ): array { // Shingle token filter. $mapping['settings']['analysis']['filter']['shingle_filter'] = [ 'type' => 'shingle', @@ -168,7 +168,7 @@ public function get_suggestion( $query = null ) { * @param array $args WP_Query arguments * @param array $wp_query WP_Query object */ - public function add_query_args( $formatted_args, $args, $wp_query ) : array { + public function add_query_args( $formatted_args, $args, $wp_query ): array { $search_analyzer = [ 'phrase' => [ 'field' => 'post_content.shingle', @@ -210,7 +210,7 @@ public function add_query_args( $formatted_args, $args, $wp_query ) : array { * @param bool $enabled Whether to enable the search queries integration. * @param WP_Query $query The WP_Query object. */ - public function set_ep_suggestion( $enabled, $query ) : bool { + public function set_ep_suggestion( $enabled, $query ): bool { if ( $query->is_search() && ! empty( $query->query_vars['s'] ) ) { $query->set( 'ep_suggestion', true ); } @@ -223,7 +223,7 @@ public function set_ep_suggestion( $enabled, $query ) : bool { * * Requires the search feature to be activated */ - public function requirements_status() : FeatureRequirementsStatus { + public function requirements_status(): FeatureRequirementsStatus { return new FeatureRequirementsStatus( 1 ); } diff --git a/includes/classes/Feature/Facets/FacetType.php b/includes/classes/Feature/Facets/FacetType.php index 86545101a..7d715dfe0 100644 --- a/includes/classes/Feature/Facets/FacetType.php +++ b/includes/classes/Feature/Facets/FacetType.php @@ -26,21 +26,21 @@ abstract public function setup(); * * @return string The filter name. */ - abstract public function get_filter_name() : string; + abstract public function get_filter_name(): string; /** * Get the facet filter type. * * @return string The filter name. */ - abstract public function get_filter_type() : string; + abstract public function get_filter_type(): string; /** * Get the facet sanitize function. * * @return string The function name. */ - public function get_sanitize_callback() : string { + public function get_sanitize_callback(): string { /** * Filter the facet filter sanitize callback. @@ -78,7 +78,7 @@ public function format_selected( string $facet, $value, array $filters ) { * @param array $filters Selected filters * @return array */ - public function add_query_params( array $query_params, array $filters ) : array { + public function add_query_params( array $query_params, array $filters ): array { $selected = $filters[ $this->get_filter_type() ]; foreach ( $selected as $facet => $filter ) { @@ -99,14 +99,14 @@ public function add_query_params( array $query_params, array $filters ) : array * @param string $block_name The block name * @return array */ - protected function block_template_meta_fields( string $block_name ) : array { + protected function block_template_meta_fields( string $block_name ): array { $block_template_utils = \ElasticPress\get_container()->get( '\ElasticPress\BlockTemplateUtils' ); $ep_blocks = $block_template_utils->get_specific_block_in_all_templates( $block_name ); return array_filter( array_reduce( $ep_blocks, - function( $acc, $block ) use ( $block_name ) { + function ( $acc, $block ) use ( $block_name ) { if ( 0 !== strpos( $block['blockName'], $block_name ) ) { return $acc; } diff --git a/includes/classes/Feature/Facets/Renderer.php b/includes/classes/Feature/Facets/Renderer.php index 9a96ab64b..03fec4ba3 100644 --- a/includes/classes/Feature/Facets/Renderer.php +++ b/includes/classes/Feature/Facets/Renderer.php @@ -32,7 +32,7 @@ abstract public function render( $args, $instance ); * * @return bool */ - protected function should_render() : bool { + protected function should_render(): bool { return true; } @@ -44,7 +44,7 @@ protected function should_render() : bool { * @param string $order ASC or DESC. * @return array */ - protected function order_values( array $values, string $orderby = 'count', $order = 'desc' ) : array { + protected function order_values( array $values, string $orderby = 'count', $order = 'desc' ): array { $orderby = strtolower( $orderby ); $orderby = in_array( $orderby, [ 'name', 'count' ], true ) ? $orderby : 'count'; diff --git a/includes/classes/Feature/Facets/Types/Date/FacetType.php b/includes/classes/Feature/Facets/Types/Date/FacetType.php index 83bae35cd..77c84f9f3 100644 --- a/includes/classes/Feature/Facets/Types/Date/FacetType.php +++ b/includes/classes/Feature/Facets/Types/Date/FacetType.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\Facets\Types\Date; -use \ElasticPress\Features; +use ElasticPress\Features; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. @@ -42,7 +42,7 @@ public function setup() { * * @return string The filter name. */ - public function get_filter_name() : string { + public function get_filter_name(): string { /** * Filter the facet filter name that's added to the URL * @@ -59,7 +59,7 @@ public function get_filter_name() : string { * * @return string The filter name. */ - public function get_filter_type() : string { + public function get_filter_type(): string { /** * Filter the facet filter type. Used by the Facet feature to organize filters. * @@ -139,7 +139,7 @@ public function format_selected( string $facet, $value, array $filters ) { * @param array $filters Selected filters * @return array */ - public function add_query_params( array $query_params, array $filters ) : array { + public function add_query_params( array $query_params, array $filters ): array { $selected = $filters[ $this->get_filter_type() ] ?? []; if ( ! empty( $selected['terms'] ) ) { @@ -238,7 +238,7 @@ public function get_facet_options() { * * @return array An array of formatted dates. */ - public function parse_dates( $dates ) : array { + public function parse_dates( $dates ): array { $options = array_column( $this->get_facet_options(), 'value', 'url-param' ); // Only use the first two dates. @@ -272,5 +272,4 @@ public function add_filter_name( $data ) { $data['dateFilterName'] = $this->get_filter_name(); return $data; } - } diff --git a/includes/classes/Feature/Facets/Types/Date/Renderer.php b/includes/classes/Feature/Facets/Types/Date/Renderer.php index 094ef33a9..772f931ff 100644 --- a/includes/classes/Feature/Facets/Types/Date/Renderer.php +++ b/includes/classes/Feature/Facets/Types/Date/Renderer.php @@ -250,7 +250,7 @@ protected function is_custom_date(): bool { * * @return string The filter name. */ - protected function get_filter_name() : string { + protected function get_filter_name(): string { $feature = Features::factory()->get_registered_feature( 'facets' ); $facet_type = $feature->types['date']; return $facet_type->get_filter_name(); diff --git a/includes/classes/Feature/Facets/Types/Meta/FacetType.php b/includes/classes/Feature/Facets/Types/Meta/FacetType.php index 9c59f2289..4ebacc1df 100644 --- a/includes/classes/Feature/Facets/Types/Meta/FacetType.php +++ b/includes/classes/Feature/Facets/Types/Meta/FacetType.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\Facets\Types\Meta; -use \ElasticPress\Features; +use ElasticPress\Features; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. @@ -66,7 +66,7 @@ public function agg_filters( $query_args ) { * * @return string The filter name. */ - public function get_filter_name() : string { + public function get_filter_name(): string { /** * Filter the facet filter name that's added to the URL * @@ -83,7 +83,7 @@ public function get_filter_name() : string { * * @return string The filter name. */ - public function get_filter_type() : string { + public function get_filter_type(): string { /** * Filter the facet filter type. Used by the Facet feature to organize filters. * @@ -312,7 +312,7 @@ public function get_facets_meta_fields() { * @param string $meta_key The meta field. * @return array */ - public function get_meta_values( string $meta_key ) : array { + public function get_meta_values( string $meta_key ): array { /** * Short-circuits the process of getting distinct meta values. * diff --git a/includes/classes/Feature/Facets/Types/Meta/Renderer.php b/includes/classes/Feature/Facets/Types/Meta/Renderer.php index bf078fe54..2505d75e0 100644 --- a/includes/classes/Feature/Facets/Types/Meta/Renderer.php +++ b/includes/classes/Feature/Facets/Types/Meta/Renderer.php @@ -188,7 +188,7 @@ public function render( $args, $instance ) { * @param string $url Filter URL. * @return string HTML for an individual facet term. */ - public function get_facet_item_value_html( $item, string $url ) : string { + public function get_facet_item_value_html( $item, string $url ): string { $href = sprintf( 'href="%s"', esc_url( $url ) @@ -274,7 +274,7 @@ public function get_facet_item_value_html( $item, string $url ) : string { * * @return boolean */ - protected function should_render() : bool { + protected function should_render(): bool { global $wp_query; if ( empty( $this->meta_field ) ) { @@ -299,7 +299,7 @@ protected function should_render() : bool { * * @return array */ - protected function get_selected_meta() : array { + protected function get_selected_meta(): array { $feature = Features::factory()->get_registered_feature( 'facets' ); $selected_filters = $feature->get_selected(); @@ -319,7 +319,7 @@ protected function get_selected_meta() : array { * @param string $url Filter URL. * @return string HTML for an individual facet term. */ - public function get_meta_value_html( array $value, string $url ) : string { + public function get_meta_value_html( array $value, string $url ): string { _deprecated_function( __METHOD__, '4.7.0', '\ElasticPress\Feature\Facets\Types\Meta\Renderer::get_facet_item_value_html()' ); return $this->get_facet_item_value_html( $value, $url ); diff --git a/includes/classes/Feature/Facets/Types/MetaRange/FacetType.php b/includes/classes/Feature/Facets/Types/MetaRange/FacetType.php index aa6dce91a..5bc15b124 100644 --- a/includes/classes/Feature/Facets/Types/MetaRange/FacetType.php +++ b/includes/classes/Feature/Facets/Types/MetaRange/FacetType.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\Facets\Types\MetaRange; -use \ElasticPress\Features; +use ElasticPress\Features; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. @@ -42,7 +42,7 @@ public function setup() { * * @return string The filter name. */ - public function get_filter_name() : string { + public function get_filter_name(): string { /** * Filter the facet filter name that's added to the URL * @@ -59,7 +59,7 @@ public function get_filter_name() : string { * * @return string The filter name. */ - public function get_filter_type() : string { + public function get_filter_type(): string { /** * Filter the facet filter type. Used by the Facet feature to organize filters. * @@ -207,7 +207,7 @@ public function format_selected( string $facet, $value, array $filters ) { * @param array $filters Selected filters * @return array */ - public function add_query_params( array $query_params, array $filters ) : array { + public function add_query_params( array $query_params, array $filters ): array { $selected = $filters[ $this->get_filter_type() ]; foreach ( $selected as $facet => $values ) { diff --git a/includes/classes/Feature/Facets/Types/MetaRange/Renderer.php b/includes/classes/Feature/Facets/Types/MetaRange/Renderer.php index 3fcc1e819..682fbff1b 100644 --- a/includes/classes/Feature/Facets/Types/MetaRange/Renderer.php +++ b/includes/classes/Feature/Facets/Types/MetaRange/Renderer.php @@ -106,7 +106,7 @@ public function render( $args, $instance ) { * * @return boolean */ - protected function should_render() : bool { + protected function should_render(): bool { global $wp_query; $feature = Features::factory()->get_registered_feature( 'facets' ); diff --git a/includes/classes/Feature/Facets/Types/PostType/FacetType.php b/includes/classes/Feature/Facets/Types/PostType/FacetType.php index 9192a70d1..a27b4a03c 100644 --- a/includes/classes/Feature/Facets/Types/PostType/FacetType.php +++ b/includes/classes/Feature/Facets/Types/PostType/FacetType.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\Facets\Types\PostType; -use \ElasticPress\Features; +use ElasticPress\Features; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. @@ -41,7 +41,7 @@ public function setup() { * * @return string The filter name. */ - public function get_filter_name() : string { + public function get_filter_name(): string { /** * Filter the facet filter name that's added to the URL * @@ -58,7 +58,7 @@ public function get_filter_name() : string { * * @return string The filter name. */ - public function get_filter_type() : string { + public function get_filter_type(): string { /** * Filter the facet filter type. Used by the Facet feature to organize filters. * @@ -185,7 +185,7 @@ public function format_selected( string $facet, $value, array $filters ) { * @param array $filters Selected filters * @return array */ - public function add_query_params( array $query_params, array $filters ) : array { + public function add_query_params( array $query_params, array $filters ): array { $selected = $filters[ $this->get_filter_type() ] ?? []; if ( ! empty( $selected['terms'] ) ) { diff --git a/includes/classes/Feature/Facets/Types/PostType/Renderer.php b/includes/classes/Feature/Facets/Types/PostType/Renderer.php index 6a371b178..2dac26761 100644 --- a/includes/classes/Feature/Facets/Types/PostType/Renderer.php +++ b/includes/classes/Feature/Facets/Types/PostType/Renderer.php @@ -141,7 +141,7 @@ public function render( $args, $instance ) { * @param string $url Filter URL. * @return string HTML for an individual facet term. */ - public function get_facet_item_value_html( $item, $url ) : string { + public function get_facet_item_value_html( $item, $url ): string { $href = sprintf( 'href="%s"', esc_url( $url ) @@ -227,7 +227,7 @@ public function get_facet_item_value_html( $item, $url ) : string { * * @return boolean */ - protected function should_render() : bool { + protected function should_render(): bool { global $wp_query; $feature = Features::factory()->get_registered_feature( 'facets' ); diff --git a/includes/classes/Feature/Facets/Types/Taxonomy/FacetType.php b/includes/classes/Feature/Facets/Types/Taxonomy/FacetType.php index 05e917149..e11803e69 100644 --- a/includes/classes/Feature/Facets/Types/Taxonomy/FacetType.php +++ b/includes/classes/Feature/Facets/Types/Taxonomy/FacetType.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\Facets\Types\Taxonomy; -use \ElasticPress\Features; +use ElasticPress\Features; /** * Taxonomy facet type class @@ -62,7 +62,7 @@ public function register_widgets() { * * @return string The filter name. */ - public function get_filter_name() : string { + public function get_filter_name(): string { /** * Filter the facet filter name that's added to the URL * @@ -79,7 +79,7 @@ public function get_filter_name() : string { * * @return string The filter name. */ - public function get_filter_type() : string { + public function get_filter_type(): string { /** * Filter the facet filter type. Used by the Facet feature to organize filters. * @@ -96,7 +96,7 @@ public function get_filter_type() : string { * * @return string The function name. */ - public function get_sanitize_callback() : string { + public function get_sanitize_callback(): string { /** * Filter the facet filter sanitize callback. diff --git a/includes/classes/Feature/Facets/Types/Taxonomy/Renderer.php b/includes/classes/Feature/Facets/Types/Taxonomy/Renderer.php index 44fb7a7dc..e51bb15a2 100644 --- a/includes/classes/Feature/Facets/Types/Taxonomy/Renderer.php +++ b/includes/classes/Feature/Facets/Types/Taxonomy/Renderer.php @@ -260,7 +260,7 @@ public function render( $args, $instance ) { break; } - $i++; + ++$i; } $flat_ordered_terms = array(); @@ -526,24 +526,22 @@ protected function order_by_selected( $terms, $selected_terms, $order = false, $ if ( 'asc' === $order ) { uasort( $ordered_terms, - function( $a, $b ) { + function ( $a, $b ) { return $a->count <=> $b->count; } ); } else { uasort( $ordered_terms, - function( $a, $b ) { + function ( $a, $b ) { return $b->count <=> $a->count; } ); } - } else { - if ( 'asc' === $order ) { + } elseif ( 'asc' === $order ) { ksort( $ordered_terms ); - } else { - krsort( $ordered_terms ); - } + } else { + krsort( $ordered_terms ); } return array_values( $ordered_terms ); diff --git a/includes/classes/Feature/ProtectedContent/ProtectedContent.php b/includes/classes/Feature/ProtectedContent/ProtectedContent.php index 936227be1..76f5935a2 100644 --- a/includes/classes/Feature/ProtectedContent/ProtectedContent.php +++ b/includes/classes/Feature/ProtectedContent/ProtectedContent.php @@ -174,10 +174,8 @@ public function integrate( $query ) { } $query->set( 'ep_integrate', true ); - } else { - if ( ! empty( $supported_post_types[ $post_type ] ) ) { + } elseif ( ! empty( $supported_post_types[ $post_type ] ) ) { $query->set( 'ep_integrate', true ); - } } /** @@ -356,12 +354,9 @@ public function integrate_comments_query( $comment_query ) { } $comment_query->query_vars['ep_integrate'] = true; - } else { - if ( in_array( $comment_type, $supported_comment_types, true ) ) { + } elseif ( in_array( $comment_type, $supported_comment_types, true ) ) { $comment_query->query_vars['ep_integrate'] = true; - } } - } /** @@ -425,7 +420,7 @@ public function requirements_status() { * @param bool $skip Current value of $skip * @return bool */ - public function sync_password_protected( $new_skip, bool $skip ) : bool { + public function sync_password_protected( $new_skip, bool $skip ): bool { return $skip; } diff --git a/includes/classes/Feature/RelatedPosts/RelatedPosts.php b/includes/classes/Feature/RelatedPosts/RelatedPosts.php index 428430db0..e3806d95c 100644 --- a/includes/classes/Feature/RelatedPosts/RelatedPosts.php +++ b/includes/classes/Feature/RelatedPosts/RelatedPosts.php @@ -8,7 +8,7 @@ namespace ElasticPress\Feature\RelatedPosts; -use \WP_Query; +use WP_Query; use ElasticPress\Elasticsearch; use ElasticPress\Feature; use ElasticPress\REST; diff --git a/includes/classes/Feature/Search/Search.php b/includes/classes/Feature/Search/Search.php index 30f0422e2..229ba3193 100644 --- a/includes/classes/Feature/Search/Search.php +++ b/includes/classes/Feature/Search/Search.php @@ -817,7 +817,6 @@ public function save_exclude_from_search_meta( $post_id ) { } else { delete_post_meta( $post_id, 'ep_exclude_from_search' ); } - } /** diff --git a/includes/classes/Feature/Search/Synonyms.php b/includes/classes/Feature/Search/Synonyms.php index 0f089704e..749c1a5cf 100644 --- a/includes/classes/Feature/Search/Synonyms.php +++ b/includes/classes/Feature/Search/Synonyms.php @@ -475,7 +475,7 @@ public function handle_update_synonyms() { public function update_synonyms() { return array_reduce( $this->get_affected_indices(), - function( $success, $index ) { + function ( $success, $index ) { $filter = $this->get_synonym_filter(); $mapping = Elasticsearch::factory()->get_mapping( $index ); @@ -532,7 +532,7 @@ public function get_affected_indices() { return array_filter( array_map( - function( $index ) { + function ( $index ) { $indexable = Indexables::factory()->get( $index ); return $indexable ? $indexable->get_index_name() : false; }, @@ -890,7 +890,7 @@ public function setup_endpoint() { * @param array $filters Array of filters. * @return array */ - protected function maybe_change_filter_position( array $filters ) : array { + protected function maybe_change_filter_position( array $filters ): array { $lowercase_filter = array_search( 'lowercase', $filters, true ); if ( false !== $lowercase_filter ) { diff --git a/includes/classes/Feature/Search/Weighting.php b/includes/classes/Feature/Search/Weighting.php index a4fe8cabf..f7d582b9f 100644 --- a/includes/classes/Feature/Search/Weighting.php +++ b/includes/classes/Feature/Search/Weighting.php @@ -418,7 +418,7 @@ public function register_rest_routes() { [ 'callback' => [ $this, 'update_weighting' ], 'methods' => 'POST', - 'permission_callback' => function() { + 'permission_callback' => function () { return current_user_can( Utils\get_capability() ); }, ] diff --git a/includes/classes/Feature/SearchOrdering/SearchOrdering.php b/includes/classes/Feature/SearchOrdering/SearchOrdering.php index eff29f77a..3dde59649 100644 --- a/includes/classes/Feature/SearchOrdering/SearchOrdering.php +++ b/includes/classes/Feature/SearchOrdering/SearchOrdering.php @@ -181,7 +181,7 @@ public function filter_updated_messages( $messages ) { * * @return FeatureRequirementsStatus */ - public function requirements_status() : FeatureRequirementsStatus { + public function requirements_status(): FeatureRequirementsStatus { return new FeatureRequirementsStatus( 0 ); } @@ -796,5 +796,4 @@ public function update_page_title( $admin_title, $title ) { return $admin_title; } - } diff --git a/includes/classes/Feature/Terms/Terms.php b/includes/classes/Feature/Terms/Terms.php index 35a0d66eb..f81998885 100644 --- a/includes/classes/Feature/Terms/Terms.php +++ b/includes/classes/Feature/Terms/Terms.php @@ -125,5 +125,4 @@ public function set_admin_terms_search_fuzziness( $fuzziness ) { } return $fuzziness; } - } diff --git a/includes/classes/Feature/WooCommerce/Orders.php b/includes/classes/Feature/WooCommerce/Orders.php index 8c705acdc..39411f78d 100644 --- a/includes/classes/Feature/WooCommerce/Orders.php +++ b/includes/classes/Feature/WooCommerce/Orders.php @@ -279,7 +279,7 @@ public function search_order( $wp ) { * @param \WP_Query $query Query we might integrate with * @return bool */ - public function should_integrate_with_query( \WP_Query $query ) : bool { + public function should_integrate_with_query( \WP_Query $query ): bool { /** * Check the post type */ @@ -300,7 +300,7 @@ public function should_integrate_with_query( \WP_Query $query ) : bool { * * @return array */ - public function get_supported_post_types() : array { + public function get_supported_post_types(): array { $post_types = [ 'shop_order', 'shop_order_refund' ]; /** @@ -344,7 +344,7 @@ public function get_supported_post_types() : array { * @param array $notices Current EP notices * @return array */ - public function hpos_compatibility_notice( array $notices ) : array { + public function hpos_compatibility_notice( array $notices ): array { $current_screen = \get_current_screen(); if ( empty( $current_screen->id ) || 'woocommerce_page_wc-orders' !== $current_screen->id ) { return $notices; diff --git a/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php b/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php index 9413eac2d..ef2c9036a 100644 --- a/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php +++ b/includes/classes/Feature/WooCommerce/OrdersAutosuggest.php @@ -504,7 +504,7 @@ public function mapping( $mapping ) { * @param \WP_Query $query Query being executed * @return array New search fields */ - public function set_search_fields( array $search_fields, \WP_Query $query ) : array { + public function set_search_fields( array $search_fields, \WP_Query $query ): array { $is_orders_search_template = (bool) $query->get( 'ep_order_search_template' ); if ( $is_orders_search_template ) { @@ -574,7 +574,7 @@ public function maybe_set_posts_where( $where, $query ) { * @since 5.1.0 * @return boolean */ - public function is_available() : bool { + public function is_available(): bool { /** * Whether the autosuggest feature is available for non * ElasticPress.io customers. @@ -592,7 +592,7 @@ public function is_available() : bool { * @since 5.1.0 * @return boolean */ - public function is_enabled() : bool { + public function is_enabled(): bool { return $this->is_available() && '1' === $this->woocommerce->get_setting( 'orders' ); } @@ -627,7 +627,7 @@ public function is_hpos_compatible() { * @param array $settings_schema Current settings schema * @return array */ - public function add_settings_schema( array $settings_schema ) : array { + public function add_settings_schema( array $settings_schema ): array { $available = $this->is_available(); $settings_schema[] = [ @@ -649,7 +649,7 @@ public function add_settings_schema( array $settings_schema ) : array { * @since 5.1.0 * @return string */ - protected function get_setting_help_message() : string { + protected function get_setting_help_message(): string { $available = $this->is_available(); $epio_autosuggest_kb_link = 'https://www.elasticpress.io/documentation/article/configuring-elasticpress-io-order-autosuggest/'; diff --git a/includes/classes/Feature/WooCommerce/Products.php b/includes/classes/Feature/WooCommerce/Products.php index 134bddb2b..86d15c3c2 100644 --- a/includes/classes/Feature/WooCommerce/Products.php +++ b/includes/classes/Feature/WooCommerce/Products.php @@ -665,7 +665,7 @@ public function translate_args( $query ) { * @param \WP_Query $query Query we might integrate with * @return bool */ - public function should_integrate_with_query( \WP_Query $query ) : bool { + public function should_integrate_with_query( \WP_Query $query ): bool { $has_ep_integrate = isset( $query->query_vars['ep_integrate'] ) && filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ); $is_search = '' !== $this->woocommerce->get_search_term( $query ); @@ -703,7 +703,7 @@ public function should_integrate_with_query( \WP_Query $query ) : bool { * * @return array */ - public function get_supported_taxonomies() : array { + public function get_supported_taxonomies(): array { $supported_taxonomies = array( 'product_cat', 'product_tag', @@ -749,7 +749,7 @@ public function get_supported_taxonomies() : array { * @param \WP_Query $query The WP_Query object * @return array */ - public function get_supported_post_types( \WP_Query $query ) : array { + public function get_supported_post_types( \WP_Query $query ): array { $post_types = [ 'product_variation' ]; $is_main_post_type_archive = $query->is_main_query() && $query->is_post_type_archive( 'product' ); @@ -935,7 +935,7 @@ protected function maybe_set_search_fields( \WP_Query $query ) { * @param array $search_fields Array of search fields. * @return array */ - public function remove_author( array $search_fields ) : array { + public function remove_author( array $search_fields ): array { foreach ( $search_fields as $field_key => $field ) { if ( 'author_name' === $field ) { unset( $search_fields[ $field_key ] ); @@ -1035,7 +1035,7 @@ protected function maybe_set_orderby( \WP_Query $query ) { * @param array $meta_key The meta key to get the mapping for. * @return string The mapped meta key. */ - public function get_orderby_meta_mapping( $meta_key ) : string { + public function get_orderby_meta_mapping( $meta_key ): string { /** * Filter WooCommerce to Elasticsearch meta mapping * @@ -1070,7 +1070,7 @@ public function get_orderby_meta_mapping( $meta_key ) : string { * @param array $attribute_taxonomies Attribute taxonomies. * @return array $attribute_taxonomies Attribute taxonomies. */ - public function add_taxonomy_attributes( array $attribute_taxonomies ) : array { + public function add_taxonomy_attributes( array $attribute_taxonomies ): array { $all_attr_taxonomies = wc_get_attribute_taxonomies(); foreach ( $all_attr_taxonomies as $attr_taxonomy ) { diff --git a/includes/classes/Feature/WooCommerce/WooCommerce.php b/includes/classes/Feature/WooCommerce/WooCommerce.php index 58186c62a..689840c61 100644 --- a/includes/classes/Feature/WooCommerce/WooCommerce.php +++ b/includes/classes/Feature/WooCommerce/WooCommerce.php @@ -136,7 +136,7 @@ public function tear_down() { * @param \WP_Query $query The WP_Query object * @return string */ - public function get_search_term( \WP_Query $query ) : string { + public function get_search_term( \WP_Query $query ): string { $search = $query->get( 'search' ); return ( ! empty( $search ) ) ? $search : $query->get( 's', '' ); } @@ -290,7 +290,7 @@ public function output_feature_box_settings() { * @deprecated 5.1.0 * @return boolean */ - public function is_orders_autosuggest_available() : bool { + public function is_orders_autosuggest_available(): bool { _deprecated_function( __METHOD__, '5.1.0', "\ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->orders_autosuggest->is_available()" ); return $this->orders_autosuggest->is_available(); } @@ -302,7 +302,7 @@ public function is_orders_autosuggest_available() : bool { * @deprecated 5.1.0 * @return boolean */ - public function is_orders_autosuggest_enabled() : bool { + public function is_orders_autosuggest_enabled(): bool { _deprecated_function( __METHOD__, '5.1.0', "\ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->orders_autosuggest->is_enabled()" ); return $this->orders_autosuggest->is_enabled(); } diff --git a/includes/classes/IndexHelper.php b/includes/classes/IndexHelper.php index be01d9725..23f9611e1 100644 --- a/includes/classes/IndexHelper.php +++ b/includes/classes/IndexHelper.php @@ -250,7 +250,7 @@ protected function build_index_meta() { protected function filter_indexables( $indexables ) { return array_filter( $indexables, - function( $indexable ) { + function ( $indexable ) { return empty( $this->args['indexables'] ) || in_array( $indexable, $this->args['indexables'], true ); } ); @@ -572,7 +572,7 @@ protected function index_next_batch() { foreach ( $this->current_query['objects'] as $object ) { if ( $this->should_skip_object_index( $object, $indexable ) ) { - $this->index_meta['current_sync_item']['skipped']++; + ++$this->index_meta['current_sync_item']['skipped']; } else { $queued_items[ $object->ID ] = true; } @@ -675,7 +675,7 @@ protected function index_next_batch() { $failed_objects, array_filter( $return['items'], - function( $item ) { + function ( $item ) { return ! empty( $item['index']['error'] ); } ) @@ -918,7 +918,7 @@ protected function update_last_index( string $final_status = '' ) { protected function add_last_sync( array $last_sync_info ) { // Remove error messages from previous syncs - we only store msgs for the newest one. $last_syncs = array_map( - function( $sync ) { + function ( $sync ) { unset( $sync['errors'] ); return $sync; }, @@ -1144,7 +1144,7 @@ public function is_full_reindexing( $indexable_slug, $blog_id = null ) { * @since 5.0.0 * @return array */ - public function get_sync_history() : array { + public function get_sync_history(): array { return Utils\get_option( 'ep_sync_history', [] ); } @@ -1154,7 +1154,7 @@ public function get_sync_history() : array { * @since 5.0.0 * @return array */ - public function get_last_sync() : array { + public function get_last_sync(): array { $syncs = $this->get_sync_history(); if ( empty( $syncs ) ) { return []; @@ -1432,7 +1432,7 @@ protected function on_error_update_and_clean( $error, $context = 'sync' ) { * @since 4.4.0 * @return integer */ - public function get_index_default_per_page() : int { + public function get_index_default_per_page(): int { /** * Filter number of items to index per cycle in the dashboard * @@ -1492,7 +1492,7 @@ protected function flush_messages_queue() { * @param string|array $messages Messages * @return array */ - protected function build_message_errors_data( $messages ) : array { + protected function build_message_errors_data( $messages ): array { $messages = (array) $messages; $error_interpreter = new \ElasticPress\ElasticsearchErrorInterpreter(); @@ -1506,7 +1506,7 @@ protected function build_message_errors_data( $messages ) : array { 'count' => 1, ]; } else { - $errors_list[ $error['error'] ]['count']++; + ++$errors_list[ $error['error'] ]['count']; } } return $errors_list; diff --git a/includes/classes/Indexable.php b/includes/classes/Indexable.php index 6e974b96e..75b9f318c 100644 --- a/includes/classes/Indexable.php +++ b/includes/classes/Indexable.php @@ -532,7 +532,7 @@ protected function send_bulk_index_request( $documents ) { timer_start(); $result = Elasticsearch::factory()->bulk_index( $this->get_index_name(), $this->slug, implode( '', $body ) ); $request_time = timer_stop(); - $requests++; + ++$requests; /** * Perform actions before a new batch of documents is processed. @@ -678,7 +678,6 @@ public function prepare_meta_types( $meta ) { } return $prepared_meta; - } /** @@ -1183,7 +1182,7 @@ public function generate_mapping() { * @param array $query_vars Query vars * @return SearchAlgorithm Instance of search algorithm to be used */ - public function get_search_algorithm( string $search_text, array $search_fields, array $query_vars ) : \ElasticPress\SearchAlgorithm { + public function get_search_algorithm( string $search_text, array $search_fields, array $query_vars ): \ElasticPress\SearchAlgorithm { /** * Filter the search algorithm to be used * @@ -1288,7 +1287,7 @@ public function setup() {} * @param array $mapping The mapping * @return array */ - public function add_ngram_analyzer( array $mapping ) : array { + public function add_ngram_analyzer( array $mapping ): array { $mapping['settings']['analysis']['analyzer']['edge_ngram_analyzer'] = array( 'type' => 'custom', 'tokenizer' => 'standard', diff --git a/includes/classes/Indexable/Comment/Comment.php b/includes/classes/Indexable/Comment/Comment.php index 70a433e91..49ad4082a 100644 --- a/includes/classes/Indexable/Comment/Comment.php +++ b/includes/classes/Indexable/Comment/Comment.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Comment; -use \WP_Comment_Query; +use WP_Comment_Query; use ElasticPress\Elasticsearch; use ElasticPress\Features; use ElasticPress\Indexable; @@ -987,11 +987,9 @@ public function prepare_meta( $comment_id ) { if ( true === $allowed_protected_keys || in_array( $key, $allowed_protected_keys, true ) ) { $allow_index = true; } - } else { + } elseif ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { - if ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { $allow_index = true; - } } /** @@ -1082,5 +1080,4 @@ protected function parse_orderby( $orderby, $order, $args ) { return $sort; } - } diff --git a/includes/classes/Indexable/Comment/QueryIntegration.php b/includes/classes/Indexable/Comment/QueryIntegration.php index c1f8043f4..950485779 100644 --- a/includes/classes/Indexable/Comment/QueryIntegration.php +++ b/includes/classes/Indexable/Comment/QueryIntegration.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Comment; -use \WP_Comment_Query; +use WP_Comment_Query; use ElasticPress\Indexables; use ElasticPress\Utils; @@ -331,7 +331,7 @@ protected function fill_descendants( $comments, $query_vars ) { } } - $level ++; + ++$level; $levels[ $level ] = $child_comments; } while ( $child_comments ); @@ -372,5 +372,4 @@ protected function fill_descendants( $comments, $query_vars ) { return $comments; } - } diff --git a/includes/classes/Indexable/Comment/SyncManager.php b/includes/classes/Indexable/Comment/SyncManager.php index 0291a8531..3b94ff8e1 100644 --- a/includes/classes/Indexable/Comment/SyncManager.php +++ b/includes/classes/Indexable/Comment/SyncManager.php @@ -227,5 +227,4 @@ protected function maybe_index_comment( $comment_id ) { } } } - } diff --git a/includes/classes/Indexable/Post/DateQuery.php b/includes/classes/Indexable/Post/DateQuery.php index 06e38f2de..46d46356e 100644 --- a/includes/classes/Indexable/Post/DateQuery.php +++ b/includes/classes/Indexable/Post/DateQuery.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Post; -use \WP_Date_Query; +use WP_Date_Query; if ( ! defined( 'ABSPATH' ) ) { // @codeCoverageIgnoreStart diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index a04280d84..f3ff530de 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -8,8 +8,8 @@ namespace ElasticPress\Indexable\Post; -use \WP_Query; -use \WP_User; +use WP_Query; +use WP_User; use ElasticPress\Elasticsearch; use ElasticPress\Indexable; @@ -755,7 +755,7 @@ private function get_parent_terms( $terms, $term, $tax_name, $object_id ) { * @param int $post_id The post ID * @return array */ - private function get_formatted_term( \WP_Term $term, int $post_id ) : array { + private function get_formatted_term( \WP_Term $term, int $post_id ): array { $formatted_term = [ 'term_id' => $term->term_id, 'slug' => $term->slug, @@ -810,7 +810,6 @@ protected function get_term_order( $term_taxonomy_id, $object_id ) { } return isset( $term_orders[ $term_taxonomy_id ] ) ? (int) $term_orders[ $term_taxonomy_id ] : 0; - } /** @@ -902,7 +901,6 @@ public function prepare_meta( $post ) { * @return {array} Prepared meta */ return apply_filters( 'ep_prepared_post_meta', $prepared_meta, $post ); - } /** @@ -1418,7 +1416,7 @@ protected function apply_aggregations( $formatted_args, $agg, $use_filters, $fil * @param array $query_vars Query vars * @return SearchAlgorithm Instance of search algorithm to be used */ - public function get_search_algorithm( string $search_text, array $search_fields, array $query_vars ) : \ElasticPress\SearchAlgorithm { + public function get_search_algorithm( string $search_text, array $search_fields, array $query_vars ): \ElasticPress\SearchAlgorithm { $search_algorithm_version_option = \ElasticPress\Utils\get_option( 'ep_search_algorithm_version', '4.0' ); /** @@ -2465,7 +2463,7 @@ protected function maybe_set_aggs( $formatted_args, $args, $filters ) { * @param string $field Field name * @return string */ - protected function parse_tax_query_field( string $field ) : string { + protected function parse_tax_query_field( string $field ): string { $from_to = [ 'name' => 'name.raw', @@ -2590,11 +2588,9 @@ protected function filter_allowed_metas_auto( $metas, $post ) { if ( true === $allowed_protected_keys || in_array( $key, $allowed_protected_keys, true ) ) { $allow_index = true; } - } else { + } elseif ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { - if ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { $allow_index = true; - } } /** @@ -2620,7 +2616,7 @@ protected function filter_allowed_metas_auto( $metas, $post ) { * @param bool $force_refresh Whether to use or not a cached value. Default false, use cached. * @return array */ - public function get_distinct_meta_field_keys_db( bool $force_refresh = false ) : array { + public function get_distinct_meta_field_keys_db( bool $force_refresh = false ): array { global $wpdb; /** @@ -2706,7 +2702,7 @@ public function get_distinct_meta_field_keys_db( bool $force_refresh = false ) : * @param bool $force_refresh Whether to use or not a cached value. Default false, use cached. * @return array */ - public function get_distinct_meta_field_keys_db_per_post_type( string $post_type, bool $force_refresh = false ) : array { + public function get_distinct_meta_field_keys_db_per_post_type( string $post_type, bool $force_refresh = false ): array { $allowed_screen = 'status-report' === \ElasticPress\Screen::factory()->get_current_screen(); /** @@ -2794,7 +2790,7 @@ public function get_distinct_meta_field_keys_db_per_post_type( string $post_type * @param bool $force_refresh Whether to use or not a cached value. Default false, use cached. * @return array */ - public function get_indexable_meta_keys_per_post_type( string $post_type, bool $force_refresh = false ) : array { + public function get_indexable_meta_keys_per_post_type( string $post_type, bool $force_refresh = false ): array { $mock_post = new \WP_Post( (object) [ 'post_type' => $post_type ] ); $meta_keys = $this->get_distinct_meta_field_keys_db_per_post_type( $post_type, $force_refresh ); @@ -2821,7 +2817,7 @@ function ( $meta_key ) use ( $mock_post ) { * @param bool $force_refresh Whether to use or not a cached value. Default false, use cached. * @return array */ - public function get_predicted_indexable_meta_keys( bool $force_refresh = false ) : array { + public function get_predicted_indexable_meta_keys( bool $force_refresh = false ): array { $empty_post = new \WP_Post( (object) [] ); $meta_keys = $this->get_distinct_meta_field_keys_db( $force_refresh ); @@ -2833,7 +2829,7 @@ public function get_predicted_indexable_meta_keys( bool $force_refresh = false ) $all_keys = array_filter( array_keys( $filtered_meta ), - function( $meta_key ) use ( $empty_post ) { + function ( $meta_key ) use ( $empty_post ) { return $this->is_meta_allowed( $meta_key, $empty_post ); } ); @@ -2849,7 +2845,7 @@ function( $meta_key ) use ( $empty_post ) { * @since 5.1.0 * @return string */ - public function get_test_meta_value() : string { + public function get_test_meta_value(): string { /** * Filter the value used to fill meta fields while predicting indexable content. * @@ -2931,7 +2927,7 @@ protected function get_lazy_post_type_ids( string $post_type ) { * @param array $post_ids Set of post IDs * @return array */ - protected function get_meta_keys_from_post_ids( array $post_ids ) : array { + protected function get_meta_keys_from_post_ids( array $post_ids ): array { global $wpdb; if ( empty( $post_ids ) ) { @@ -2959,7 +2955,7 @@ protected function get_meta_keys_from_post_ids( array $post_ids ) : array { * @param array $mapping The mapping array * @return array */ - public function add_term_suggest_field( array $mapping ) : array { + public function add_term_suggest_field( array $mapping ): array { if ( version_compare( (string) Elasticsearch::factory()->get_elasticsearch_version(), '7.0', '<' ) ) { $mapping_properties = &$mapping['mappings']['post']['properties']; } else { @@ -2983,7 +2979,7 @@ public function add_term_suggest_field( array $mapping ) : array { * @since 5.1.4 * @return array */ - public function get_all_allowed_metas_manual() : array { + public function get_all_allowed_metas_manual(): array { $post_types = \ElasticPress\Indexables::factory()->get( 'post' )->get_indexable_post_types(); $search_feature = \ElasticPress\Features::factory()->get_registered_feature( 'search' ); $weighting = $search_feature->weighting->get_weighting_configuration_with_defaults(); diff --git a/includes/classes/Indexable/Post/QueryIntegration.php b/includes/classes/Indexable/Post/QueryIntegration.php index 89081e802..06d78c978 100644 --- a/includes/classes/Indexable/Post/QueryIntegration.php +++ b/includes/classes/Indexable/Post/QueryIntegration.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Post; -use \WP_Query; +use WP_Query; use ElasticPress\Indexables; use ElasticPress\Utils; @@ -189,7 +189,6 @@ public function maybe_switch_to_blog( $post, $query = null ) { $this->switched = false; } } - } /** @@ -588,7 +587,7 @@ protected function maybe_sanitize_suggestion( $ep_query ) { $suggestion['options'] = array_filter( $suggestion['options'], - function( $option ) use ( $min_score ) { + function ( $option ) use ( $min_score ) { return number_format( $option['score'], 10 ) > $min_score; } ); diff --git a/includes/classes/Indexable/Post/SyncManager.php b/includes/classes/Indexable/Post/SyncManager.php index a5feafcaa..f5b1591f4 100644 --- a/includes/classes/Indexable/Post/SyncManager.php +++ b/includes/classes/Indexable/Post/SyncManager.php @@ -224,7 +224,7 @@ public function action_queue_meta_sync( $meta_id, $object_id, $meta_key, $meta_v if ( $query->have_posts() && $query->elasticsearch_success ) { $posts_to_be_synced = array_filter( $query->posts, - function( $object_id ) { + function ( $object_id ) { return ! apply_filters( 'ep_post_sync_kill', false, $object_id, $object_id ); } ); @@ -852,7 +852,7 @@ protected function should_reindex_post( $post_id, $taxonomy ) { * @param \WP_Taxonomy $tax The taxonomy object * @return boolean */ - protected function is_tax_max_count_bigger_than_items_per_cycle( \WP_Taxonomy $tax ) : bool { + protected function is_tax_max_count_bigger_than_items_per_cycle( \WP_Taxonomy $tax ): bool { $transient_name = "ep_term_max_count_{$tax->name}"; $cached_max_count = get_transient( $transient_name ); diff --git a/includes/classes/Indexable/Term/QueryIntegration.php b/includes/classes/Indexable/Term/QueryIntegration.php index 1788bbfdf..8adcf5ad7 100644 --- a/includes/classes/Indexable/Term/QueryIntegration.php +++ b/includes/classes/Indexable/Term/QueryIntegration.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Term; -use \WP_Term_Query; +use WP_Term_Query; use ElasticPress\Indexables; use ElasticPress\Utils; @@ -419,5 +419,4 @@ protected function is_searchable( $query ) { $indexable_taxonomies = Indexables::factory()->get( 'term' )->get_indexable_taxonomies(); return empty( array_diff( $taxonomies, $indexable_taxonomies ) ); } - } diff --git a/includes/classes/Indexable/Term/SyncManager.php b/includes/classes/Indexable/Term/SyncManager.php index bf170f6d8..d5af68c81 100644 --- a/includes/classes/Indexable/Term/SyncManager.php +++ b/includes/classes/Indexable/Term/SyncManager.php @@ -244,5 +244,4 @@ public function action_queue_children_sync( $term_id ) { $this->add_to_queue( $hierarchy_term_id ); } } - } diff --git a/includes/classes/Indexable/Term/Term.php b/includes/classes/Indexable/Term/Term.php index 63eda6059..0f67fa0b1 100644 --- a/includes/classes/Indexable/Term/Term.php +++ b/includes/classes/Indexable/Term/Term.php @@ -8,7 +8,7 @@ namespace ElasticPress\Indexable\Term; -use \WP_Term_Query; +use WP_Term_Query; use ElasticPress\Elasticsearch; use ElasticPress\Indexable; @@ -357,11 +357,9 @@ public function prepare_meta( $term_id ) { if ( true === $allowed_protected_keys || in_array( $key, $allowed_protected_keys, true ) ) { $allow_index = true; } - } else { + } elseif ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { - if ( true !== $excluded_public_keys && ! in_array( $key, $excluded_public_keys, true ) ) { $allow_index = true; - } } /** diff --git a/includes/classes/Indexables.php b/includes/classes/Indexables.php index 4cee9d717..a2011c616 100644 --- a/includes/classes/Indexables.php +++ b/includes/classes/Indexables.php @@ -111,7 +111,7 @@ public function deactivate_all() { * @param string $slug Indexable slug * @return boolean */ - public function is_active( string $slug ) : bool { + public function is_active( string $slug ): bool { return ! empty( $this->active_indexables[ $slug ] ); } @@ -135,13 +135,11 @@ public function get_all( $global = null, $slug_only = false, $status = 'active' } else { $indexables[] = $indexable; } - } else { - if ( $global === $indexable->global ) { - if ( $slug_only ) { - $indexables[] = $slug; - } else { - $indexables[] = $indexable; - } + } elseif ( $global === $indexable->global ) { + if ( $slug_only ) { + $indexables[] = $slug; + } else { + $indexables[] = $indexable; } } } diff --git a/includes/classes/QueryLogger.php b/includes/classes/QueryLogger.php index 11dc0807e..44f90e96b 100644 --- a/includes/classes/QueryLogger.php +++ b/includes/classes/QueryLogger.php @@ -89,7 +89,7 @@ public function log_query( $query, $type ) { * @param bool $should_filter_old Whether it should filter out old entries or not. Default to true, only return entries newer than the limit * @return array */ - public function get_logs( bool $should_filter_old = true ) : array { + public function get_logs( bool $should_filter_old = true ): array { $logs = ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) ? get_site_transient( self::CACHE_KEY, [] ) : get_transient( self::CACHE_KEY, [] ); @@ -214,7 +214,7 @@ public function clear_logs() { * @param array $notices Current EP notices * @return array */ - public function maybe_add_notice( array $notices ) : array { + public function maybe_add_notice( array $notices ): array { if ( ! current_user_can( Utils\get_capability() ) ) { return $notices; } @@ -277,7 +277,7 @@ public function maybe_add_notice( array $notices ) : array { * @param string $type The query type * @return array */ - protected function format_log_entry( array $query, string $type ) : array { + protected function format_log_entry( array $query, string $type ): array { global $wp; $query_time = ( ! empty( $query['time_start'] ) && ! empty( $query['time_finish'] ) ) ? @@ -344,7 +344,7 @@ protected function format_log_entry( array $query, string $type ) : array { * @param string $type The query type * @return boolean */ - protected function should_log_query_type( array $query, string $type ) : bool { + protected function should_log_query_type( array $query, string $type ): bool { /** * Filter the array with a map from query types to callables. If the callable returns true, * the query will be logged. diff --git a/includes/classes/Screen/StatusReport.php b/includes/classes/Screen/StatusReport.php index ea76e0c84..bac313801 100644 --- a/includes/classes/Screen/StatusReport.php +++ b/includes/classes/Screen/StatusReport.php @@ -8,7 +8,7 @@ namespace ElasticPress\Screen; -use \ElasticPress\Utils; +use ElasticPress\Utils; defined( 'ABSPATH' ) || exit; @@ -87,7 +87,7 @@ public function admin_enqueue_scripts() { * * @return array */ - public function get_reports() : array { + public function get_reports(): array { $reports = []; $query_logger = \ElasticPress\get_container()->get( '\ElasticPress\QueryLogger' ); @@ -125,7 +125,7 @@ public function get_reports() : array { $filtered_reports = array_filter( $filtered_reports, - function( $report_slug ) use ( $skipped_reports ) { + function ( $report_slug ) use ( $skipped_reports ) { return ! in_array( $report_slug, $skipped_reports, true ); }, ARRAY_FILTER_USE_KEY @@ -140,12 +140,12 @@ function( $report_slug ) use ( $skipped_reports ) { * @since 4.5.0 * @return array */ - protected function get_formatted_reports() : array { + protected function get_formatted_reports(): array { if ( empty( $this->formatted_reports ) ) { $reports = $this->get_reports(); $this->formatted_reports = array_map( - function( $report ) { + function ( $report ) { return [ 'actions' => $report->get_actions(), 'groups' => $report->get_groups(), @@ -166,7 +166,7 @@ function( $report ) { * @param array $groups Report groups * @return string */ - protected function render_copy_paste_report( string $title, array $groups ) : string { + protected function render_copy_paste_report( string $title, array $groups ): string { $output = "## {$title} ##\n\n"; foreach ( $groups as $group ) { diff --git a/includes/classes/Screen/Sync.php b/includes/classes/Screen/Sync.php index d169e7750..582e1cf61 100644 --- a/includes/classes/Screen/Sync.php +++ b/includes/classes/Screen/Sync.php @@ -77,7 +77,7 @@ public function admin_enqueue_scripts() { 'apiUrl' => rest_url( 'elasticpress/v1/sync' ), 'autoIndex' => Utils\isset_do_sync_parameter() && ( ! defined( 'EP_DASHBOARD_SYNC' ) || EP_DASHBOARD_SYNC ), 'indexMeta' => Utils\get_indexing_status(), - 'indexables' => array_map( fn( $indexable) => [ $indexable->slug, $indexable->labels['plural'] ], $indexables ), + 'indexables' => array_map( fn( $indexable ) => [ $indexable->slug, $indexable->labels['plural'] ], $indexables ), 'isEpio' => Utils\is_epio(), 'nonce' => wp_create_nonce( 'wp_rest' ), 'postTypes' => array_map( fn( $post_type ) => [ $post_type, get_post_type_object( $post_type )->labels->name ], $post_types ), diff --git a/includes/classes/SearchAlgorithm.php b/includes/classes/SearchAlgorithm.php index faa84dc59..1bc7e371d 100644 --- a/includes/classes/SearchAlgorithm.php +++ b/includes/classes/SearchAlgorithm.php @@ -23,21 +23,21 @@ abstract class SearchAlgorithm { * * @return string */ - abstract public function get_slug() : string; + abstract public function get_slug(): string; /** * Return the Search Algorithm human readable name. * * @return string */ - abstract public function get_name() : string; + abstract public function get_name(): string; /** * Return the Search Algorithm description. * * @return string */ - abstract public function get_description() : string; + abstract public function get_description(): string; /** * Return the Elasticsearch `query` clause. @@ -48,7 +48,7 @@ abstract public function get_description() : string; * @param array $query_vars Query vars * @return array ES `query` */ - abstract protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array; + abstract protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ): array; /** * Wrapper for the `get_raw_query`, making sure the `ep_{$indexable_slug}_formatted_args_query` filter is applied. @@ -59,7 +59,7 @@ abstract protected function get_raw_query( string $indexable_slug, string $searc * @param array $query_vars Query vars * @return array ES `query` */ - public function get_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array { + public function get_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ): array { $query = $this->get_raw_query( $indexable_slug, $search_term, $search_fields, $query_vars ); /** diff --git a/includes/classes/SearchAlgorithm/DefaultAlgorithm.php b/includes/classes/SearchAlgorithm/DefaultAlgorithm.php index 83d1daee6..4aed46a3f 100644 --- a/includes/classes/SearchAlgorithm/DefaultAlgorithm.php +++ b/includes/classes/SearchAlgorithm/DefaultAlgorithm.php @@ -23,7 +23,7 @@ class DefaultAlgorithm extends \ElasticPress\SearchAlgorithm { * * @return string */ - public function get_slug() : string { + public function get_slug(): string { return 'default'; } @@ -32,7 +32,7 @@ public function get_slug() : string { * * @return string */ - public function get_name() : string { + public function get_name(): string { return esc_html__( 'Default', 'elasticpress' ); } @@ -41,7 +41,7 @@ public function get_name() : string { * * @return string */ - public function get_description() : string { + public function get_description(): string { return esc_html__( 'Use a fuzzy match approach which includes results that have misspellings, and also includes matches on only some of the words in the search.', 'elasticpress' ); } @@ -54,7 +54,7 @@ public function get_description() : string { * @param array $query_vars Query vars * @return array ES `query` */ - protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array { + protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ): array { $query = [ 'bool' => [ 'should' => [ @@ -130,7 +130,7 @@ protected function get_raw_query( string $indexable_slug, string $search_term, a * @param array $query_vars Query vars * @return array ES `query` */ - protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ) : array { + protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ): array { if ( 'post' !== $indexable_slug ) { return $query; } diff --git a/includes/classes/SearchAlgorithm/Version_350.php b/includes/classes/SearchAlgorithm/Version_350.php index 37b7c12a4..034dd8646 100644 --- a/includes/classes/SearchAlgorithm/Version_350.php +++ b/includes/classes/SearchAlgorithm/Version_350.php @@ -23,7 +23,7 @@ class Version_350 extends \ElasticPress\SearchAlgorithm { * * @return string */ - public function get_slug() : string { + public function get_slug(): string { return '3.5'; } @@ -32,7 +32,7 @@ public function get_slug() : string { * * @return string */ - public function get_name() : string { + public function get_name(): string { return esc_html__( 'Version 3.5', 'elasticpress' ); } @@ -41,7 +41,7 @@ public function get_name() : string { * * @return string */ - public function get_description() : string { + public function get_description(): string { return esc_html__( 'Search for the existence of all words in the search first, then return results based on how closely those words appear.', 'elasticpress' ); } @@ -54,7 +54,7 @@ public function get_description() : string { * @param array $query_vars Query vars * @return array ES `query` */ - protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array { + protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ): array { $query = [ 'bool' => [ 'should' => [ @@ -93,7 +93,7 @@ protected function get_raw_query( string $indexable_slug, string $search_term, a * @param array $query_vars Query vars * @return array ES `query` */ - protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ) : array { + protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ): array { if ( 'post' !== $indexable_slug ) { return $query; } diff --git a/includes/classes/SearchAlgorithm/Version_400.php b/includes/classes/SearchAlgorithm/Version_400.php index d39ba791a..d06d78b13 100644 --- a/includes/classes/SearchAlgorithm/Version_400.php +++ b/includes/classes/SearchAlgorithm/Version_400.php @@ -23,7 +23,7 @@ class Version_400 extends \ElasticPress\SearchAlgorithm { * * @return string */ - public function get_slug() : string { + public function get_slug(): string { return '4.0'; } @@ -32,7 +32,7 @@ public function get_slug() : string { * * @return string */ - public function get_name() : string { + public function get_name(): string { return esc_html__( 'Version 4.0', 'elasticpress' ); } @@ -41,7 +41,7 @@ public function get_name() : string { * * @return string */ - public function get_description() : string { + public function get_description(): string { return esc_html__( 'Search for all search terms in one field first, then prioritize them over search terms matched in different fields.', 'elasticpress' ); } @@ -54,7 +54,7 @@ public function get_description() : string { * @param array $query_vars Query vars * @return array ES `query` */ - protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ) : array { + protected function get_raw_query( string $indexable_slug, string $search_term, array $search_fields, array $query_vars ): array { $query = [ 'bool' => [ 'should' => [ @@ -126,7 +126,7 @@ protected function get_raw_query( string $indexable_slug, string $search_term, a * @param array $query_vars Query vars * @return array ES `query` */ - protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ) : array { + protected function apply_legacy_filters( array $query, string $indexable_slug, array $search_fields, array $query_vars ): array { if ( 'post' !== $indexable_slug ) { return $query; } diff --git a/includes/classes/StatusReport/ElasticPress.php b/includes/classes/StatusReport/ElasticPress.php index 824666b06..8a2ea58b3 100644 --- a/includes/classes/StatusReport/ElasticPress.php +++ b/includes/classes/StatusReport/ElasticPress.php @@ -24,7 +24,7 @@ class ElasticPress extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'ElasticPress', 'elasticpress' ); } @@ -33,7 +33,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { return [ $this->get_basic_settings(), $this->get_timeouts(), @@ -45,7 +45,7 @@ public function get_groups() : array { * * @return array */ - protected function get_basic_settings() : array { + protected function get_basic_settings(): array { $is_epio = Utils\is_epio(); $fields = []; diff --git a/includes/classes/StatusReport/ElasticPressIo.php b/includes/classes/StatusReport/ElasticPressIo.php index d68aa1b83..b283f189d 100644 --- a/includes/classes/StatusReport/ElasticPressIo.php +++ b/includes/classes/StatusReport/ElasticPressIo.php @@ -26,7 +26,7 @@ class ElasticPressIo extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'ElasticPress.io', 'elasticpress' ); } @@ -35,7 +35,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { $groups = [ $this->get_autosuggest_group(), $this->get_instant_results_group(), @@ -50,7 +50,7 @@ public function get_groups() : array { * * @return array */ - protected function get_autosuggest_group() : array { + protected function get_autosuggest_group(): array { $autosuggest_feature = \ElasticPress\Features::factory()->get_registered_feature( 'autosuggest' ); if ( ! $autosuggest_feature->is_active() ) { @@ -109,7 +109,7 @@ protected function get_autosuggest_group() : array { * * @return array */ - protected function get_instant_results_group() : array { + protected function get_instant_results_group(): array { $instant_results_feature = \ElasticPress\Features::factory()->get_registered_feature( 'instant-results' ); if ( ! $instant_results_feature->is_active() ) { @@ -146,7 +146,7 @@ protected function get_instant_results_group() : array { * @since 4.5.0 * @return array */ - protected function get_orders_search_group() : array { + protected function get_orders_search_group(): array { $woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' ); if ( ! $woocommerce_feature->is_active() ) { @@ -186,7 +186,7 @@ protected function get_orders_search_group() : array { * * @return array */ - protected function get_instant_results_field() : array { + protected function get_instant_results_field(): array { $index = Indexables::factory()->get( 'post' )->get_index_name(); if ( ! $index ) { @@ -219,7 +219,7 @@ protected function get_instant_results_field() : array { * @return array * @since 4.5.0 */ - public function get_messages() : array { + public function get_messages(): array { $messages = \ElasticPress\ElasticPressIo::factory()->get_endpoint_messages( true ); $messages = array_values( $messages ); @@ -232,7 +232,7 @@ public function get_messages() : array { * @since 4.5.0 * @return array */ - protected function get_orders_search_field() : array { + protected function get_orders_search_field(): array { $index = Indexables::factory()->get( 'post' )->get_index_name(); if ( ! $index ) { diff --git a/includes/classes/StatusReport/FailedQueries.php b/includes/classes/StatusReport/FailedQueries.php index fc90fc2b1..791f214c8 100644 --- a/includes/classes/StatusReport/FailedQueries.php +++ b/includes/classes/StatusReport/FailedQueries.php @@ -8,8 +8,8 @@ namespace ElasticPress\StatusReport; -use \ElasticPress\QueryLogger; -use \ElasticPress\Utils; +use ElasticPress\QueryLogger; +use ElasticPress\Utils; defined( 'ABSPATH' ) || exit; @@ -41,7 +41,7 @@ public function __construct( QueryLogger $query_logger ) { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'Failed Queries', 'elasticpress' ); } @@ -50,7 +50,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { $this->maybe_clear_logs(); $logs = $this->query_logger->get_logs( false ); @@ -108,7 +108,7 @@ public function get_groups() : array { * * @return string */ - public function get_actions() : array { + public function get_actions(): array { global $wp; $logs = $this->query_logger->get_logs( false ); diff --git a/includes/classes/StatusReport/Features.php b/includes/classes/StatusReport/Features.php index 99953670a..a80cd059a 100644 --- a/includes/classes/StatusReport/Features.php +++ b/includes/classes/StatusReport/Features.php @@ -8,8 +8,8 @@ namespace ElasticPress\StatusReport; -use \ElasticPress\Features as EP_Features; -use \ElasticPress\Feature\Search\Search; +use ElasticPress\Features as EP_Features; +use ElasticPress\Feature\Search\Search; defined( 'ABSPATH' ) || exit; @@ -25,7 +25,7 @@ class Features extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'Feature Settings', 'elasticpress' ); } @@ -34,12 +34,12 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { $features_settings = \ElasticPress\Utils\get_option( 'ep_feature_settings', [] ); $features = array_filter( EP_Features::factory()->registered_features, - function( $feature ) { + function ( $feature ) { return $feature->is_active(); } ); @@ -79,7 +79,7 @@ function( $feature ) { * @param Search $feature Feature object * @return array New fields */ - protected function get_search_extra_fields( array $fields, Search $feature ) : array { + protected function get_search_extra_fields( array $fields, Search $feature ): array { if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { return $fields; } diff --git a/includes/classes/StatusReport/IndexableContent.php b/includes/classes/StatusReport/IndexableContent.php index afd943438..2c4ecc9dd 100644 --- a/includes/classes/StatusReport/IndexableContent.php +++ b/includes/classes/StatusReport/IndexableContent.php @@ -24,7 +24,7 @@ class IndexableContent extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'Indexable Content', 'elasticpress' ); } @@ -33,7 +33,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { return $this->get_indexable_content_groups(); } @@ -42,7 +42,7 @@ public function get_groups() : array { * * @return array */ - protected function get_indexable_content_groups() : array { + protected function get_indexable_content_groups(): array { $groups = []; if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { @@ -66,7 +66,7 @@ protected function get_indexable_content_groups() : array { * * @return array */ - protected function get_indexable_content_group() : array { + protected function get_indexable_content_group(): array { $post_counts = $this->get_post_count_group(); $meta_counts = $this->get_post_meta_fields(); @@ -88,7 +88,7 @@ protected function get_indexable_content_group() : array { * * @return array */ - protected function get_post_count_group() : array { + protected function get_post_count_group(): array { $post_indexable = \ElasticPress\Indexables::factory()->get( 'post' ); $post_types = $post_indexable->get_indexable_post_types(); @@ -126,7 +126,7 @@ function ( $count, $post_status ) use ( $post_count, $post_stati ) { * * @return array */ - protected function get_post_meta_fields() : array { + protected function get_post_meta_fields(): array { $post_indexable = \ElasticPress\Indexables::factory()->get( 'post' ); $post_types = $post_indexable->get_indexable_post_types(); diff --git a/includes/classes/StatusReport/Indices.php b/includes/classes/StatusReport/Indices.php index 280bb056d..689d36f85 100644 --- a/includes/classes/StatusReport/Indices.php +++ b/includes/classes/StatusReport/Indices.php @@ -22,7 +22,7 @@ class Indices extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'Elasticsearch Indices', 'elasticpress' ); } @@ -31,7 +31,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { $elasticsearch = \ElasticPress\Elasticsearch::factory(); $should_have_indices = $elasticsearch->get_index_names(); diff --git a/includes/classes/StatusReport/LastSync.php b/includes/classes/StatusReport/LastSync.php index 53f7e99dc..c9e808829 100644 --- a/includes/classes/StatusReport/LastSync.php +++ b/includes/classes/StatusReport/LastSync.php @@ -22,7 +22,7 @@ class LastSync extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'Last Sync', 'elasticpress' ); } @@ -31,7 +31,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { $fields = []; $sync_info = \ElasticPress\IndexHelper::factory()->get_last_sync(); diff --git a/includes/classes/StatusReport/Report.php b/includes/classes/StatusReport/Report.php index 2d7507835..358fa6695 100644 --- a/includes/classes/StatusReport/Report.php +++ b/includes/classes/StatusReport/Report.php @@ -22,21 +22,21 @@ abstract class Report { * * @return string */ - abstract public function get_title() : string; + abstract public function get_title(): string; /** * Return the report group(s) of fields * * @return array */ - abstract public function get_groups() : array; + abstract public function get_groups(): array; /** * Return any actions related to the report, like a button * * @return string */ - public function get_actions() : array { + public function get_actions(): array { return []; } @@ -46,7 +46,7 @@ public function get_actions() : array { * @return array * @since 4.5.0 */ - public function get_messages() : array { + public function get_messages(): array { return []; } } diff --git a/includes/classes/StatusReport/WordPress.php b/includes/classes/StatusReport/WordPress.php index 443f075b1..da847c801 100644 --- a/includes/classes/StatusReport/WordPress.php +++ b/includes/classes/StatusReport/WordPress.php @@ -22,7 +22,7 @@ class WordPress extends Report { * * @return string */ - public function get_title() : string { + public function get_title(): string { return __( 'WordPress', 'elasticpress' ); } @@ -31,7 +31,7 @@ public function get_title() : string { * * @return array */ - public function get_groups() : array { + public function get_groups(): array { return [ $this->get_wp_basic_group(), $this->get_server_group(), @@ -43,7 +43,7 @@ public function get_groups() : array { * * @return array */ - protected function get_wp_basic_group() : array { + protected function get_wp_basic_group(): array { global $wp_version; $fields = []; @@ -118,7 +118,7 @@ protected function get_wp_basic_group() : array { * * @return array */ - protected function get_server_group() : array { + protected function get_server_group(): array { $fields = []; $fields['php_version'] = [ diff --git a/includes/dashboard.php b/includes/dashboard.php index 6288d52fb..f43cf1f99 100644 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -303,10 +303,8 @@ function maybe_notice( $force = false ) { if ( ! is_super_admin() || ! is_network_admin() ) { return false; } - } else { - if ( is_network_admin() || ! current_user_can( Utils\get_capability() ) ) { + } elseif ( is_network_admin() || ! current_user_can( Utils\get_capability() ) ) { return false; - } } /** @@ -691,7 +689,7 @@ function action_admin_menu() { * @param string $format Format of the return ('locales' or 'elasticsearch' ) * @return array */ -function get_available_languages( string $format = 'elasticsearch' ) : array { +function get_available_languages( string $format = 'elasticsearch' ): array { /** * Filter available languages in Elasticsearch. * @@ -973,7 +971,7 @@ function block_categories( $block_categories ) { ]; return $block_categories; -}; +} /** * Enqueue shared block editor assets. diff --git a/includes/utils.php b/includes/utils.php index e066f143a..b8d408d16 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -58,7 +58,7 @@ function get_epio_credentials() { * @param string $context Context for the capability. Defaults to empty string. * @return string */ -function get_capability( string $context = '' ) : string { +function get_capability( string $context = '' ): string { /** * Filter the WP capability needed to interact with ElasticPress in the admin * @@ -92,7 +92,7 @@ function get_capability( string $context = '' ) : string { * @param string $context Context for the capability. Defaults to empty string. * @return string */ -function get_network_capability( string $context = '' ) : string { +function get_network_capability( string $context = '' ): string { /** * Filter the WP capability needed to interact with ElasticPress in the network admin * @@ -112,7 +112,7 @@ function get_network_capability( string $context = '' ) : string { * @param string $context Context for the capability. Defaults to empty string. * @return array */ -function get_post_map_capabilities( string $context = '' ) : array { +function get_post_map_capabilities( string $context = '' ): array { $capability = get_capability( $context ); return [ @@ -437,7 +437,7 @@ function get_term_tree( $all_terms, $orderby = 'count', $order = 'desc', $flat = } foreach ( $all_terms as $key => $term ) { - $iteration_id++; + ++$iteration_id; if ( ! isset( $term->children ) ) { $term->children = []; @@ -464,16 +464,15 @@ function get_term_tree( $all_terms, $orderby = 'count', $order = 'desc', $flat = } unset( $all_terms[ $key ] ); - } else { - if ( ! empty( $terms_map[ $term->parent ] ) && isset( $terms_map[ $term->parent ]->level ) ) { + } elseif ( ! empty( $terms_map[ $term->parent ] ) && isset( $terms_map[ $term->parent ]->level ) ) { - if ( empty( $orderby ) ) { - $terms_map[ $term->parent ]->children[] = $term; - } elseif ( 'count' === $orderby ) { - $terms_map[ $term->parent ]->children[ ( ( $term->count * 10000000 ) + $iteration_id ) ] = $term; - } elseif ( 'name' === $orderby ) { - $terms_map[ $term->parent ]->children[ $term->name ] = $term; - } + if ( empty( $orderby ) ) { + $terms_map[ $term->parent ]->children[] = $term; + } elseif ( 'count' === $orderby ) { + $terms_map[ $term->parent ]->children[ ( ( $term->count * 10000000 ) + $iteration_id ) ] = $term; + } elseif ( 'name' === $orderby ) { + $terms_map[ $term->parent ]->children[ $term->name ] = $term; + } $parent_level = ( $terms_map[ $term->parent ]->level ) ? $terms_map[ $term->parent ]->level : 0; @@ -481,7 +480,6 @@ function get_term_tree( $all_terms, $orderby = 'count', $order = 'desc', $flat = $term->parent_term = $terms_map[ $term->parent ]; unset( $all_terms[ $key ] ); - } } } } @@ -596,7 +594,6 @@ function get_indexing_status() { } return $index_status; - } /** @@ -770,7 +767,7 @@ function get_asset_info( $slug, $attribute = null ) { * @param boolean|string $do_sync Whether the link should or should not start a resync. Pass a string to store the reason of the resync. * @return string */ -function get_sync_url( $do_sync = false ) : string { +function get_sync_url( $do_sync = false ): string { $page = 'admin.php?page=elasticpress-sync'; if ( $do_sync ) { $page .= '&do_sync'; @@ -790,7 +787,7 @@ function get_sync_url( $do_sync = false ) : string { * @since 5.1.2 * @return boolean */ -function isset_do_sync_parameter() : bool { +function isset_do_sync_parameter(): bool { return isset( $_GET['do_sync'] ) && ! empty( $_GET['ep_sync_nonce'] ) && wp_verify_nonce( sanitize_key( $_GET['ep_sync_nonce'] ), 'ep_sync_nonce' ); } @@ -822,7 +819,7 @@ function get_request_id_base() { * @since 4.5.0 * @return string */ -function generate_request_id() : string { +function generate_request_id(): string { $uuid = str_replace( '-', '', wp_generate_uuid4() ); /** @@ -843,7 +840,7 @@ function generate_request_id() : string { * @param mixed $response The Elasticsearch response * @return string */ -function get_elasticsearch_error_reason( $response ) : string { +function get_elasticsearch_error_reason( $response ): string { if ( is_string( $response ) ) { return $response; } diff --git a/tests/cypress/wordpress-files/test-mu-plugins/disable-welcome-guide.php b/tests/cypress/wordpress-files/test-mu-plugins/disable-welcome-guide.php index e8c6d49c6..b9c6d0b64 100644 --- a/tests/cypress/wordpress-files/test-mu-plugins/disable-welcome-guide.php +++ b/tests/cypress/wordpress-files/test-mu-plugins/disable-welcome-guide.php @@ -11,7 +11,7 @@ add_action( 'enqueue_block_editor_assets', - function() { + function () { wp_add_inline_script( 'wp-data', "window.onload = function() { @@ -21,4 +21,3 @@ function() { }, 999 ); - diff --git a/tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php b/tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php index 9dbe6b036..2b3555a2a 100644 --- a/tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php +++ b/tests/cypress/wordpress-files/test-mu-plugins/unique-index-name.php @@ -7,7 +7,7 @@ add_filter( 'ep_index_name', - function( $index_name ) { + function ( $index_name ) { $docker_cid = get_docker_cid(); if ( $docker_cid ) { @@ -20,7 +20,7 @@ function( $index_name ) { add_action( 'admin_footer', - function() { + function () { printf( '
Completely custom made element
' : $html; }; add_filter( 'ep_facet_meta_value_html', $change_html, 10, 3 ); diff --git a/tests/php/features/TestFacetTypePostType.php b/tests/php/features/TestFacetTypePostType.php index 560961f46..a28dfa5b0 100644 --- a/tests/php/features/TestFacetTypePostType.php +++ b/tests/php/features/TestFacetTypePostType.php @@ -45,7 +45,7 @@ public function testGetFilterName() { /** * Test the `ep_facet_post_type_filter_name` filter */ - $change_filter_name = function( $filter_name ) { + $change_filter_name = function ( $filter_name ) { return $filter_name . '_'; }; add_filter( 'ep_facet_post_type_filter_name', $change_filter_name ); @@ -66,7 +66,7 @@ public function testGetFilterType() { /** * Test the `ep_facet_post_type_filter_type` filter */ - $change_filter_type = function( $filter_type ) { + $change_filter_type = function ( $filter_type ) { return $filter_type . '_'; }; add_filter( 'ep_facet_post_type_filter_type', $change_filter_type ); @@ -142,7 +142,7 @@ public function testGetFacetablePostTypes() { /** * Test the `ep_facetable_post_types` filter */ - $change_filter_type = function( $post_types ) { + $change_filter_type = function ( $post_types ) { $post_types['test'] = 'test'; return $post_types; }; diff --git a/tests/php/features/TestFacetTypePostTypeRenderer.php b/tests/php/features/TestFacetTypePostTypeRenderer.php index 9a30f79b1..90b1a4278 100644 --- a/tests/php/features/TestFacetTypePostTypeRenderer.php +++ b/tests/php/features/TestFacetTypePostTypeRenderer.php @@ -8,7 +8,7 @@ namespace ElasticPressTest; -use \ElasticPress\Feature\Facets\Types\PostType\Renderer; +use ElasticPress\Feature\Facets\Types\PostType\Renderer; /** * Facets\Types\PostType\FacetType test class */ @@ -65,7 +65,7 @@ public function testGetPostTypeValueHtml() { /** * Test the `ep_facet_post_type_value_label` filter */ - $change_label = function( $label, $value ) { + $change_label = function ( $label, $value ) { return ( 'page' === $value['value'] ) ? 'Different Label' : $label; }; add_filter( 'ep_facet_post_type_value_label', $change_label, 10, 2 ); @@ -81,7 +81,7 @@ public function testGetPostTypeValueHtml() { /** * Test the `ep_facet_post_type_value_accessible_label` filter */ - $change_accessible_label = function( $label, $value ) { + $change_accessible_label = function ( $label, $value ) { return ( 'page' === $value['value'] ) ? 'Apply filter!' : $label; }; add_filter( 'ep_facet_post_type_value_accessible_label', $change_accessible_label, 10, 2 ); @@ -97,7 +97,7 @@ public function testGetPostTypeValueHtml() { /** * Test the `ep_facet_post_type_value_html` filter */ - $change_html = function( $html, $value, $url ) { + $change_html = function ( $html, $value, $url ) { return ( 'https://example.com' === $url ) ? 'Completely custom made element
' : $html; }; add_filter( 'ep_facet_post_type_value_html', $change_html, 10, 3 ); diff --git a/tests/php/features/TestFacetTypeTaxonomy.php b/tests/php/features/TestFacetTypeTaxonomy.php index 352c3044f..e7a626d90 100644 --- a/tests/php/features/TestFacetTypeTaxonomy.php +++ b/tests/php/features/TestFacetTypeTaxonomy.php @@ -32,7 +32,7 @@ public function testGetFilterName() { /** * Test the `ep_facet_filter_name` filter */ - $change_filter_name = function( $filter_name ) { + $change_filter_name = function ( $filter_name ) { return $filter_name . '_'; }; add_filter( 'ep_facet_filter_name', $change_filter_name ); @@ -57,7 +57,7 @@ public function testGetFilterType() { /** * Test the `ep_facet_filter_type` filter */ - $change_filter_type = function( $filter_type ) { + $change_filter_type = function ( $filter_type ) { return $filter_type . '_'; }; add_filter( 'ep_facet_filter_type', $change_filter_type ); @@ -94,7 +94,7 @@ public function testGetFacetableTaxonomies() { /** * Test the `ep_facet_include_taxonomies` filter */ - $change_facetable_taxonomies = function( $taxonomies ) { + $change_facetable_taxonomies = function ( $taxonomies ) { unset( $taxonomies['category'] ); return $taxonomies; }; @@ -130,7 +130,7 @@ public function testSetWpQueryAggs() { /** * Test the `ep_facet_use_field` filter */ - $change_cat_facet_field = function( $field, $taxonomy ) { + $change_cat_facet_field = function ( $field, $taxonomy ) { return ( 'category' === $taxonomy->name ) ? 'term_id' : $field; }; @@ -145,7 +145,7 @@ public function testSetWpQueryAggs() { /** * Test the `ep_facet_taxonomies_size` filter */ - $change_tax_bucket_size = function( $size, $taxonomy ) { + $change_tax_bucket_size = function ( $size, $taxonomy ) { return ( 'category' === $taxonomy->name ) ? 5 : $size; }; @@ -219,7 +219,7 @@ public function testGetSanitizeCallback() { $expected_result = sanitize_title( $test_taxonomy ); $this->assertArrayHasKey( $expected_result, $selected['taxonomies']['taxonomy']['terms'] ); - $sanitize_function = function( $function ) { + $sanitize_function = function ( $function ) { $this->assertSame( 'sanitize_title', $function ); @@ -332,7 +332,7 @@ public function testAddQueryParams() { public function test_ep_facet_special_slug_taxonomies_filter() { add_filter( 'ep_facet_tax_special_slug_taxonomies', - function( $special_slug_taxonomies ) { + function ( $special_slug_taxonomies ) { $special_slug_taxonomies['testmyfilter'] = 'testmyfilterchangedfilter'; return $special_slug_taxonomies; }, diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index 00557aedb..3c96f279b 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -474,7 +474,7 @@ public function test_maybe_change_sort() { $this->assertEquals( 2, $query->found_posts ); $this->assertEquals( $exact_match_id, $query->posts[0]->ID ); - $filter = function( $value ) { + $filter = function ( $value ) { $value['protected_content']['use_default_wp_sort'] = '1'; return $value; }; diff --git a/tests/php/features/TestSearch.php b/tests/php/features/TestSearch.php index 3446e8cda..421ad5073 100644 --- a/tests/php/features/TestSearch.php +++ b/tests/php/features/TestSearch.php @@ -160,7 +160,6 @@ public function testDecayingEnabled() { $this->assertTrue( ElasticPress\Features::factory()->get_registered_feature( 'search' )->is_decaying_enabled() ); add_filter( 'ep_is_decaying_enabled', '__return_false' ); $this->assertFalse( ElasticPress\Features::factory()->get_registered_feature( 'search' )->is_decaying_enabled() ); - } /** diff --git a/tests/php/features/TestSearchOrdering.php b/tests/php/features/TestSearchOrdering.php index 4df831e03..2f2554672 100644 --- a/tests/php/features/TestSearchOrdering.php +++ b/tests/php/features/TestSearchOrdering.php @@ -265,7 +265,6 @@ public function testSavePostEarlyReturn() { $return = $this->get_feature()->save_post( $pointer_id, get_post( $pointer_id ) ); $this->assertNull( $return ); - } /** @@ -436,7 +435,7 @@ public function testSavePostMaxCustomResults() { * Test the `create_or_return_custom_result_term` method */ public function testCreateTermFailed() { - $create_term_failed = function() { + $create_term_failed = function () { return new \WP_Error( 'test_error' ); }; diff --git a/tests/php/features/TestWeighting.php b/tests/php/features/TestWeighting.php index d4aefb6b5..de811d785 100644 --- a/tests/php/features/TestWeighting.php +++ b/tests/php/features/TestWeighting.php @@ -8,7 +8,7 @@ namespace ElasticPressTest; use ElasticPress; -use \ElasticPress\Utils; +use ElasticPress\Utils; /** * Weighting test class @@ -177,7 +177,6 @@ public function test_weighting_configuration() { $weighting_configuration = $this->save_weighting_configuration( $weighting_settings ); $this->assertEquals( false, $weighting_configuration['post']['post_title']['enabled'] ); - } /** @@ -292,14 +291,14 @@ function () { add_filter( 'ep_searchable_post_types', - function( $config ) { + function ( $config ) { return array_merge( $config, [ 'invalid_post_type' ] ); } ); add_filter( 'ep_weighting_configuration', - function( $config ) { + function ( $config ) { return array_merge( $config, [ 'invalid_post_type' ] ); } ); @@ -350,7 +349,7 @@ public function testPostTypeHasFieldsWithCustomConfig() { * @since 4.1.0 */ public function testPostTypeHasFieldsWithCustomConfigViaFilter() { - $function = function() { + $function = function () { return [ 'page' => [], 'post' => [ @@ -411,7 +410,7 @@ public function testDoWeightingWithEmptySearchQuery() { * Test the `do_weighting` method (with the default config) */ public function testDoWeightingWithDefaultConfig() { - $new_formatted_args = $this->get_weighting_feature()->do_weighting( ... $this->getArgs() ); + $new_formatted_args = $this->get_weighting_feature()->do_weighting( ...$this->getArgs() ); // We have 5 searchable post types. $this->assertEquals( 5, count( $new_formatted_args['query']['function_score']['query']['bool']['should'] ) ); @@ -470,21 +469,21 @@ public function getArgs() { public function testApplyFilterWhenWeightingConfigWasNotSaved() { delete_option( 'elasticpress_weighting' ); - $add_post_content_filter = function( $weight_config ) { + $add_post_content_filter = function ( $weight_config ) { $weight_config['new_cpt']['post_content_filtered'] = [ 'enabled' => true, 'weight' => 40, ]; return $weight_config; }; - $set_query_post_type = function() { + $set_query_post_type = function () { return 'new_cpt'; }; add_filter( 'ep_weighting_configuration_for_search', $add_post_content_filter ); add_filter( 'ep_query_post_type', $set_query_post_type ); - $new_formatted_args = $this->get_weighting_feature()->do_weighting( ... $this->getArgs() ); + $new_formatted_args = $this->get_weighting_feature()->do_weighting( ...$this->getArgs() ); $query_multi_match = $new_formatted_args['query']['function_score']['query'] ['bool']['should'][0]['bool']['must'][0] diff --git a/tests/php/features/WooCommerce/TestWooCommerce.php b/tests/php/features/WooCommerce/TestWooCommerce.php index 05e8d7aa6..ede24d103 100644 --- a/tests/php/features/WooCommerce/TestWooCommerce.php +++ b/tests/php/features/WooCommerce/TestWooCommerce.php @@ -191,7 +191,7 @@ public function testIsOrdersAutosuggestEnabled() { /** * Enable it */ - $filter = function() { + $filter = function () { return [ 'woocommerce' => [ 'orders' => '1', diff --git a/tests/php/features/WooCommerce/TestWooCommerceOrders.php b/tests/php/features/WooCommerce/TestWooCommerceOrders.php index 2f5a3257c..44608146f 100644 --- a/tests/php/features/WooCommerce/TestWooCommerceOrders.php +++ b/tests/php/features/WooCommerce/TestWooCommerceOrders.php @@ -277,7 +277,7 @@ public function testGetSupportedPostTypes() { /** * Test the `ep_woocommerce_orders_supported_post_types` filter */ - $add_post_type = function( $post_types ) { + $add_post_type = function ( $post_types ) { $post_types[] = 'shop_order_custom'; return $post_types; }; @@ -306,7 +306,7 @@ public function testOrdersAutosuggestMethods( $method, $args ) { * * @return array */ - public function ordersAutosuggestMethodsDataProvider() : array { + public function ordersAutosuggestMethodsDataProvider(): array { return [ [ 'after_update_feature', [ 'test', [], [] ] ], [ 'enqueue_admin_assets', [ '' ] ], @@ -349,7 +349,7 @@ public function test_hpos_compatibility_notice() { $this->assertCount( 1, $this->orders->hpos_compatibility_notice( $notices ) ); $option_name = \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION; - $change_value = function() { + $change_value = function () { return 'yes'; }; add_filter( 'pre_option_' . $option_name, $change_value ); @@ -361,7 +361,7 @@ public function test_hpos_compatibility_notice() { /** * Test if the notice is hidden when the user already dismissed it */ - $change_hide_option = function() { + $change_hide_option = function () { return 1; }; add_filter( 'pre_option_ep_hide_wc_orders_incompatible_notice', $change_hide_option ); diff --git a/tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php b/tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php index b183c90a0..ca02632d2 100644 --- a/tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php +++ b/tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php @@ -131,7 +131,7 @@ public function testFilterTermSuggestWithCustomOrderId() { /** * Set a custom Order Number */ - $set_custom_order_id = function( $order_id ) { + $set_custom_order_id = function ( $order_id ) { return 'custom-' . $order_id; }; add_filter( 'woocommerce_order_number', $set_custom_order_id ); @@ -200,7 +200,7 @@ public function testMappingEs7() { * @group woocommerce-orders-autosuggest */ public function testMappingEs5() { - $change_es_version = function() { + $change_es_version = function () { return '5.6'; }; add_filter( 'ep_elasticsearch_version', $change_es_version ); @@ -334,7 +334,7 @@ public function test_is_enabled() { /** * Enable it */ - $filter = function() { + $filter = function () { return [ 'woocommerce' => [ 'orders' => '1', @@ -364,14 +364,14 @@ public function test_is_hpos_compatible() { // Turn HPOS on $custom_orders_table = \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION; - $change_custom_orders_table = function() { + $change_custom_orders_table = function () { return 'yes'; }; add_filter( 'pre_option_' . $custom_orders_table, $change_custom_orders_table ); // Disable legacy mode $legacy_mode = \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION; - $change_legacy_mode = function() { + $change_legacy_mode = function () { return 'no'; }; add_filter( 'pre_option_' . $legacy_mode, $change_legacy_mode ); @@ -418,7 +418,7 @@ public function test_get_setting_help_message_feature_available() { public function test_get_setting_help_message_feature_hpos_incompatible() { // Turn HPOS on $custom_orders_table = \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION; - $change_custom_orders_table = function() { + $change_custom_orders_table = function () { return 'yes'; }; add_filter( 'pre_option_' . $custom_orders_table, $change_custom_orders_table ); diff --git a/tests/php/features/WooCommerce/TestWooCommerceProduct.php b/tests/php/features/WooCommerce/TestWooCommerceProduct.php index c3c646b5e..b2c9eb170 100644 --- a/tests/php/features/WooCommerce/TestWooCommerceProduct.php +++ b/tests/php/features/WooCommerce/TestWooCommerceProduct.php @@ -203,7 +203,7 @@ public function testWoocommerceAttributeTaxonomiesAreSync() { * * @return array */ - public function productQueryOrderDataProvider() : array { + public function productQueryOrderDataProvider(): array { return [ [ 'total_sales', @@ -360,7 +360,7 @@ public function testProductQueryOrder( $product_arg_key, $query_args, $query_str // mock the query as post type archive add_action( 'parse_query', - function( \WP_Query $query ) { + function ( \WP_Query $query ) { $query->is_post_type_archive = true; } ); @@ -439,7 +439,7 @@ public function testProductListInAdminUseElasticSearch() { add_filter( 'ep_post_filters', - function( $filters, $args, $query ) { + function ( $filters, $args, $query ) { $expected_result = array( 'terms' => array( 'post_type.raw' => array( @@ -679,7 +679,7 @@ public function testAttributesFilterUseES() { // mock the query as post type archive add_action( 'parse_query', - function( \WP_Query $query ) { + function ( \WP_Query $query ) { $query->is_post_type_archive = true; } ); @@ -701,7 +701,7 @@ function( \WP_Query $query ) { $this->assertEquals( 'Cap', $query_results[0]->post_title ); // Enable the product attributes lookup table for catalog filtering - $enable_attribute_lookup = function() { + $enable_attribute_lookup = function () { return 'yes'; }; add_filter( 'pre_option_woocommerce_attribute_lookup_enabled', $enable_attribute_lookup ); @@ -934,7 +934,7 @@ public function testDecayingDisabledOnProducts( $setting, $post_type, $assert ) * * @return array */ - public function decayingDisabledOnProductsProvider() : array { + public function decayingDisabledOnProductsProvider(): array { return [ [ 'disabled_only_products', @@ -996,7 +996,7 @@ public function testGetSupportedPostTypes() { /** * Test the `ep_woocommerce_products_supported_post_types` filter */ - $add_post_type = function( $post_types, $filter_query ) use ( $query ) { + $add_post_type = function ( $post_types, $filter_query ) use ( $query ) { $this->assertSame( $filter_query, $query ); $post_types[] = 'post'; return $post_types; @@ -1029,7 +1029,7 @@ public function testGetSupportedTaxonomies() { /** * Test the `ep_woocommerce_products_supported_taxonomies` filter */ - $add_taxonomy = function( $taxonomies ) { + $add_taxonomy = function ( $taxonomies ) { $taxonomies[] = 'custom_category'; return $taxonomies; }; diff --git a/tests/php/includes/classes/factory/CommentFactory.php b/tests/php/includes/classes/factory/CommentFactory.php index 16c3d0d15..0d5a9fbe7 100644 --- a/tests/php/includes/classes/factory/CommentFactory.php +++ b/tests/php/includes/classes/factory/CommentFactory.php @@ -30,5 +30,4 @@ public function create_object( $args ) { return $id; } - } diff --git a/tests/php/includes/classes/factory/PostFactory.php b/tests/php/includes/classes/factory/PostFactory.php index d202baa7e..c9097ed56 100644 --- a/tests/php/includes/classes/factory/PostFactory.php +++ b/tests/php/includes/classes/factory/PostFactory.php @@ -34,5 +34,4 @@ public function create_object( $args ) { ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id ); return $post_id; } - } diff --git a/tests/php/includes/classes/factory/TermFactory.php b/tests/php/includes/classes/factory/TermFactory.php index 0f80d5091..ba97ecf76 100644 --- a/tests/php/includes/classes/factory/TermFactory.php +++ b/tests/php/includes/classes/factory/TermFactory.php @@ -34,5 +34,4 @@ public function create_object( $args ) { return $term_id; } - } diff --git a/tests/php/includes/classes/mock/Global/Feature.php b/tests/php/includes/classes/mock/Global/Feature.php index 2125e1b13..6b369cfd5 100644 --- a/tests/php/includes/classes/mock/Global/Feature.php +++ b/tests/php/includes/classes/mock/Global/Feature.php @@ -8,7 +8,7 @@ namespace ElasticPressTest\GlobalIndexable; -use \ElasticPress\Indexables; +use ElasticPress\Indexables; require_once __DIR__ . '/Indexable.php'; @@ -52,4 +52,3 @@ public function requirements_status() { \ElasticPress\Features::factory()->register_feature( new GlobalFeature() ); - diff --git a/tests/php/includes/classes/mock/class-wp-cli.php b/tests/php/includes/classes/mock/class-wp-cli.php index c8cde61f9..6ab0f2aa7 100644 --- a/tests/php/includes/classes/mock/class-wp-cli.php +++ b/tests/php/includes/classes/mock/class-wp-cli.php @@ -121,5 +121,4 @@ public static function get_runner() { $runner->assoc_args = []; return $runner; } - } diff --git a/tests/php/includes/functions.php b/tests/php/includes/functions.php index 9f571eccb..151c1ae06 100644 --- a/tests/php/includes/functions.php +++ b/tests/php/includes/functions.php @@ -22,7 +22,7 @@ function count_indexes() { $count_indexes = 0; foreach ( $sites as $site ) { if ( ElasticPress\Indexables::factory()->get( 'post' )->index_exists( $site['blog_id'] ) ) { - $count_indexes++; + ++$count_indexes; $last_blog_id_with_index = $site['blog_id']; } } diff --git a/tests/php/indexables/TestComment.php b/tests/php/indexables/TestComment.php index d4f5afaf0..93efdf23b 100644 --- a/tests/php/indexables/TestComment.php +++ b/tests/php/indexables/TestComment.php @@ -133,7 +133,7 @@ public function createComments( $number = 4, $has_child = false ) { public function testCommentSync() { add_action( 'ep_sync_comment_on_transition', - function() { + function () { $this->fired_actions['ep_sync_comment_on_transition'] = true; } ); @@ -229,7 +229,7 @@ public function testCommentSyncKill() { add_filter( 'ep_comment_sync_kill', - function( $kill, $comment_id ) use ( $created_comment_id ) { + function ( $kill, $comment_id ) use ( $created_comment_id ) { if ( $created_comment_id === $comment_id ) { return true; } @@ -279,7 +279,7 @@ public function testBasicCommentQuery() { $this->assertEquals( 3, count( $comments ) ); // Test some of the filters and defaults. - $return_2 = function() { + $return_2 = function () { return 2; }; @@ -606,14 +606,14 @@ public function testCommentQueryHierarchical() { public function testCommentDelete() { add_action( 'ep_sync_comment_on_transition', - function() { + function () { $this->fired_actions['ep_sync_comment_on_transition'] = true; } ); add_action( 'deleted_comment', - function() { + function () { $this->fired_actions['deleted_comment'] = true; } ); @@ -2473,7 +2473,7 @@ public function test_mapping_ep_stop_filter() { $this->assertContains( 'ep_stop', $index_settings['index.analysis.analyzer.default.filter'] ); $this->assertSame( '_english_', $index_settings['index.analysis.filter.ep_stop.stopwords'] ); - $change_lang = function( $lang, $context ) { + $change_lang = function ( $lang, $context ) { return 'filter_ep_stop' === $context ? '_arabic_' : $lang; }; add_filter( 'ep_analyzer_language', $change_lang, 11, 2 ); diff --git a/tests/php/indexables/TestCommentMultisite.php b/tests/php/indexables/TestCommentMultisite.php index d635350f5..0b64c37ba 100644 --- a/tests/php/indexables/TestCommentMultisite.php +++ b/tests/php/indexables/TestCommentMultisite.php @@ -59,7 +59,6 @@ public function set_up() { ElasticPress\Indexables::factory()->get( 'comment' )->create_network_alias( $indexes ); wp_set_current_user( $admin_id ); - } /** diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index e851d8494..d48e8d46d 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -54,7 +54,7 @@ public function set_up() { // Allow some meta fields to be indexed. add_filter( 'ep_prepare_meta_allowed_keys', - function( $allowed_metakeys ) { + function ( $allowed_metakeys ) { return array_merge( $allowed_metakeys, [ @@ -2518,7 +2518,7 @@ public function testSearchRelevanceOrderbyQueryAdvanced() { foreach ( $query->posts as $post ) { $this->assertEquals( $posts[ $i ], $post->ID ); - $i++; + ++$i; } } @@ -3897,7 +3897,7 @@ public function testPrepareMetaManual() { $this->markTestSkipped(); } - $change_meta_mode = function() { + $change_meta_mode = function () { return 'manual'; }; add_filter( 'ep_meta_mode', $change_meta_mode ); @@ -3908,7 +3908,7 @@ public function testPrepareMetaManual() { // Set default weighting $weighting_default = $weighting->get_weighting_configuration_with_defaults(); - $set_default_weighting = function() use ( $weighting_default ) { + $set_default_weighting = function () use ( $weighting_default ) { return $weighting_default; }; @@ -3933,7 +3933,7 @@ public function testPrepareMetaManual() { /** * Test addition via the ep_prepare_meta_allowed_protected_keys filter. */ - $add_meta_via_allowed_protected = function( $fields, $post ) { + $add_meta_via_allowed_protected = function ( $fields, $post ) { $this->assertInstanceOf( '\WP_Post', $post ); $this->assertIsArray( $fields ); return [ '_test_private_meta_1' ]; @@ -3946,7 +3946,7 @@ public function testPrepareMetaManual() { /** * Test addition via the ep_prepare_meta_allowed_keys filter. */ - $add_meta_via_allowed = function( $fields, $post ) { + $add_meta_via_allowed = function ( $fields, $post ) { $this->assertInstanceOf( '\WP_Post', $post ); $this->assertIsArray( $fields ); @@ -3960,7 +3960,7 @@ public function testPrepareMetaManual() { // Set changed weighting remove_filter( 'ep_weighting_configuration', $set_default_weighting ); - $set_changed_weighting = function() use ( $weighting_default ) { + $set_changed_weighting = function () use ( $weighting_default ) { $weighting_default['post']['meta.test_key2.value'] = [ 'enabled' => true, 'weight' => 1, @@ -3991,7 +3991,6 @@ public function filter_ep_prepare_meta_allowed_protected_keys( $meta_keys ) { $meta_keys[] = '_test_private_meta_1'; return $meta_keys; - } /** @@ -4005,7 +4004,6 @@ public function filter_ep_prepare_meta_excluded_public_keys( $meta_keys ) { $meta_keys[] = 'test_key1'; return $meta_keys; - } /** @@ -4083,7 +4081,6 @@ public function testMetaValueTypes() { $this->assertTrue( is_array( $recognizable_time ) && array_key_exists( 'datetime', $recognizable_time ) && '2020-01-20 00:00:00' === $recognizable_time['datetime'] ); $this->assertTrue( is_array( $relative_format ) && 6 === count( $relative_format ) ); $this->assertTrue( is_array( $relative_format ) && array_key_exists( 'datetime', $relative_format ) && gmdate( 'Y-m-d H:i:s', strtotime( '+1 year' ) ) === $relative_format['datetime'] ); - } /** @@ -4156,7 +4153,6 @@ public function testMetaKeyQuery() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); - } /** @@ -4187,7 +4183,6 @@ public function testMetaKeyQueryNum() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); - } /** @@ -4227,7 +4222,6 @@ public function testMetaKeyQueryMix() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); - } /** @@ -4307,7 +4301,6 @@ public function testMetaValueTypeQueryNumeric() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); - } /** @@ -4469,7 +4462,6 @@ public function testMetaValueTypeQueryDate() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); - } /** @@ -6146,7 +6138,7 @@ public function testHttpRequestArgsFilter() { add_filter( 'http_request_args', - function( $args ) { + function ( $args ) { $args['headers']['x-my-value'] = '12345'; return $args; } @@ -6154,7 +6146,7 @@ function( $args ) { add_filter( 'http_request_args', - function( $args ) { + function ( $args ) { $this->assertSame( '12345', $args['headers']['x-my-value'] ); return $args; }, @@ -6366,7 +6358,7 @@ public function testPrepareDocumentFallbacks() { // Run it again with a filter to return a taxonomy that's not // a WP_Taxonomy class. - $terms_callback = function() { + $terms_callback = function () { return [ 'testPrepareDocumentFallbacks', ]; @@ -6778,7 +6770,7 @@ public function testFormatArgsEpPostFilter() { $test_args = []; $test_query = new \WP_Query( $test_args ); - $add_es_filter = function( $filters, $args, $query ) use ( $test_query, $test_args ) { + $add_es_filter = function ( $filters, $args, $query ) use ( $test_query, $test_args ) { $filters['new_filter'] = [ 'term' => [ 'my_custom_field.raw' => 'my_custom_value', @@ -6835,7 +6827,7 @@ public function testParseOrderby( $orderby, $es_key ) { 'order' => 'asc', ]; - $assert_callback = function( $args ) use ( &$method_executed, $es_key ) { + $assert_callback = function ( $args ) use ( &$method_executed, $es_key ) { $method_executed = true; $this->assertArrayHasKey( $es_key, $args['sort'][0] ); @@ -6919,7 +6911,7 @@ public function testParseOrderbyMetaValueParams( $meta_value_type, $es_type, $me 'meta_key' => 'test_key', ]; - $assert_callback = function( $args ) use ( &$method_executed, $es_type ) { + $assert_callback = function ( $args ) use ( &$method_executed, $es_type ) { $method_executed = true; $this->assertArrayHasKey( "meta.test_key.{$es_type}", $args['sort'][0] ); @@ -6964,7 +6956,7 @@ public function testParseOrderbyMetaValueWithoutMetaKeyParams( $meta_value_type, ], ]; - $assert_callback = function( $args ) use ( &$method_executed, $es_type ) { + $assert_callback = function ( $args ) use ( &$method_executed, $es_type ) { $method_executed = true; $this->assertArrayHasKey( "meta.test_key.{$es_type}", $args['sort'][0] ); @@ -7010,7 +7002,7 @@ public function testParseOrderbyMetaQueryTypes( $meta_value_type, $es_type ) { ], ]; - $assert_callback = function( $args ) use ( &$method_executed, $es_type ) { + $assert_callback = function ( $args ) use ( &$method_executed, $es_type ) { $method_executed = true; $this->assertArrayHasKey( "meta.test_key.{$es_type}", $args['sort'][0] ); @@ -7054,7 +7046,7 @@ public function testParseOrderbyMetaMultiple() { ], ]; - $assert_callback = function( $args ) use ( &$method_executed ) { + $assert_callback = function ( $args ) use ( &$method_executed ) { $method_executed = true; $expected_sort = [ @@ -7110,7 +7102,7 @@ public function testParseNestedTaxQuery() { ], ]; - $assert_callback = function( $args ) { + $assert_callback = function ( $args ) { $this->assertSame( 123, $args['post_filter']['bool']['must'][0]['bool']['must'][0]['bool']['should'][0]['terms']['terms.category.term_id'][0] ); $this->assertSame( 456, $args['post_filter']['bool']['must'][0]['bool']['must'][0]['bool']['should'][1]['terms']['terms.post_tag.term_id'][0] ); @@ -7147,12 +7139,12 @@ public function testPutMapping() { foreach ( $version_and_file as $version => $file ) { - $version_callback = function() use ( $version ) { + $version_callback = function () use ( $version ) { return $version; }; // Callback to test the mapping file that was selected. - $assert_callback = function( $mapping_file ) use ( $file ) { + $assert_callback = function ( $mapping_file ) use ( $file ) { $this->assertSame( $file, basename( $mapping_file ) ); return $mapping_file; }; @@ -7236,7 +7228,7 @@ public function testFoundPosts() { */ public function testGetESPosts() { - $assert_callback = function( $formatted_args, $args ) { + $assert_callback = function ( $formatted_args, $args ) { $this->assertSame( 'post', $args['post_type'] ); @@ -7266,7 +7258,7 @@ public function testGetESPosts() { ElasticPress\Elasticsearch::factory()->refresh_indices(); // Now test the fields parameter. - $assert_callback = function( $new_posts ) use ( $post_ids ) { + $assert_callback = function ( $new_posts ) use ( $post_ids ) { $this->assertContains( $post_ids[0], $new_posts ); $this->assertContains( $post_ids[1], $new_posts ); @@ -7288,7 +7280,7 @@ public function testGetESPosts() { remove_filter( 'ep_wp_query', $assert_callback ); // Test the id=>parent parameter. - $assert_callback = function( $new_posts ) use ( $post_ids ) { + $assert_callback = function ( $new_posts ) use ( $post_ids ) { $this->assertSame( $post_ids[0], $new_posts[0]->ID ); $this->assertSame( $post_ids[1], $new_posts[1]->ID ); @@ -7502,7 +7494,7 @@ public function testPostSyncQueuePermissions() { // Test user permissions. We'll tell WP the user is not allowed // to edit the post we created at the top of this function. - $map_meta_cap_callback = function( $caps, $cap, $user_id, $args ) use ( $post_id ) { + $map_meta_cap_callback = function ( $caps, $cap, $user_id, $args ) use ( $post_id ) { if ( 'edit_post' === $cap && is_array( $args ) && ! empty( $args ) && $post_id === $args[0] ) { $caps = [ 'do_not_allow' ]; @@ -7982,7 +7974,7 @@ public function testGetSearchAlgorithm() { */ $version_35 = \ElasticPress\SearchAlgorithms::factory()->get( '3.5' ); - $set_version_35 = function() { + $set_version_35 = function () { return '3.5'; }; @@ -7999,7 +7991,7 @@ public function testGetSearchAlgorithm() { */ $basic = \ElasticPress\SearchAlgorithms::factory()->get( 'basic' ); - $set_non_existent_version = function() { + $set_non_existent_version = function () { return 'foobar'; }; @@ -8033,7 +8025,7 @@ public function testIsMetaAllowed() { add_filter( 'ep_prepare_meta_allowed_keys', - function( $allowed_metakeys ) { + function ( $allowed_metakeys ) { return array_merge( $allowed_metakeys, [ 'meta' ] ); } ); @@ -8110,7 +8102,7 @@ public function testGetAllDistinctValues() { $this->assertCount( 1, $distinct_values ); $this->assertContains( 'bar', $distinct_values ); - $change_bucket_size = function( $count, $field ) { + $change_bucket_size = function ( $count, $field ) { return ( 'meta.test_key1.raw' === $field ) ? 1 : $count; }; add_filter( 'ep_post_all_distinct_values', $change_bucket_size, 10, 2 ); @@ -8184,7 +8176,7 @@ public function testExcludeFromSearchQueryBypassFilter() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - $bypass = function( $should_bypass, $query ) { + $bypass = function ( $should_bypass, $query ) { $this->assertInstanceOf( \WP_Query::class, $query ); return true; }; @@ -8327,7 +8319,7 @@ public function testHighlightTagsWithCustomClass() { add_filter( 'ep_highlighting_class', - function( $class ) { + function ( $class ) { return 'my-custom-class'; } ); @@ -8339,7 +8331,6 @@ function( $class ) { $this->assertStringContainsString( 'test', $query->posts[0]->post_content ); $this->assertStringContainsString( 'test', $query->posts[0]->post_title ); - } /** @@ -8366,7 +8357,7 @@ public function testHighlightTagsOnlyForTitle() { add_filter( 'ep_highlighting_fields', - function( $fields ) { + function ( $fields ) { return array( 'post_title' ); } ); @@ -8442,7 +8433,7 @@ public function testHighlightTagsNotSetWhenSearchIsEmpty() { add_action( 'pre_http_request', - function( $preempt, $parsed_args, $url ) { + function ( $preempt, $parsed_args, $url ) { $body = json_decode( $parsed_args['body'], true ); $this->assertArrayNotHasKey( 'highlight', $body ); @@ -8533,7 +8524,6 @@ public function testExcludeFromSearchQueryWithMetaQuery() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); - } /** @@ -8588,7 +8578,7 @@ public function testGetDistinctMetaFieldKeysDb() { /** * Test the `ep_post_pre_meta_keys_db` filter */ - $return_custom_array = function() { + $return_custom_array = function () { return [ 'totally_custom_key' ]; }; add_filter( 'ep_post_pre_meta_keys_db', $return_custom_array ); @@ -8605,7 +8595,7 @@ public function testGetDistinctMetaFieldKeysDb() { /** * Test the `ep_post_pre_meta_keys_db` filter */ - $return_custom_array = function( $meta_keys ) { + $return_custom_array = function ( $meta_keys ) { return array_merge( $meta_keys, [ 'custom_key' ] ); }; add_filter( 'ep_post_meta_keys_db', $return_custom_array ); @@ -8636,7 +8626,7 @@ public function testGetDistinctMetaFieldKeysDbPerPostType() { /** * Test the `ep_post_pre_meta_keys_db_per_post_type` filter */ - $return_custom_array = function( $meta_keys, $post_type ) { + $return_custom_array = function ( $meta_keys, $post_type ) { $this->assertSame( $post_type, 'ep_test' ); return [ 'totally_custom_key' ]; }; @@ -8654,7 +8644,7 @@ public function testGetDistinctMetaFieldKeysDbPerPostType() { /** * Test the `ep_post_meta_keys_db_per_post_type` filter */ - $return_custom_array = function( $meta_keys, $post_type ) { + $return_custom_array = function ( $meta_keys, $post_type ) { $this->assertSame( $post_type, 'ep_test' ); return array_merge( $meta_keys, [ 'custom_key' ] ); }; @@ -8678,14 +8668,14 @@ public function testGetLazyPostTypeIdsFilters() { /** * Test the `ep_post_meta_by_type_ids_per_page` and `ep_post_meta_by_type_number_of_pages` filters */ - $custom_number_of_ids = function( $per_page, $post_type ) { + $custom_number_of_ids = function ( $per_page, $post_type ) { $this->assertSame( 11000, $per_page ); $this->assertSame( $post_type, 'ep_test' ); return 1; }; add_filter( 'ep_post_meta_by_type_ids_per_page', $custom_number_of_ids, 10, 2 ); - $custom_number_of_pages = function( $pages, $per_page, $post_type ) { + $custom_number_of_pages = function ( $pages, $per_page, $post_type ) { $this->assertSame( 1, $per_page ); $this->assertSame( $post_type, 'ep_test' ); return 1; @@ -8907,7 +8897,7 @@ public function testDeletingThumbnailShouldNotUpdateRelatedNonIndexablePost() { // Remove product from indexable post types. add_filter( 'ep_indexable_post_types', - function( $post_types ) { + function ( $post_types ) { unset( $post_types['product'] ); return $post_types; } @@ -9064,7 +9054,7 @@ public function testAddTermSuggestFieldEs7() { * @group post */ public function testAddTermSuggestFieldEs5() { - $change_es_version = function() { + $change_es_version = function () { return '5.6'; }; add_filter( 'ep_elasticsearch_version', $change_es_version ); @@ -9174,7 +9164,7 @@ public function test_mapping_ep_stop_filter() { $this->assertContains( 'ep_stop', $index_settings['index.analysis.analyzer.default.filter'] ); $this->assertSame( '_english_', $index_settings['index.analysis.filter.ep_stop.stopwords'] ); - $change_lang = function( $lang, $context ) { + $change_lang = function ( $lang, $context ) { return 'filter_ep_stop' === $context ? '_arabic_' : $lang; }; add_filter( 'ep_analyzer_language', $change_lang, 11, 2 ); @@ -9227,7 +9217,7 @@ public function test_get_all_allowed_metas_manual() { ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->tear_down(); // Add some meta data using the Weighting Dashboard - $set_changed_weighting = function( $weighting_default ) { + $set_changed_weighting = function ( $weighting_default ) { $weighting_default['post']['meta.allowed_weighting_dashboard.value'] = [ 'enabled' => true, 'weight' => 1, diff --git a/tests/php/indexables/TestPostMultisite.php b/tests/php/indexables/TestPostMultisite.php index bf39dd6f5..3b38006df 100644 --- a/tests/php/indexables/TestPostMultisite.php +++ b/tests/php/indexables/TestPostMultisite.php @@ -68,7 +68,7 @@ public function set_up() { // Allow some meta fields to be indexed. add_filter( 'ep_prepare_meta_allowed_keys', - function( $allowed_metakeys ) { + function ( $allowed_metakeys ) { return array_merge( $allowed_metakeys, [ @@ -240,7 +240,7 @@ public function testWPQuerySearchContent() { $this->assertEquals( $post->site_id, get_current_blog_id() ); if ( get_current_blog_id() !== $original_site_id ) { - $other_site_post_count++; + ++$other_site_post_count; } } @@ -500,7 +500,7 @@ public function testWPQuerySearchExcerpt() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -562,7 +562,7 @@ public function testTaxQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -620,7 +620,7 @@ public function testPostTypeSearchQueryPage() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -672,7 +672,7 @@ public function testPostTypeSearchQueryPost() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -724,7 +724,7 @@ public function testNoPostTypeSearchQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -775,7 +775,7 @@ public function testNoPostTypeNoSearchQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -833,7 +833,7 @@ public function testAuthorIDQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -889,14 +889,14 @@ public function testAuthorNameQuery() { ) ); - $posts_created++; + ++$posts_created; } ElasticPress\Elasticsearch::factory()->refresh_indices(); restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -950,7 +950,7 @@ public function testSearchMetaQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1034,7 +1034,7 @@ public function testFilterMetaQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1103,7 +1103,7 @@ public function testSearchTaxQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1170,7 +1170,7 @@ public function testSearchAuthorQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1376,7 +1376,7 @@ public function testQueryRestorationResetPostData() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1441,7 +1441,7 @@ public function testQueryRestorationResetQuery() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1508,7 +1508,7 @@ public function testQueryStack() { restore_current_blog(); - $i++; + ++$i; } $args = array( @@ -1587,7 +1587,7 @@ public function testQueryIntegrationSkip() { restore_current_blog(); - $i++; + ++$i; } add_filter( 'ep_skip_query_integration', '__return_true' ); @@ -1926,7 +1926,7 @@ public function testWPQuerySearchContentWithDeprecatedSitesParam() { $this->assertEquals( $post->site_id, get_current_blog_id() ); if ( get_current_blog_id() !== $original_site_id ) { - $other_site_post_count++; + ++$other_site_post_count; } } @@ -2108,6 +2108,4 @@ public function testWPQuerySearchContentForAllSiteExceptOne() { $this->assertEquals( 4, $query->post_count ); $this->assertEquals( 4, $query->found_posts ); } - - } diff --git a/tests/php/indexables/TestTerm.php b/tests/php/indexables/TestTerm.php index 33f99dc0c..fb32b2ea3 100644 --- a/tests/php/indexables/TestTerm.php +++ b/tests/php/indexables/TestTerm.php @@ -139,7 +139,7 @@ public function deleteAllTerms() { public function testTermSync() { add_action( 'ep_sync_term_on_transition', - function() { + function () { $this->fired_actions['ep_sync_term_on_transition'] = true; } ); @@ -211,14 +211,14 @@ public function testTermSyncKill() { add_action( 'ep_sync_term_on_transition', - function() { + function () { $this->fired_actions['ep_sync_term_on_transition'] = true; } ); add_filter( 'ep_term_sync_kill', - function( $kill, $term_id ) use ( $created_term_id ) { + function ( $kill, $term_id ) use ( $created_term_id ) { if ( $created_term_id === $term_id ) { return true; } @@ -273,7 +273,7 @@ public function testBasicTermQuery() { $this->assertEquals( 4, count( $term_query->terms ) ); // Test some of the filters and defaults. - $return_2 = function() { + $return_2 = function () { return 2; }; @@ -1009,7 +1009,7 @@ public function testHierarchicalTerms() { // Remove uncategorized, not synced to ES. $wp_slugs[ $query_type ] = array_filter( $wp_slugs[ $query_type ], - function( $slug ) { + function ( $slug ) { return 'uncategorized' !== $slug; } ); @@ -1396,7 +1396,7 @@ public function testPrepareMetaProtectedKeys() { $term = new \ElasticPress\Indexable\Term\Term(); - $callback = function( $keys ) { + $callback = function ( $keys ) { $keys[] = '_custom_protected_key'; return $keys; }; @@ -1525,12 +1525,12 @@ public function testPutMapping() { foreach ( $version_and_file as $version => $file ) { - $version_callback = function() use ( $version ) { + $version_callback = function () use ( $version ) { return $version; }; // Callback to test the mapping file that was selected. - $assert_callback = function( $mapping_file ) use ( $file ) { + $assert_callback = function ( $mapping_file ) use ( $file ) { $this->assertSame( $file, basename( $mapping_file ) ); return $mapping_file; }; @@ -1548,7 +1548,6 @@ public function testPutMapping() { remove_filter( 'ep_fallback_elasticsearch_version', $version_callback ); remove_filter( 'ep_term_mapping_file', $assert_callback ); } - } /** @@ -1737,7 +1736,7 @@ public function test_mapping_ep_stop_filter() { $this->assertContains( 'ep_stop', $index_settings['index.analysis.analyzer.default.filter'] ); $this->assertSame( '_english_', $index_settings['index.analysis.filter.ep_stop.stopwords'] ); - $change_lang = function( $lang, $context ) { + $change_lang = function ( $lang, $context ) { return 'filter_ep_stop' === $context ? '_arabic_' : $lang; }; add_filter( 'ep_analyzer_language', $change_lang, 11, 2 ); diff --git a/tests/php/indexables/TestTermMultisite.php b/tests/php/indexables/TestTermMultisite.php index 5b46c04cf..67e3c8c81 100644 --- a/tests/php/indexables/TestTermMultisite.php +++ b/tests/php/indexables/TestTermMultisite.php @@ -59,7 +59,6 @@ public function set_up() { ElasticPress\Indexables::factory()->get( 'term' )->create_network_alias( $indexes ); wp_set_current_user( $admin_id ); - } /** @@ -149,7 +148,6 @@ public function testTermQueryForSitesSubset() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 8, count( $query->get_terms() ) ); - } /** @@ -276,7 +274,6 @@ public function testTermQueryForAllSitesExceptOne() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 8, count( $query->get_terms() ) ); - } /** @@ -372,7 +369,6 @@ public function testTermQuerySearchWithDeprecatedSitesParam() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 4, count( $query->get_terms() ) ); - } /** diff --git a/tests/php/screen/TestSettings.php b/tests/php/screen/TestSettings.php index 2901d510f..11ed3032f 100644 --- a/tests/php/screen/TestSettings.php +++ b/tests/php/screen/TestSettings.php @@ -8,9 +8,9 @@ namespace ElasticPressTest; -use \ElasticPress\Screen; -use \ElasticPress\Screen\Settings; -use \ElasticPress\Utils; +use ElasticPress\Screen; +use ElasticPress\Screen\Settings; +use ElasticPress\Utils; /** * Test the Settings class diff --git a/tests/php/screen/TestStatusReport.php b/tests/php/screen/TestStatusReport.php index 9c63158f2..82b33c877 100644 --- a/tests/php/screen/TestStatusReport.php +++ b/tests/php/screen/TestStatusReport.php @@ -8,8 +8,8 @@ namespace ElasticPressTest; -use \ElasticPress\Screen\StatusReport; -use \ElasticPress\Utils; +use ElasticPress\Screen\StatusReport; +use ElasticPress\Utils; /** * Test the Status Report class @@ -39,7 +39,7 @@ public function testGetReports() { public function testGetReportsFilter() { $status_report = new StatusReport(); - $add_filter = function( $reports ) { + $add_filter = function ( $reports ) { $reports['custom'] = new \stdClass(); return $reports; }; @@ -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.Misspelled $reports = $status_report->get_reports(); $this->assertSame( @@ -328,7 +328,7 @@ public function testFailedQueriesReport() { add_filter( 'ep_query_logger_logs', - function( $logs ) use ( $time_stamp, $random_no ) { + function ( $logs ) use ( $time_stamp, $random_no ) { $logs = array( [ 'wp_url' => 'http://example.com', diff --git a/tests/php/searchAlgorithms/TestDefaultSearchAlgorithm.php b/tests/php/searchAlgorithms/TestDefaultSearchAlgorithm.php index 9207092bf..7c447553d 100644 --- a/tests/php/searchAlgorithms/TestDefaultSearchAlgorithm.php +++ b/tests/php/searchAlgorithms/TestDefaultSearchAlgorithm.php @@ -54,7 +54,7 @@ public function testFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -101,7 +101,7 @@ public function testPostFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -148,7 +148,7 @@ public function testLegacyFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -188,7 +188,7 @@ public function testLegacyFilters() { * @param array $search_fields Search fields * @return array */ - protected function getModel( string $search_term, array $search_fields ) : array { + protected function getModel( string $search_term, array $search_fields ): array { return [ 'bool' => [ 'should' => [ diff --git a/tests/php/searchAlgorithms/TestVersion_350SearchAlgorithm.php b/tests/php/searchAlgorithms/TestVersion_350SearchAlgorithm.php index 4912220dd..cf9ffb5e4 100644 --- a/tests/php/searchAlgorithms/TestVersion_350SearchAlgorithm.php +++ b/tests/php/searchAlgorithms/TestVersion_350SearchAlgorithm.php @@ -54,7 +54,7 @@ public function testFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -81,7 +81,7 @@ public function testPostFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -106,7 +106,7 @@ public function testLegacyFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -126,7 +126,7 @@ public function testLegacyFilters() { * @param array $search_fields Search fields * @return array */ - protected function getModel( string $search_term, array $search_fields ) : array { + protected function getModel( string $search_term, array $search_fields ): array { return [ 'bool' => [ 'should' => [ diff --git a/tests/php/searchAlgorithms/TestVersion_400SearchAlgorithm.php b/tests/php/searchAlgorithms/TestVersion_400SearchAlgorithm.php index aece47a19..ad2c4fd45 100644 --- a/tests/php/searchAlgorithms/TestVersion_400SearchAlgorithm.php +++ b/tests/php/searchAlgorithms/TestVersion_400SearchAlgorithm.php @@ -54,7 +54,7 @@ public function testFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -111,7 +111,7 @@ public function testPostFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -169,7 +169,7 @@ public function testLegacyFilters() { $search_term = 'search_term'; $search_fields = [ 'post_title', 'post_content' ]; - $test_filter = function() { + $test_filter = function () { return 1234; }; @@ -219,7 +219,7 @@ public function testLegacyFilters() { * @param array $search_fields Search fields * @return array */ - protected function getModel( string $search_term, array $search_fields ) : array { + protected function getModel( string $search_term, array $search_fields ): array { return [ 'bool' => [ 'should' => [ From aabe217589b2e8617fdd0913ea70d1849ca3cc43 Mon Sep 17 00:00:00 2001 From: Felipe Elia