'; /* 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 ) ); diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index f8fed09cc26..44950d581f3 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -341,7 +341,7 @@ public function hydrate_api_request( $path ) { 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']; } diff --git a/src/AssetsController.php b/src/AssetsController.php index 3fbd7b961ac..814027ae673 100644 --- a/src/AssetsController.php +++ b/src/AssetsController.php @@ -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', @@ -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 ) ); diff --git a/src/BlockTemplatesController.php b/src/BlockTemplatesController.php index 7538cea4e1f..6e47f797c21 100644 --- a/src/BlockTemplatesController.php +++ b/src/BlockTemplatesController.php @@ -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'] && @@ -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. @@ -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. @@ -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() ); } ); @@ -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; } ) diff --git a/src/BlockTypes/AbstractBlock.php b/src/BlockTypes/AbstractBlock.php index c4ef90ddfb2..bf2e4aeb5fa 100644 --- a/src/BlockTypes/AbstractBlock.php +++ b/src/BlockTypes/AbstractBlock.php @@ -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 ); } diff --git a/src/BlockTypes/AbstractProductGrid.php b/src/BlockTypes/AbstractProductGrid.php index a7460767493..1cac2dc69d7 100644 --- a/src/BlockTypes/AbstractProductGrid.php +++ b/src/BlockTypes/AbstractProductGrid.php @@ -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; }, diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index 38133e31b14..614a4669d0d 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -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; } @@ -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; } @@ -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'], @@ -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, @@ -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'], @@ -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; } ); @@ -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 ); } ); diff --git a/src/BlockTypes/ClassicTemplate.php b/src/BlockTypes/ClassicTemplate.php index 9b292f8bd02..f53b80328f4 100644 --- a/src/BlockTypes/ClassicTemplate.php +++ b/src/BlockTypes/ClassicTemplate.php @@ -138,7 +138,7 @@ protected function render_order_received() { echo '
'; printf( /* translators: %1$s is the install command, %2$s is the build command, %3$s is the watch command. */ @@ -255,19 +255,19 @@ function ( Container $container ) { ); $this->container->register( AssetDataRegistry::class, - function( Container $container ) { + function ( Container $container ) { return new AssetDataRegistry( $container->get( AssetApi::class ) ); } ); $this->container->register( AssetsController::class, - function( Container $container ) { + function ( Container $container ) { return new AssetsController( $container->get( AssetApi::class ) ); } ); $this->container->register( PaymentMethodRegistry::class, - function() { + function () { return new PaymentMethodRegistry(); } ); @@ -349,26 +349,26 @@ function () { ); $this->container->register( DraftOrders::class, - function( Container $container ) { + function ( Container $container ) { return new DraftOrders( $container->get( Package::class ) ); } ); $this->container->register( CreateAccount::class, - function( Container $container ) { + function ( Container $container ) { return new CreateAccount( $container->get( Package::class ) ); } ); $this->container->register( GoogleAnalytics::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); return new GoogleAnalytics( $asset_api ); } ); $this->container->register( JetpackWooCommerceAnalytics::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); $asset_data_registry = $container->get( AssetDataRegistry::class ); $block_templates_controller = $container->get( BlockTemplatesController::class ); @@ -377,13 +377,13 @@ function( Container $container ) { ); $this->container->register( Notices::class, - function( Container $container ) { + function ( Container $container ) { return new Notices( $container->get( Package::class ) ); } ); $this->container->register( Hydration::class, - function( Container $container ) { + function ( Container $container ) { return new Hydration( $container->get( AssetDataRegistry::class ) ); } ); @@ -404,28 +404,28 @@ function () { // Maintains backwards compatibility with previous Store API namespace. $this->container->register( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', - function( Container $container ) { + function ( Container $container ) { $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '7.2.0', 'Automattic\WooCommerce\StoreApi\Formatters', '7.4.0' ); return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Formatters::class ); } ); $this->container->register( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', - function( Container $container ) { + function ( Container $container ) { $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '7.2.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '7.4.0' ); return $container->get( StoreApi::class )->container()->get( \Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class ); } ); $this->container->register( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', - function( Container $container ) { + function ( Container $container ) { $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '7.2.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '7.4.0' ); return $container->get( StoreApi::class )->container()->get( SchemaController::class ); } ); $this->container->register( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', - function( Container $container ) { + function ( Container $container ) { $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '7.2.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '7.4.0' ); return $container->get( StoreApi::class )->container()->get( RoutesController::class ); } @@ -446,7 +446,7 @@ function ( $container ) { ); $this->container->register( TasksController::class, - function() { + function () { return new TasksController(); } ); @@ -455,12 +455,12 @@ function() { /** * Throws a deprecation notice for a dependency without breaking requests. * - * @param string $function Class or function being deprecated. + * @param string $function_name Class or function being deprecated. * @param string $version Version in which it was deprecated. * @param string $replacement Replacement class or function, if applicable. * @param string $trigger_error_version Optional version to start surfacing this as a PHP error rather than a log. Defaults to $version. */ - protected function deprecated_dependency( $function, $version, $replacement = '', $trigger_error_version = '' ) { + protected function deprecated_dependency( $function_name, $version, $replacement = '', $trigger_error_version = '' ) { if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { return; } @@ -468,12 +468,12 @@ protected function deprecated_dependency( $function, $version, $replacement = '' $trigger_error_version = $trigger_error_version ? $trigger_error_version : $version; $error_message = $replacement ? sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', - $function, + $function_name, $version, $replacement ) : sprintf( '%1$s is deprecated since version %2$s with no alternative available.', - $function, + $function_name, $version ); /** @@ -481,7 +481,7 @@ protected function deprecated_dependency( $function, $version, $replacement = '' * * @since 7.3.0 */ - do_action( 'deprecated_function_run', $function, $replacement, $version ); + do_action( 'deprecated_function_run', $function_name, $replacement, $version ); $log_error = false; @@ -521,28 +521,28 @@ protected function deprecated_dependency( $function, $version, $replacement = '' protected function register_payment_methods() { $this->container->register( Cheque::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); return new Cheque( $asset_api ); } ); $this->container->register( PayPal::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); return new PayPal( $asset_api ); } ); $this->container->register( BankTransfer::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); return new BankTransfer( $asset_api ); } ); $this->container->register( CashOnDelivery::class, - function( Container $container ) { + function ( Container $container ) { $asset_api = $container->get( AssetApi::class ); return new CashOnDelivery( $asset_api ); } diff --git a/src/Domain/Package.php b/src/Domain/Package.php index 6958a6bec8d..19d13a8201b 100644 --- a/src/Domain/Package.php +++ b/src/Domain/Package.php @@ -79,7 +79,6 @@ public function get_version_stored_on_db() { */ public function set_version_stored_on_db() { update_option( Options::WC_BLOCK_VERSION, $this->get_version() ); - } /** diff --git a/src/Domain/Services/CreateAccount.php b/src/Domain/Services/CreateAccount.php index 6954dd3c784..b338d87cd76 100644 --- a/src/Domain/Services/CreateAccount.php +++ b/src/Domain/Services/CreateAccount.php @@ -38,7 +38,7 @@ function ( $wc_emails_instance ) { // Add custom "new account" handler. add_action( 'woocommerce_created_customer_notification', - function( $customer_id, $new_customer_data = array(), $password_generated = false ) use ( $wc_emails_instance ) { + function ( $customer_id, $new_customer_data = array(), $password_generated = false ) use ( $wc_emails_instance ) { // If this is a block-based signup, send a new email with password reset link (no password in email). if ( isset( $new_customer_data['source'] ) && 'store-api' === $new_customer_data['source'] ) { $this->customer_new_account( $customer_id, $new_customer_data ); diff --git a/src/Domain/Services/DraftOrders.php b/src/Domain/Services/DraftOrders.php index 1f0fc2d3b75..6df732100cc 100644 --- a/src/Domain/Services/DraftOrders.php +++ b/src/Domain/Services/DraftOrders.php @@ -168,13 +168,13 @@ public function delete_expired_draft_orders() { ] ); - // do we bail because the query results are unexpected? + // Do we bail because the query results are unexpected? try { - $this->assert_order_results( $orders, $batch_size ); + $this->assert_order_results( $orders ); if ( $orders ) { foreach ( $orders as $order ) { $order->delete( true ); - $count ++; + ++$count; } } if ( $batch_size === $count && function_exists( 'as_enqueue_async_action' ) ) { @@ -206,11 +206,10 @@ private function ensure_draft_status_registered() { * this service class executes. * * @param WC_Order[] $order_results The order results being asserted. - * @param int $expected_batch_size The expected batch size for the results. * @throws Exception If any assertions fail, an exception is thrown. */ - private function assert_order_results( $order_results, $expected_batch_size ) { - // if not an array, then just return because it won't get handled + private function assert_order_results( $order_results ) { + // If not an array, then just return because it won't get handled // anyways. if ( ! is_array( $order_results ) ) { return; @@ -218,17 +217,21 @@ private function assert_order_results( $order_results, $expected_batch_size ) { $suffix = ' This is an indicator that something is filtering WooCommerce or WordPress queries and modifying the query parameters.'; - // if count is greater than our expected batch size, then that's a problem. + // If count is greater than our expected batch size, then that's a problem. + // phpcs ignores are because the output is hardcoded and doesn't need to be escaped. if ( count( $order_results ) > 20 ) { + // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped throw new Exception( 'There are an unexpected number of results returned from the query.' . $suffix ); } - // if any of the returned orders are not draft (or not a WC_Order), then that's a problem. + // If any of the returned orders are not draft (or not a WC_Order), then that's a problem. foreach ( $order_results as $order ) { if ( ! ( $order instanceof WC_Order ) ) { + // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped throw new Exception( 'The returned results contain a value that is not a WC_Order.' . $suffix ); } if ( ! $order->has_status( self::STATUS ) ) { + // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped throw new Exception( 'The results contain an order that is not a `wc-checkout-draft` status in the results.' . $suffix ); } } diff --git a/src/Domain/Services/FeatureGating.php b/src/Domain/Services/FeatureGating.php index 581e6aecd32..f2d2f9466b8 100644 --- a/src/Domain/Services/FeatureGating.php +++ b/src/Domain/Services/FeatureGating.php @@ -177,5 +177,4 @@ public function is_block_templates_controller_refactor_enabled() { } return false; } - } diff --git a/src/Domain/Services/GoogleAnalytics.php b/src/Domain/Services/GoogleAnalytics.php index 1123cd52016..55d2b19e4fb 100644 --- a/src/Domain/Services/GoogleAnalytics.php +++ b/src/Domain/Services/GoogleAnalytics.php @@ -106,7 +106,7 @@ private function get_google_analytics_settings() { * @param string $src Src of script. * @return string */ - public function async_script_loader_tags( $tag, $handle, $src ) { + public function async_script_loader_tags( $tag, $handle, $src ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed if ( ! in_array( $handle, array( 'google-tag-manager' ), true ) ) { return $tag; } diff --git a/src/Domain/Services/JetpackWooCommerceAnalytics.php b/src/Domain/Services/JetpackWooCommerceAnalytics.php index 0908813b64e..6211251acb3 100644 --- a/src/Domain/Services/JetpackWooCommerceAnalytics.php +++ b/src/Domain/Services/JetpackWooCommerceAnalytics.php @@ -121,7 +121,7 @@ public function output_order_received_page_view_properties( $order_id ) { $order = wc_get_order( $order_id ); $product_data = wp_json_encode( array_map( - function( $item ) { + function ( $item ) { $product = wc_get_product( $item->get_product_id() ); $product_details = $this->get_product_details( $product ); return array( @@ -377,7 +377,7 @@ public function track_local_pickup( $served, $result, $request ) { 'pickup_locations_enabled' => count( array_filter( $locations, - function( $location ) { + function ( $location ) { return $location['enabled']; } ) ), diff --git a/src/Domain/Services/Notices.php b/src/Domain/Services/Notices.php index 12090af3cf1..6a17c0fb375 100644 --- a/src/Domain/Services/Notices.php +++ b/src/Domain/Services/Notices.php @@ -47,7 +47,7 @@ public function init() { add_filter( 'wc_get_template', [ $this, 'get_notices_template' ], 10, 5 ); add_action( 'wp_head', - function() { + function () { // These pages may return notices in ajax responses, so we need the styles to be ready. if ( is_cart() || is_checkout() ) { wp_enqueue_style( 'wc-blocks-style' ); @@ -94,7 +94,7 @@ public function add_kses_notice_allowed_tags( $allowed_tags ) { * @param string $default_path Default path. * @return string */ - public function get_notices_template( $template, $template_name, $args, $template_path, $default_path ) { + public function get_notices_template( $template, $template_name, $args, $template_path, $default_path ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Ignoring because those parameters passed by the filter. if ( in_array( $template_name, $this->notice_templates, true ) ) { $template = $this->package->get_path( 'templates/' . $template_name ); wp_enqueue_style( 'wc-blocks-style' ); diff --git a/src/Installer.php b/src/Installer.php index 60cc71b7a00..69687977dcf 100644 --- a/src/Installer.php +++ b/src/Installer.php @@ -116,7 +116,7 @@ protected function maybe_create_table( $table_name, $create_sql ) { protected function add_create_table_notice( $table_name ) { add_action( 'admin_notices', - function() use ( $table_name ) { + function () use ( $table_name ) { echo '
'; printf( /* translators: %1$s table name, %2$s database user, %3$s database name. */ diff --git a/src/Payments/PaymentMethodRegistry.php b/src/Payments/PaymentMethodRegistry.php index e0ea1ea0712..536752cf707 100644 --- a/src/Payments/PaymentMethodRegistry.php +++ b/src/Payments/PaymentMethodRegistry.php @@ -24,7 +24,7 @@ final class PaymentMethodRegistry extends IntegrationRegistry { public function get_all_active_registered() { return array_filter( $this->get_all_registered(), - function( $payment_method ) { + function ( $payment_method ) { return $payment_method->is_active(); } ); diff --git a/src/Shipping/ShippingController.php b/src/Shipping/ShippingController.php index d233d193926..dcac54e1f3d 100644 --- a/src/Shipping/ShippingController.php +++ b/src/Shipping/ShippingController.php @@ -54,7 +54,7 @@ public function init() { if ( is_admin() ) { $this->asset_data_registry->add( 'countryStates', - function() { + function () { return WC()->countries->get_states(); }, true @@ -438,7 +438,7 @@ public function filter_shipping_packages( $packages ) { // Check all packages for an instance of a collectable shipping method. $valid_packages = array_filter( $packages, - function( $package ) { + function ( $package ) { $shipping_method_ids = ArrayUtil::select( $package['rates'] ?? [], 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD ); return ! empty( array_intersect( LocalPickupUtils::get_local_pickup_method_ids(), $shipping_method_ids ) ); } @@ -447,14 +447,14 @@ function( $package ) { // Remove pickup location from rates arrays. if ( count( $valid_packages ) !== count( $packages ) ) { $packages = array_map( - function( $package ) { + function ( $package ) { if ( ! is_array( $package['rates'] ) ) { $package['rates'] = []; return $package; } $package['rates'] = array_filter( $package['rates'], - function( $rate ) { + function ( $rate ) { return ! in_array( $rate->get_method_id(), LocalPickupUtils::get_local_pickup_method_ids(), true ); } ); diff --git a/src/StoreApi/Exceptions/InvalidCartException.php b/src/StoreApi/Exceptions/InvalidCartException.php index 490b658099a..9c23fbc57b5 100644 --- a/src/StoreApi/Exceptions/InvalidCartException.php +++ b/src/StoreApi/Exceptions/InvalidCartException.php @@ -70,5 +70,4 @@ public function getError() { public function getAdditionalData() { return $this->additional_data; } - } diff --git a/src/StoreApi/Exceptions/StockAvailabilityException.php b/src/StoreApi/Exceptions/StockAvailabilityException.php index 5069f260e8f..2998896b18f 100644 --- a/src/StoreApi/Exceptions/StockAvailabilityException.php +++ b/src/StoreApi/Exceptions/StockAvailabilityException.php @@ -68,5 +68,4 @@ public function getAdditionalData() { public function getProductName() { return $this->product_name; } - } diff --git a/src/StoreApi/Formatters.php b/src/StoreApi/Formatters.php index 2a03b78e3cd..457a40207d2 100644 --- a/src/StoreApi/Formatters.php +++ b/src/StoreApi/Formatters.php @@ -1,7 +1,7 @@ remove_arg_options( $property['properties'] ); } elseif ( isset( $property['items']['properties'] ) ) { @@ -294,7 +294,7 @@ public function get_endpoint_args_for_item_schema( $method = \WP_REST_Server::CR */ protected function force_schema_readonly( $properties ) { return array_map( - function( $property ) { + function ( $property ) { $property['readonly'] = true; if ( isset( $property['items']['properties'] ) ) { $property['items']['properties'] = $this->force_schema_readonly( $property['items']['properties'] ); diff --git a/src/StoreApi/Schemas/V1/CartShippingRateSchema.php b/src/StoreApi/Schemas/V1/CartShippingRateSchema.php index cc5a39211df..6b27a973010 100644 --- a/src/StoreApi/Schemas/V1/CartShippingRateSchema.php +++ b/src/StoreApi/Schemas/V1/CartShippingRateSchema.php @@ -341,7 +341,7 @@ protected function get_rate_meta_data( $rate ) { return array_reduce( array_keys( $meta_data ), - function( $return, $key ) use ( $meta_data ) { + function ( $return, $key ) use ( $meta_data ) { $return[] = [ 'key' => $key, 'value' => $meta_data[ $key ], diff --git a/src/StoreApi/Schemas/V1/CheckoutSchema.php b/src/StoreApi/Schemas/V1/CheckoutSchema.php index 3a84f9c0759..b1d67793bd3 100644 --- a/src/StoreApi/Schemas/V1/CheckoutSchema.php +++ b/src/StoreApi/Schemas/V1/CheckoutSchema.php @@ -220,7 +220,7 @@ protected function get_checkout_response( \WC_Order $order, PaymentResult $payme */ protected function prepare_payment_details_for_response( array $payment_details ) { return array_map( - function( $key, $value ) { + function ( $key, $value ) { return (object) [ 'key' => $key, 'value' => $value, diff --git a/src/StoreApi/Schemas/V1/ErrorSchema.php b/src/StoreApi/Schemas/V1/ErrorSchema.php index 564e9e3a308..4f534ad91fa 100644 --- a/src/StoreApi/Schemas/V1/ErrorSchema.php +++ b/src/StoreApi/Schemas/V1/ErrorSchema.php @@ -53,5 +53,4 @@ public function get_item_response( $error ) { 'message' => $this->prepare_html_response( $error->get_error_message() ), ]; } - } diff --git a/src/StoreApi/Schemas/V1/ImageAttachmentSchema.php b/src/StoreApi/Schemas/V1/ImageAttachmentSchema.php index 036c3823369..d8199b3be75 100644 --- a/src/StoreApi/Schemas/V1/ImageAttachmentSchema.php +++ b/src/StoreApi/Schemas/V1/ImageAttachmentSchema.php @@ -95,5 +95,4 @@ public function get_item_response( $attachment_id ) { 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), ]; } - } diff --git a/src/StoreApi/Schemas/V1/OrderSchema.php b/src/StoreApi/Schemas/V1/OrderSchema.php index f017488c77c..1fc98f5f9c6 100644 --- a/src/StoreApi/Schemas/V1/OrderSchema.php +++ b/src/StoreApi/Schemas/V1/OrderSchema.php @@ -347,7 +347,7 @@ protected function get_totals( $order ) { 'total_items' => $this->prepare_money_response( array_sum( array_map( - function( $item ) { + function ( $item ) { return $item->get_total(); }, array_values( $order->get_items( 'line_item' ) ) @@ -357,7 +357,7 @@ function( $item ) { 'total_items_tax' => $this->prepare_money_response( array_sum( array_map( - function( $item ) { + function ( $item ) { return $item->get_tax_total(); }, array_values( $order->get_items( 'tax' ) ) @@ -367,7 +367,7 @@ function( $item ) { 'total_fees_tax' => $this->prepare_money_response( array_sum( array_map( - function( $item ) { + function ( $item ) { return $item->get_total_tax(); }, array_values( $order->get_items( 'fee' ) ) @@ -377,7 +377,7 @@ function( $item ) { 'total_discount_tax' => $this->prepare_money_response( $order->get_discount_tax() ), 'total_shipping_tax' => $this->prepare_money_response( $order->get_shipping_tax() ), 'tax_lines' => array_map( - function( $item ) { + function ( $item ) { return [ 'name' => $item->get_name(), 'price' => $item->get_tax_total(), diff --git a/src/StoreApi/Schemas/V1/ProductSchema.php b/src/StoreApi/Schemas/V1/ProductSchema.php index 9d7935b9d7b..f4e41d5e3c2 100644 --- a/src/StoreApi/Schemas/V1/ProductSchema.php +++ b/src/StoreApi/Schemas/V1/ProductSchema.php @@ -578,7 +578,7 @@ protected function get_variations( \WC_Product $product ) { $attributes = array_filter( $product->get_attributes(), [ $this, 'filter_variation_attribute' ] ); $default_variation_meta_data = array_reduce( $attributes, - function( $defaults, $attribute ) use ( $product ) { + function ( $defaults, $attribute ) use ( $product ) { $meta_key = wc_variation_attribute_name( $attribute->get_name() ); $defaults[ $meta_key ] = [ 'name' => wc_attribute_label( $attribute->get_name(), $product ), @@ -627,7 +627,7 @@ function( $defaults, $attribute ) use ( $product ) { */ $attributes_by_variation = array_reduce( $variation_meta_data, - function( $values, $data ) use ( $default_variation_meta_keys ) { + function ( $values, $data ) use ( $default_variation_meta_keys ) { // The query above only includes the keys of $default_variation_meta_data so we know all of the attributes // being processed here apply to this product. However, we need an additional check here because the // cache may have been primed elsewhere and include keys from other products. diff --git a/src/StoreApi/StoreApi.php b/src/StoreApi/StoreApi.php index 7b740e37a2e..ed33e921247 100644 --- a/src/StoreApi/StoreApi.php +++ b/src/StoreApi/StoreApi.php @@ -22,7 +22,7 @@ final class StoreApi { public function init() { add_action( 'rest_api_init', - function() { + function () { self::container()->get( Legacy::class )->init(); self::container()->get( RoutesController::class )->register_all_routes(); } @@ -30,7 +30,7 @@ function() { // Runs on priority 11 after rest_api_default_filters() which is hooked at 10. add_action( 'rest_api_init', - function() { + function () { self::container()->get( Authentication::class )->init(); }, 11 diff --git a/src/StoreApi/Utilities/ArrayUtils.php b/src/StoreApi/Utilities/ArrayUtils.php index e1cc9e404fe..eb36e31d4b1 100644 --- a/src/StoreApi/Utilities/ArrayUtils.php +++ b/src/StoreApi/Utilities/ArrayUtils.php @@ -16,7 +16,7 @@ class ArrayUtils { public static function natural_language_join( $array, $enclose_items_with_quotes = false ) { if ( true === $enclose_items_with_quotes ) { $array = array_map( - function( $item ) { + function ( $item ) { return '"' . $item . '"'; }, $array diff --git a/src/StoreApi/Utilities/CartController.php b/src/StoreApi/Utilities/CartController.php index ec0cccde5a5..32004a57a9e 100644 --- a/src/StoreApi/Utilities/CartController.php +++ b/src/StoreApi/Utilities/CartController.php @@ -820,7 +820,7 @@ public function get_shipping_packages( $calculate_rates = true ) { // Add extra package data to array. if ( count( $packages ) ) { $packages = array_map( - function( $key, $package, $index ) { + function ( $key, $package, $index ) { $package['package_id'] = isset( $package['package_id'] ) ? $package['package_id'] : $key; $package['package_name'] = isset( $package['package_name'] ) ? $package['package_name'] : $this->get_package_name( $package, $index ); return $package; @@ -934,7 +934,7 @@ public function apply_coupon( $coupon_code ) { // Prevents new coupons being added if individual use coupons are already in the cart. $individual_use_coupons = $this->get_cart_coupons( - function( $code ) { + function ( $code ) { $coupon = new \WC_Coupon( $code ); return $coupon->get_individual_use(); } diff --git a/src/StoreApi/Utilities/LocalPickupUtils.php b/src/StoreApi/Utilities/LocalPickupUtils.php index 29cff3b2142..bbc7b293b63 100644 --- a/src/StoreApi/Utilities/LocalPickupUtils.php +++ b/src/StoreApi/Utilities/LocalPickupUtils.php @@ -24,7 +24,7 @@ public static function is_local_pickup_enabled() { public static function get_local_pickup_method_ids() { $all_methods_supporting_local_pickup = array_reduce( WC()->shipping()->get_shipping_methods(), - function( $methods, $method ) { + function ( $methods, $method ) { if ( $method->supports( 'local-pickup' ) ) { $methods[] = $method->id; } diff --git a/src/StoreApi/Utilities/OrderAuthorizationTrait.php b/src/StoreApi/Utilities/OrderAuthorizationTrait.php index 0c5c3d0c632..a9b8442c6ed 100644 --- a/src/StoreApi/Utilities/OrderAuthorizationTrait.php +++ b/src/StoreApi/Utilities/OrderAuthorizationTrait.php @@ -58,5 +58,4 @@ public function validate_billing_email_matches_order( $order_id, $billing_email throw new RouteException( 'woocommerce_rest_invalid_billing_email', __( 'Invalid billing email provided.', 'woo-gutenberg-products-block' ), 401 ); } } - } diff --git a/src/StoreApi/Utilities/OrderController.php b/src/StoreApi/Utilities/OrderController.php index 223f7bdd7eb..dc3a38c0f85 100644 --- a/src/StoreApi/Utilities/OrderController.php +++ b/src/StoreApi/Utilities/OrderController.php @@ -1,7 +1,7 @@ customer ) ) { @@ -134,7 +134,7 @@ public function sync_customer_data_with_order( \WC_Order $order ) { ); $customer->save(); - }; + } } /** @@ -181,7 +181,7 @@ protected function validate_coupons( \WC_Order $order ) { try { array_walk( $validators, - function( $validator, $index, $params ) { + function ( $validator, $index, $params ) { call_user_func_array( [ $this, $validator ], $params ); }, [ $coupon, $order ] diff --git a/src/Templates/AbstractTemplateCompatibility.php b/src/Templates/AbstractTemplateCompatibility.php index ee5c4f45384..4be6da10d7a 100644 --- a/src/Templates/AbstractTemplateCompatibility.php +++ b/src/Templates/AbstractTemplateCompatibility.php @@ -29,7 +29,7 @@ public function init() { add_filter( 'render_block_data', - function( $parsed_block, $source_block, $parent_block ) { + function ( $parsed_block, $source_block, $parent_block ) { /** * Filter to disable the compatibility layer for the blockified templates. * @@ -45,7 +45,6 @@ function( $parsed_block, $source_block, $parent_block ) { } return $this->update_render_block_data( $parsed_block, $source_block, $parent_block ); - }, 10, 3 diff --git a/src/Templates/ArchiveProductTemplatesCompatibility.php b/src/Templates/ArchiveProductTemplatesCompatibility.php index cfbd2c447a1..412bdfbdfa2 100644 --- a/src/Templates/ArchiveProductTemplatesCompatibility.php +++ b/src/Templates/ArchiveProductTemplatesCompatibility.php @@ -78,7 +78,7 @@ public function inject_hooks( $block_content, $block ) { $block_hooks = array_filter( $this->hook_data, - function( $hook ) use ( $block_name ) { + function ( $hook ) use ( $block_name ) { return in_array( $block_name, $hook['block_names'], true ); } ); @@ -100,7 +100,7 @@ function( $hook ) use ( $block_name ) { $supported_blocks = array_merge( [], ...array_map( - function( $hook ) { + function ( $hook ) { return $hook['block_names']; }, array_values( $this->hook_data ) diff --git a/src/Templates/CheckoutHeaderTemplate.php b/src/Templates/CheckoutHeaderTemplate.php index daefdac72d5..4bfc35516c9 100644 --- a/src/Templates/CheckoutHeaderTemplate.php +++ b/src/Templates/CheckoutHeaderTemplate.php @@ -9,5 +9,4 @@ class CheckoutHeaderTemplate { const SLUG = 'checkout-header'; - } diff --git a/src/Templates/MiniCartTemplate.php b/src/Templates/MiniCartTemplate.php index 8f49b7643c7..5dc3ecce6b2 100644 --- a/src/Templates/MiniCartTemplate.php +++ b/src/Templates/MiniCartTemplate.php @@ -9,5 +9,4 @@ class MiniCartTemplate { const SLUG = 'mini-cart'; - } diff --git a/src/Templates/SingleProductTemplate.php b/src/Templates/SingleProductTemplate.php index a03d0d29783..422e58e6995 100644 --- a/src/Templates/SingleProductTemplate.php +++ b/src/Templates/SingleProductTemplate.php @@ -21,7 +21,7 @@ private static function replace_first_single_product_template_block_with_passwor $single_product_template_blocks = array( 'woocommerce/product-image-gallery', 'woocommerce/product-details', 'woocommerce/add-to-cart-form', 'woocommerce/product-meta', 'woocommerce/product-rating', 'woocommerce/product-price', 'woocommerce/related-products' ); return array_reduce( $parsed_blocks, - function( $carry, $block ) use ( $single_product_template_blocks ) { + function ( $carry, $block ) use ( $single_product_template_blocks ) { if ( in_array( $block['blockName'], $single_product_template_blocks, true ) ) { if ( $carry['is_already_replaced'] ) { return array( diff --git a/src/Templates/SingleProductTemplateCompatibility.php b/src/Templates/SingleProductTemplateCompatibility.php index 56e92808cd7..c0ea67f2a57 100644 --- a/src/Templates/SingleProductTemplateCompatibility.php +++ b/src/Templates/SingleProductTemplateCompatibility.php @@ -31,7 +31,7 @@ public function inject_hooks( $block_content, $block ) { $block_hooks = array_filter( $this->hook_data, - function( $hook ) use ( $block_name ) { + function ( $hook ) use ( $block_name ) { return in_array( $block_name, $hook['block_names'], true ); } ); @@ -283,7 +283,7 @@ private static function wrap_single_product_template( $template_content ) { $grouped_blocks = self::group_blocks( $parsed_blocks ); $wrapped_blocks = array_map( - function( $blocks ) { + function ( $blocks ) { if ( 'core/template-part' === $blocks[0]['blockName'] ) { return $blocks; } @@ -310,7 +310,7 @@ function( $blocks ) { private static function inject_custom_attributes_to_first_and_last_block_single_product_template( $wrapped_blocks ) { $template_with_custom_attributes = array_reduce( $wrapped_blocks, - function( $carry, $item ) { + function ( $carry, $item ) { $index = $carry['index']; $carry['index'] = $carry['index'] + 1; @@ -383,7 +383,6 @@ private static function create_wrap_block_group( $blocks ) { $new_block['innerBlocks'] = $blocks; return $new_block; - } /** @@ -425,7 +424,7 @@ private static function has_single_product_template_blocks( $parsed_blocks ) { private static function group_blocks( $parsed_blocks ) { return array_reduce( $parsed_blocks, - function( $carry, $block ) { + function ( $carry, $block ) { if ( 'core/template-part' === $block['blockName'] ) { $carry[] = array( $block ); return $carry; @@ -484,7 +483,7 @@ private static function is_custom_html( $block ) { private static function serialize_blocks( $parsed_blocks ) { return array_reduce( $parsed_blocks, - function( $carry, $item ) { + function ( $carry, $item ) { if ( is_array( $item ) ) { return $carry . serialize_blocks( $item ); } diff --git a/src/Utils/BlockTemplateUtils.php b/src/Utils/BlockTemplateUtils.php index af08452c935..1db40457c8f 100644 --- a/src/Utils/BlockTemplateUtils.php +++ b/src/Utils/BlockTemplateUtils.php @@ -426,7 +426,7 @@ public static function get_theme_template_path( $template_slug, $template_type = // or the stylesheet directory for child themes. $possible_paths = array_reduce( $possible_templates_dir, - function( $carry, $item ) use ( $template_filename ) { + function ( $carry, $item ) use ( $template_filename ) { $filepath = DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . $template_filename; $carry[] = get_stylesheet_directory() . $filepath; @@ -502,7 +502,6 @@ public static function get_block_template( $id, $template_type ) { } return null; - } /** @@ -632,7 +631,7 @@ public static function filter_block_templates_by_feature_flag( $block_templates return array_filter( $block_templates, - function( $block_template ) use ( $flag, $block_templates_with_feature_gate ) { + function ( $block_template ) use ( $flag, $block_templates_with_feature_gate ) { if ( isset( $block_templates_with_feature_gate[ $block_template->slug ] ) ) { return $block_templates_with_feature_gate[ $block_template->slug ] <= $flag; } @@ -652,13 +651,13 @@ public static function remove_theme_templates_with_custom_alternative( $template // Get the slugs of all templates that have been customised and saved in the database. $customised_template_slugs = array_map( - function( $template ) { + function ( $template ) { return $template->slug; }, array_values( array_filter( $templates, - function( $template ) { + function ( $template ) { // This template has been customised and saved as a post. return 'custom' === $template->source; } @@ -673,7 +672,7 @@ function( $template ) { return array_values( array_filter( $templates, - function( $template ) use ( $customised_template_slugs ) { + function ( $template ) use ( $customised_template_slugs ) { // This template has been customised and saved as a post, so return it. return ! ( 'theme' === $template->source && in_array( $template->slug, $customised_template_slugs, true ) ); } @@ -754,7 +753,7 @@ public static function get_block_templates_from_db( $slugs = array(), $template_ $saved_woo_templates = $check_query->posts; return array_map( - function( $saved_woo_template ) { + function ( $saved_woo_template ) { return self::build_template_result_from_post( $saved_woo_template ); }, $saved_woo_templates diff --git a/src/Utils/CartCheckoutUtils.php b/src/Utils/CartCheckoutUtils.php index e1d74d2c65e..0e4220a8756 100644 --- a/src/Utils/CartCheckoutUtils.php +++ b/src/Utils/CartCheckoutUtils.php @@ -94,7 +94,7 @@ protected static function deep_sort_with_accents( $array ) { } $array_without_accents = array_map( - function( $value ) { + function ( $value ) { return is_array( $value ) ? self::deep_sort_with_accents( $value ) : remove_accents( wc_strtolower( html_entity_decode( $value ) ) ); diff --git a/src/Utils/StyleAttributesUtils.php b/src/Utils/StyleAttributesUtils.php index 5205dcc3691..119bb06442d 100644 --- a/src/Utils/StyleAttributesUtils.php +++ b/src/Utils/StyleAttributesUtils.php @@ -738,14 +738,14 @@ public static function get_classes_and_styles_by_attributes( $attributes, $prope $classes_and_styles = array_filter( $classes_and_styles ); $classes = array_map( - function( $item ) { + function ( $item ) { return $item['class']; }, $classes_and_styles ); $styles = array_map( - function( $item ) { + function ( $item ) { return $item['style']; }, // Exclude link color styles from parent to avoid conflict with text color.