From 0407569382f5b5319040b60b10d1845927620ee5 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Mon, 19 Feb 2024 15:29:16 -0500 Subject: [PATCH] Apply Rector suggestions for PHP 8.1 (#41253) * Apply Rector suggestions * Add changefile(s) from automation for the following project(s): woocommerce * Apply feedback suggestions * Add missing if * Align assignments to satisfy the linter * Move count call outside the loop to satisfy the linter * Escape output to satisfy the linter * Remove unnecessary assignment * Remove unnecessary is_countable check * Remove unnecessary array casting * Restore variable name * Update changelog entry * change static to self for consistency --- .../changelog/41253-as-update-to-php-81 | 4 ++++ .../admin/class-wc-admin-importers.php | 20 ++++++++-------- .../admin/class-wc-admin-webhooks.php | 2 +- .../includes/admin/helper/class-wc-helper.php | 4 ++-- .../importers/class-wc-tax-rate-importer.php | 4 ++-- .../importers/views/html-csv-import-done.php | 2 +- .../class-wc-admin-list-table-coupons.php | 3 +-- .../views/html-product-data-variations.php | 3 +-- .../class-wc-report-sales-by-category.php | 2 +- .../admin/settings/class-wc-settings-tax.php | 4 ++-- .../views/html-admin-page-status-report.php | 24 ++++++++++++------- .../woocommerce/includes/class-wc-ajax.php | 3 ++- .../class-wc-deprecated-action-hooks.php | 8 ------- .../woocommerce/includes/class-wc-geo-ip.php | 8 +++---- 14 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 plugins/woocommerce/changelog/41253-as-update-to-php-81 diff --git a/plugins/woocommerce/changelog/41253-as-update-to-php-81 b/plugins/woocommerce/changelog/41253-as-update-to-php-81 new file mode 100644 index 00000000000..e8be4d9b37e --- /dev/null +++ b/plugins/woocommerce/changelog/41253-as-update-to-php-81 @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Apply type checks and enhancements for PHP 8.1 diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-importers.php b/plugins/woocommerce/includes/admin/class-wc-admin-importers.php index 2d2886afe99..37c59e4dc5b 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-importers.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-importers.php @@ -293,11 +293,11 @@ class WC_Admin_Importers { 'position' => 'done', 'percentage' => 100, 'url' => add_query_arg( array( '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ), - 'imported' => count( $results['imported'] ), - 'imported_variations' => count( $results['imported_variations'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), + 'imported' => is_countable( $results['imported'] ) ? count( $results['imported'] ) : 0, + 'imported_variations' => is_countable( $results['imported_variations'] ) ? count( $results['imported_variations'] ) : 0, + 'failed' => is_countable( $results['failed'] ) ? count( $results['failed'] ) : 0, + 'updated' => is_countable( $results['updated'] ) ? count( $results['updated'] ) : 0, + 'skipped' => is_countable( $results['skipped'] ) ? count( $results['skipped'] ) : 0, ) ); } else { @@ -305,11 +305,11 @@ class WC_Admin_Importers { array( 'position' => $importer->get_file_position(), 'percentage' => $percent_complete, - 'imported' => count( $results['imported'] ), - 'imported_variations' => count( $results['imported_variations'] ), - 'failed' => count( $results['failed'] ), - 'updated' => count( $results['updated'] ), - 'skipped' => count( $results['skipped'] ), + 'imported' => is_countable( $results['imported'] ) ? count( $results['imported'] ) : 0, + 'imported_variations' => is_countable( $results['imported_variations'] ) ? count( $results['imported_variations'] ) : 0, + 'failed' => is_countable( $results['failed'] ) ? count( $results['failed'] ) : 0, + 'updated' => is_countable( $results['updated'] ) ? count( $results['updated'] ) : 0, + 'skipped' => is_countable( $results['skipped'] ) ? count( $results['skipped'] ) : 0, ) ); } diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php b/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php index d5c4862963d..8feac7bc5a6 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-webhooks.php @@ -192,7 +192,7 @@ class WC_Admin_Webhooks { $webhook_id = absint( $_GET['delete'] ); if ( $webhook_id ) { - $this->bulk_delete( array( $webhook_id ) ); + self::bulk_delete( array( $webhook_id ) ); } } } diff --git a/plugins/woocommerce/includes/admin/helper/class-wc-helper.php b/plugins/woocommerce/includes/admin/helper/class-wc-helper.php index f93ab209cd7..fd264411104 100644 --- a/plugins/woocommerce/includes/admin/helper/class-wc-helper.php +++ b/plugins/woocommerce/includes/admin/helper/class-wc-helper.php @@ -408,7 +408,7 @@ class WC_Helper { } $filters = array_fill_keys( array_keys( self::get_filters() ), 0 ); - if ( empty( $subscriptions ) ) { + if ( ! is_array( $subscriptions ) || empty( $subscriptions ) ) { return array(); } @@ -1461,7 +1461,7 @@ class WC_Helper { if ( is_readable( $txt ) ) { $txt = file_get_contents( $txt ); $txt = preg_split( '#\s#', $txt ); - if ( count( $txt ) >= 2 ) { + if ( is_array( $txt ) && count( $txt ) >= 2 ) { $header = sprintf( '%d:%s', $txt[0], $txt[1] ); } } diff --git a/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php b/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php index e07375ffd97..a32b9e9d5d7 100644 --- a/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php +++ b/plugins/woocommerce/includes/admin/importers/class-wc-tax-rate-importer.php @@ -146,8 +146,8 @@ class WC_Tax_Rate_Importer extends WP_Importer { if ( false !== $handle ) { $header = fgetcsv( $handle, 0, $this->delimiter ); - - if ( 10 === count( $header ) ) { + $count = is_countable( $header ) ? count( $header ) : 0; + if ( 10 === $count ) { $row = fgetcsv( $handle, 0, $this->delimiter ); diff --git a/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php b/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php index 70ef0ddd651..d74a37eebd7 100644 --- a/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php +++ b/plugins/woocommerce/includes/admin/importers/views/html-csv-import-done.php @@ -80,7 +80,7 @@ if ( ! defined( 'ABSPATH' ) ) { object->get_product_ids(); - - if ( count( $product_ids ) > 0 ) { + if ( is_array( $product_ids ) && count( $product_ids ) > 0 ) { echo esc_html( implode( ', ', $product_ids ) ); } else { echo '–'; diff --git a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php index dca2695ca46..3292ec3d1d6 100644 --- a/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php +++ b/plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-variations.php @@ -15,8 +15,7 @@ $arrow_img_url = WC_ADMIN_IMAGES_FOLDER_URL . '/product_data/no-variati ?>