Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Rector suggestions for PHP 8.1 #41482

Merged
merged 33 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
368cb00
Apply Rector suggestions
asumaran Nov 15, 2023
ca8f8fe
Add changefile(s) from automation for the following project(s): wooco…
invalid-email-address Nov 15, 2023
6aad3b9
Restore false positive
asumaran Nov 29, 2023
1b49df6
Restore false positive.
asumaran Nov 29, 2023
2b457c9
Ask if $orders is an array
asumaran Nov 29, 2023
ad08d0d
Check if variable is array
asumaran Nov 29, 2023
3cd4fd1
Restore code as taxes is always an array
asumaran Nov 29, 2023
58ba462
Restore false positive
asumaran Nov 29, 2023
503882d
Restore false positive
asumaran Nov 29, 2023
4b77a0c
Simplify variable check
asumaran Nov 29, 2023
5be20ca
Restore false positive
asumaran Nov 29, 2023
95bf621
Restore false positive
asumaran Nov 30, 2023
d1a1dfa
Restore false positive
asumaran Nov 29, 2023
bc77aed
Restore false positives
asumaran Nov 29, 2023
f2a809c
Restore false positives
asumaran Nov 30, 2023
4a86082
Restore false positive
asumaran Nov 30, 2023
5bc27d1
Restore false positive
asumaran Nov 30, 2023
a7e1b08
Restore false positive
asumaran Nov 30, 2023
46e5d73
Remove unnecessary array type casting.
asumaran Nov 30, 2023
2046906
Restore false positive
asumaran Nov 30, 2023
1f75443
Fix lint issues
asumaran Nov 30, 2023
c6a2497
Remove unnecessary default assignment
asumaran Jan 12, 2024
27eed10
Remove unnecessary is_array check
asumaran Jan 12, 2024
7620c9a
Remove unnecessary is_array check
asumaran Jan 12, 2024
0274ebb
Remove unnecessary is_array check
asumaran Jan 12, 2024
48b5787
Change default value from null to false
asumaran Jan 12, 2024
2a9f30e
Remove unnecessary is_array check
asumaran Jan 12, 2024
f052f83
Update changelog entry
asumaran Jan 16, 2024
751334a
Update changelog entry
asumaran Jan 17, 2024
7342f53
Update changelog entry
asumaran Jan 17, 2024
9ac605d
Add changefile(s) from automation for the following project(s): wooco…
invalid-email-address Jan 17, 2024
cf7655b
Update changelog entry
asumaran Jan 17, 2024
ad4e25c
Use self for consistency
asumaran Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/41482-as-update-to-php-81-2
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Apply type checks and enhancements for PHP 8.1
6 changes: 3 additions & 3 deletions plugins/woocommerce/includes/class-wc-product-factory.php
Expand Up @@ -29,18 +29,18 @@ public function get_product( $product_id = false, $deprecated = array() ) {
return false;
}

$product_type = $this->get_product_type( $product_id );
$product_type = self::get_product_type( $product_id );

// Backwards compatibility.
if ( ! empty( $deprecated ) ) {
wc_deprecated_argument( 'args', '3.0', 'Passing args to the product factory is deprecated. If you need to force a type, construct the product class directly.' );

if ( isset( $deprecated['product_type'] ) ) {
$product_type = $this->get_classname_from_product_type( $deprecated['product_type'] );
$product_type = self::get_classname_from_product_type( $deprecated['product_type'] );
}
}

$classname = $this->get_product_classname( $product_id, $product_type );
$classname = self::get_product_classname( $product_id, $product_type );

