Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Bump woocommerce/woocommerce-sniffs from 0.1.3 to 1.0.0 #11094

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require-dev": {
"phpunit/phpunit": "9.6.13",
"phpunit/php-code-coverage": "9.2.29",
"woocommerce/woocommerce-sniffs": "0.1.3",
"woocommerce/woocommerce-sniffs": "1.0.0",
"phpdocumentor/reflection": "3.0.1",
"yoast/phpunit-polyfills": "2.0.0",
"nikic/php-parser": "4.16.0 as 1.0.0",
Expand Down
239 changes: 194 additions & 45 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<exclude-pattern>src/*</exclude-pattern>
</rule>

<rule ref="WordPress.PHP.DisallowShortTernary.Found">
<rule ref="Universal.Operators.DisallowShortTernary">
<exclude-pattern>src/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>
Expand Down Expand Up @@ -67,7 +67,7 @@
<exclude name="Generic.Commenting.Todo.CommentFound"/>
</rule>

<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
<rule ref="Universal.Arrays.DisallowShortArraySyntax.Found">
<exclude-pattern>src/*</exclude-pattern>
</rule>

Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
$dependencies = array_diff( $script_data['dependencies'], [ $handle ] );
add_action(
'admin_notices',
function() use ( $handle ) {
function () use ( $handle ) {
echo '<div class="error"><p>';
/* translators: %s file handle name. */
printf( esc_html__( 'Script with handle %s had a dependency on itself which has been removed. This is an indicator that your JS code has a circular dependency that can cause bugs.', 'woo-gutenberg-products-block' ), esc_html( $handle ) );
Expand All @@ -248,7 +248,7 @@
}
);
} else {
throw new Exception( sprintf( 'Script with handle %s had a dependency on itself. This is an indicator that your JS code has a circular dependency that can cause bugs.', $handle ) );

Check failure on line 251 in src/Assets/Api.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$handle'.
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Assets/AssetDataRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
'countries' => WC()->countries->get_countries(),
'currency' => $this->get_currency_data(),
'currentUserId' => get_current_user_id(),
'currentUserIsAdmin' => current_user_can( 'manage_woocommerce' ),

Check warning on line 87 in src/Assets/AssetDataRegistry.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Found unknown capability "manage_woocommerce" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
'dateFormat' => wc_date_format(),
'homeUrl' => esc_url( home_url( '/' ) ),
'locale' => $this->get_locale_data(),
Expand Down Expand Up @@ -341,7 +341,7 @@
public function hydrate_data_from_api_request( $key, $path, $check_key_exists = false ) {
$this->add(
$key,
function() use ( $path ) {
function () use ( $path ) {
if ( isset( $this->preloaded_api_requests[ $path ], $this->preloaded_api_requests[ $path ]['body'] ) ) {
return $this->preloaded_api_requests[ $path ]['body'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private function get_block_asset_resource_hints( $filename = '' ) {
$this->get_script_dependency_src_array( $script_data['dependencies'] )
);
return array_map(
function( $src ) {
function ( $src ) {
return array(
'href' => $src,
'as' => 'script',
Expand All @@ -220,7 +220,7 @@ private function get_script_dependency_src_array( array $dependencies ) {
$wp_scripts = wp_scripts();
return array_reduce(
$dependencies,
function( $src, $handle ) use ( $wp_scripts ) {
function ( $src, $handle ) use ( $wp_scripts ) {
if ( isset( $wp_scripts->registered[ $handle ] ) ) {
$src[] = esc_url( add_query_arg( 'ver', $wp_scripts->registered[ $handle ]->ver, $this->get_absolute_url( $wp_scripts->registered[ $handle ]->src ) ) );
$src = array_merge( $src, $this->get_script_dependency_src_array( $wp_scripts->registered[ $handle ]->deps ) );
Expand Down
12 changes: 6 additions & 6 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function init() {
// This render_callback wrapper allows us to add support for plugin-housed template parts.
add_filter(
'block_type_metadata_settings',
function( $settings, $metadata ) {
function ( $settings, $metadata ) {
if (
isset( $metadata['name'], $settings['render_callback'] ) &&
'core/template-part' === $metadata['name'] &&
Expand All @@ -90,13 +90,13 @@ function( $settings, $metadata ) {
// @see https://core.trac.wordpress.org/ticket/58366 for more info.
add_filter(
'block_type_metadata_settings',
function( $settings, $metadata ) {
function ( $settings, $metadata ) {
if (
isset( $metadata['name'], $settings['render_callback'] ) &&
'core/shortcode' === $metadata['name']
) {
$settings['original_render_callback'] = $settings['render_callback'];
$settings['render_callback'] = function( $attributes, $content ) use ( $settings ) {
$settings['render_callback'] = function ( $attributes, $content ) use ( $settings ) {
// The shortcode has already been rendered, so look for the cart/checkout HTML.
if ( strstr( $content, 'woocommerce-cart-form' ) || strstr( $content, 'wc-empty-cart-message' ) || strstr( $content, 'woocommerce-checkout-form' ) ) {
// Return early before wpautop runs again.
Expand Down Expand Up @@ -410,7 +410,7 @@ public function add_block_templates( $query_result, $query, $template_type ) {
* templates that aren't listed in theme.json.
*/
$query_result = array_map(
function( $template ) {
function ( $template ) {
if ( str_contains( $template->slug, 'single-product' ) ) {
// We don't want to add the compatibility layer on the Editor Side.
// The second condition is necessary to not apply the compatibility layer on the REST API. Gutenberg uses the REST API to clone the template.
Expand All @@ -419,7 +419,7 @@ function( $template ) {
// Add the product class to the body. We should move this to a more appropriate place.
add_filter(
'body_class',
function( $classes ) {
function ( $classes ) {
return array_merge( $classes, wc_get_product_class() );
}
);
Expand Down Expand Up @@ -510,7 +510,7 @@ public function get_block_templates_from_woocommerce( $slugs, $already_found_tem
array_filter(
$already_found_templates,
function ( $template ) use ( $template_slug ) {
$template_obj = (object) $template; //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
$template_obj = (object) $template; //phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
return $template_obj->slug === $template_slug;
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function register_block_type() {
$block_settings['style'] = null;
add_filter(
'render_block',
function( $html, $block ) use ( $style_handles ) {
function ( $html, $block ) use ( $style_handles ) {
if ( $block['blockName'] === $this->get_block_type() ) {
array_map( 'wp_enqueue_style', $style_handles );
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/AbstractProductGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ protected function prime_product_variations( $product_ids ) {
// Prepare the data to cache by indexing by the parent product.
$primed_data = array_reduce(
$all_variation_meta_data,
function( $values, $data ) use ( $variation_ids_by_parent ) {
function ( $values, $data ) use ( $variation_ids_by_parent ) {
$values[ $variation_ids_by_parent[ $data->variation_id ] ?? 0 ][] = $data;
return $values;
},
Expand Down
14 changes: 7 additions & 7 deletions src/BlockTypes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function initialize() {
// This prevents the page redirecting when the cart is empty. This is so the editor still loads the page preview.
add_filter(
'woocommerce_checkout_redirect_empty_cart',
function( $return ) {
function ( $return ) {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
return isset( $_GET['_wp-find-template'] ) ? false : $return;
}
Expand Down Expand Up @@ -283,7 +283,7 @@ protected function enqueue_data( array $attributes = [] ) {
$shipping_methods = WC()->shipping()->get_shipping_methods();
$formatted_shipping_methods = array_reduce(
$shipping_methods,
function( $acc, $method ) {
function ( $acc, $method ) {
if ( in_array( $method->id, LocalPickupUtils::get_local_pickup_method_ids(), true ) ) {
return $acc;
}
Expand All @@ -305,7 +305,7 @@ function( $acc, $method ) {
$shipping_zones = \WC_Shipping_Zones::get_zones();
$formatted_shipping_zones = array_reduce(
$shipping_zones,
function( $acc, $zone ) {
function ( $acc, $zone ) {
$acc[] = [
'id' => $zone['id'],
'title' => $zone['zone_name'],
Expand All @@ -329,7 +329,7 @@ function( $acc, $zone ) {
$payment_methods = $this->get_enabled_payment_gateways();
$formatted_payment_methods = array_reduce(
$payment_methods,
function( $acc, $method ) {
function ( $acc, $method ) {
$acc[] = [
'id' => $method->id,
'title' => $method->method_title,
Expand All @@ -354,7 +354,7 @@ function( $acc, $method ) {
$declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' );
$incompatible_extensions = array_reduce(
$declared_extensions['incompatible'],
function( $acc, $item ) {
function ( $acc, $item ) {
$plugin = get_plugin_data( WP_PLUGIN_DIR . '/' . $item );
$acc[] = [
'id' => $plugin['TextDomain'],
Expand Down Expand Up @@ -390,7 +390,7 @@ protected function get_enabled_payment_gateways() {
$payment_gateways = WC()->payment_gateways->payment_gateways();
return array_filter(
$payment_gateways,
function( $payment_gateway ) {
function ( $payment_gateway ) {
return 'yes' === $payment_gateway->enabled;
}
);
Expand Down Expand Up @@ -424,7 +424,7 @@ protected function hydrate_customer_payment_methods() {
foreach ( $payment_methods as $payment_method_group => $saved_payment_methods ) {
$payment_methods[ $payment_method_group ] = array_filter(
$saved_payment_methods,
function( $saved_payment_method ) use ( $payment_gateways ) {
function ( $saved_payment_method ) use ( $payment_gateways ) {
return in_array( $saved_payment_method['method']['gateway'], array_keys( $payment_gateways ), true );
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/BlockTypes/ClassicTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function render_order_received() {

echo '<div class="wp-block-group">';

echo sprintf(
printf(
'<%1$s %2$s>%3$s</%1$s>',
'h1',
get_block_wrapper_attributes(), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
Expand Down Expand Up @@ -382,7 +382,7 @@ public function filter_products_by_stock( $meta_query ) {

$filtered_values = array_filter(
$values_to_array,
function( $value ) use ( $stock_status ) {
function ( $value ) use ( $stock_status ) {
return in_array( $value, $stock_status, true );
}
);
Expand Down
12 changes: 6 additions & 6 deletions src/BlockTypes/CollectionFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function get_aggregated_collection_data( $block ) {
$inner_blocks = $this->get_inner_blocks_recursive( $block->inner_blocks );

$collection_data_params = array_map(
function( $block_name ) use ( $inner_blocks ) {
function ( $block_name ) use ( $inner_blocks ) {
return in_array( $block_name, $inner_blocks, true );
},
$this->collection_data_params_mapping
Expand Down Expand Up @@ -222,7 +222,7 @@ private function get_formatted_products_params( $query ) {
$shared_params = array( 'exclude', 'offset', 'order', 'serach' );
array_walk(
$shared_params,
function( $key ) use ( $query, &$params ) {
function ( $key ) use ( $query, &$params ) {
$params[ $key ] = $query[ $key ] ?? '';
}
);
Expand All @@ -241,7 +241,7 @@ function( $key ) use ( $query, &$params ) {
);
array_walk(
$mapped_params,
function( $mapped_key, $original_key ) use ( $query, &$params ) {
function ( $mapped_key, $original_key ) use ( $query, &$params ) {
$params[ $mapped_key ] = $query[ $original_key ] ?? '';
}
);
Expand All @@ -250,7 +250,7 @@ function( $mapped_key, $original_key ) use ( $query, &$params ) {
* The value of taxQuery and woocommerceAttributes need additional
* transformation to the shape that Store API accepts.
*/
$taxonomy_mapper = function( $key ) {
$taxonomy_mapper = function ( $key ) {
$mapping = array(
'product_tag' => 'tag',
'product_cat' => 'category',
Expand All @@ -262,7 +262,7 @@ function( $mapped_key, $original_key ) use ( $query, &$params ) {
if ( is_array( $query['taxQuery'] ) ) {
array_walk(
$query['taxQuery'],
function( $terms, $taxonomy ) use ( $taxonomy_mapper, &$params ) {
function ( $terms, $taxonomy ) use ( $taxonomy_mapper, &$params ) {
$params[ $taxonomy_mapper( $taxonomy ) ] = implode( ',', $terms );
}
);
Expand All @@ -271,7 +271,7 @@ function( $terms, $taxonomy ) use ( $taxonomy_mapper, &$params ) {
if ( is_array( $query['woocommerceAttributes'] ) ) {
array_walk(
$query['woocommerceAttributes'],
function( $attribute ) use ( &$params ) {
function ( $attribute ) use ( &$params ) {
$params['attributes'][] = array(
'attribute' => $attribute['taxonomy'],
'term_id' => $attribute['termId'],
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ protected function get_tax_label() {
'tax_label' => $tax_label,
'display_cart_prices_including_tax' => false,
);
};
}

return array(
'tax_label' => '',
Expand Down
3 changes: 1 addition & 2 deletions src/BlockTypes/MiniCartContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function enqueue_assets( array $attributes, $content, $block ) {

$properties = array_filter(
$style['properties'],
function( $property ) {
function ( $property ) {
return $property['value'];
}
);
Expand Down Expand Up @@ -165,5 +165,4 @@ public static function get_mini_cart_block_types() {

return $block_types;
}

}
2 changes: 1 addition & 1 deletion src/BlockTypes/OrderConfirmation/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function render_order_details_table_items( $order ) {
$order_items = array_filter(
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
$order->get_items( apply_filters( 'woocommerce_purchase_order_item_types', 'line_item' ) ),
function( $item ) {
function ( $item ) {
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
return apply_filters( 'woocommerce_order_item_visible', true, $item );
}
Expand Down
1 change: 0 additions & 1 deletion src/BlockTypes/ProductAverageRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ protected function render( $attributes, $content, $block ) {
);
}
}

2 changes: 1 addition & 1 deletion src/BlockTypes/ProductCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function get_categories( $attributes ) {
if ( ! $attributes['hasEmpty'] ) {
$categories = array_filter(
$categories,
function( $category ) {
function ( $category ) {
return 0 !== $category->count;
}
);
Expand Down
26 changes: 12 additions & 14 deletions src/BlockTypes/ProductCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public function extend_rest_query_allowed_params( $params ) {
private function merge_queries( ...$queries ) {
$merged_query = array_reduce(
$queries,
function( $acc, $query ) {
function ( $acc, $query ) {
if ( ! is_array( $query ) ) {
return $acc;
}
Expand Down Expand Up @@ -537,15 +537,13 @@ private function array_merge_recursive_replace_non_array_properties( $base, $new
foreach ( $new as $key => $value ) {
if ( is_numeric( $key ) ) {
$base[] = $value;
} else {
if ( is_array( $value ) ) {
if ( ! isset( $base[ $key ] ) ) {
$base[ $key ] = array();
}
$base[ $key ] = $this->array_merge_recursive_replace_non_array_properties( $base[ $key ], $value );
} else {
$base[ $key ] = $value;
} elseif ( is_array( $value ) ) {
if ( ! isset( $base[ $key ] ) ) {
$base[ $key ] = array();
}
$base[ $key ] = $this->array_merge_recursive_replace_non_array_properties( $base[ $key ], $value );
} else {
$base[ $key ] = $value;
}
}

Expand Down Expand Up @@ -718,7 +716,7 @@ private function get_filter_by_taxonomies_query( $tax_query ): array {
$product_taxonomies = get_taxonomies( [ 'object_type' => [ 'product' ] ], 'names' );
$result = array_filter(
$tax_query,
function( $item ) use ( $product_taxonomies ) {
function ( $item ) use ( $product_taxonomies ) {
return isset( $item['taxonomy'] ) && in_array( $item['taxonomy'], $product_taxonomies, true );
}
);
Expand Down Expand Up @@ -807,7 +805,7 @@ private function get_filter_by_attributes_query() {

$queries = array_reduce(
$attributes_filter_query_args,
function( $acc, $query_args ) {
function ( $acc, $query_args ) {
$attribute_name = $query_args['filter'];
$attribute_query_type = $query_args['query_type'];

Expand Down Expand Up @@ -872,7 +870,7 @@ private function get_filter_by_attributes_query_vars() {

$this->attributes_filter_query_args = array_reduce(
wc_get_attribute_taxonomies(),
function( $acc, $attribute ) {
function ( $acc, $attribute ) {
$acc[ $attribute->attribute_name ] = array(
'filter' => AttributeFilter::FILTER_QUERY_VAR_PREFIX . $attribute->attribute_name,
'query_type' => AttributeFilter::QUERY_TYPE_QUERY_VAR_PREFIX . $attribute->attribute_name,
Expand All @@ -899,7 +897,7 @@ private function get_filter_by_stock_status_query() {

$filtered_stock_status_values = array_filter(
explode( ',', $filter_stock_status_values ),
function( $stock_status ) {
function ( $stock_status ) {
return in_array( $stock_status, StockFilter::get_stock_status_query_var_values(), true );
}
);
Expand Down Expand Up @@ -940,7 +938,7 @@ private function get_filter_by_rating_query() {
}

$rating_terms = array_map(
function( $rating ) use ( $product_visibility_terms ) {
function ( $rating ) use ( $product_visibility_terms ) {
return $product_visibility_terms[ 'rated-' . $rating ];
},
$parsed_filter_rating_values
Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/ProductGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function render_dialog() {

$html = array_reduce(
$parsed_template,
function( $carry, $item ) {
function ( $carry, $item ) {
return $carry . render_block( $item );
},
''
Expand Down
Loading
Loading