try {
return new $classname( $product_id, $deprecated );
Expand Down
4 changes: 2 additions & 2 deletions plugins/woocommerce/includes/class-wc-query.php
Expand Up @@ -554,7 +554,7 @@ public function product_query( $q ) {
*/
private function product_query_post_clauses( $args, $wp_query ) {
$args = $this->price_filter_post_clauses( $args, $wp_query );
$args = $this->filterer->filter_by_attribute_post_clauses( $args, $wp_query, $this->get_layered_nav_chosen_attributes() );
$args = $this->filterer->filter_by_attribute_post_clauses( $args, $wp_query, self::get_layered_nav_chosen_attributes() );

return $args;
}
Expand Down Expand Up @@ -790,7 +790,7 @@ public function get_tax_query( $tax_query = array(), $main_query = false ) {

if ( $main_query && ! $this->filterer->filtering_via_lookup_table_is_active() ) {
// Layered nav filters on terms.
foreach ( $this->get_layered_nav_chosen_attributes() as $taxonomy => $data ) {
foreach ( self::get_layered_nav_chosen_attributes() as $taxonomy => $data ) {
$tax_query[] = array(
'taxonomy' => $taxonomy,
'field' => 'slug',
Expand Down
11 changes: 6 additions & 5 deletions plugins/woocommerce/includes/class-wc-tracker.php
Expand Up @@ -625,8 +625,8 @@ function( $a, $b ) {
$curr_tokens = preg_split( '/[ :,\-_]+/', $key );
$prev_tokens = preg_split( '/[ :,\-_]+/', $prev );

$len_curr = count( $curr_tokens );
$len_prev = count( $prev_tokens );
$len_curr = is_array( $curr_tokens ) ? count( $curr_tokens ) : 0;
$len_prev = is_array( $prev_tokens ) ? count( $prev_tokens ) : 0;

$index_unique = -1;
// Gather the common tokens.
Expand All @@ -640,7 +640,7 @@ function( $a, $b ) {
}

// If only one token is different, and those tokens contain digits, then that could be the unique id.
if ( count( $curr_tokens ) - count( $comm_tokens ) <= 1 && count( $comm_tokens ) > 0 && $index_unique > -1 ) {
if ( $len_curr - count( $comm_tokens ) <= 1 && count( $comm_tokens ) > 0 && $index_unique > -1 ) {
$objects[ $key ]->group_key = implode( ' ', $comm_tokens );
$objects[ $prev ]->group_key = implode( ' ', $comm_tokens );
} else {
Expand Down Expand Up @@ -1072,8 +1072,9 @@ public static function get_block_tracker_data( $block_name, $woo_page_name ) {
* - pickup_locations_count
*/
public static function get_pickup_location_data() {
$pickup_location_enabled = false;
$pickup_locations_count = count( get_option( 'pickup_location_pickup_locations', array() ) );
$pickup_location_enabled = false;
$pickup_location_pickup_locations = get_option( 'pickup_location_pickup_locations', array() );
$pickup_locations_count = is_countable( $pickup_location_pickup_locations ) ? count( $pickup_location_pickup_locations ) : 0;

// Get the available shipping methods.
$shipping_methods = WC()->shipping()->get_shipping_methods();
Expand Down
Expand Up @@ -89,6 +89,7 @@ public function trigger( $order_id, $order = false ) {
$order = wc_get_order( $order_id );
}

$email_already_sent = false;
if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
Expand Down
Expand Up @@ -236,6 +236,7 @@ private function load_shipping_method_options() {

$data_store = WC_Data_Store::load( 'shipping-zone' );
$raw_zones = $data_store->get_zones();
$zones = array();

foreach ( $raw_zones as $raw_zone ) {
$zones[] = new WC_Shipping_Zone( $raw_zone );
Expand Down Expand Up @@ -327,7 +328,7 @@ private function get_canonical_package_rate_ids( $chosen_package_rate_ids ) {
* @since 3.4.0
*
* @param array $rate_ids Rate ids to check.
* @return boolean
* @return array
*/
private function get_matching_rates( $rate_ids ) {
// First, match entries in 'method_id:instance_id' format. Then, match entries in 'method_id' format by stripping off the instance ID from the candidates.
Expand Down
Expand Up @@ -418,11 +418,11 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
$result = WC_Gateway_Paypal_API_Handler::refund_transaction( $order, $amount, $reason );

if ( is_wp_error( $result ) ) {
$this->log( 'Refund Failed: ' . $result->get_error_message(), 'error' );
static::log( 'Refund Failed: ' . $result->get_error_message(), 'error' );
return new WP_Error( 'error', $result->get_error_message() );
}

$this->log( 'Refund Result: ' . wc_print_r( $result, true ) );
static::log( 'Refund Result: ' . wc_print_r( $result, true ) );

switch ( strtolower( $result->ACK ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
case 'success':
Expand Down Expand Up @@ -450,13 +450,13 @@ public function capture_payment( $order_id ) {
$result = WC_Gateway_Paypal_API_Handler::do_capture( $order );

if ( is_wp_error( $result ) ) {
$this->log( 'Capture Failed: ' . $result->get_error_message(), 'error' );
static::log( 'Capture Failed: ' . $result->get_error_message(), 'error' );
/* translators: %s: Paypal gateway error message */
$order->add_order_note( sprintf( __( 'Payment could not be captured: %s', 'woocommerce' ), $result->get_error_message() ) );
return;
}

$this->log( 'Capture Result: ' . wc_print_r( $result, true ) );
static::log( 'Capture Result: ' . wc_print_r( $result, true ) );

// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( ! empty( $result->PAYMENTSTATUS ) ) {
Expand Down