mirror of
https://github.com/woocommerce/woocommerce.git
synced 2025-02-15 13:50:34 +08:00
Remove deprecated usage of ${var}
syntax in strings (#36439)
* issue-35763/fix-php-8.2-deprecation-warnings * Declare $mockable_functions property * Declare $mockable_classes property * Fix deprecated usage of ${var} in strings * Add changelog file * Avoid using interpolation to create SQL statement We could ignore the PHPCS error. However, ignoring the error leaves PHPCS unable to detect future changes that may introduce unsafe interpolation. I think the more verbose approach is the safest approach in this case. * Ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared There doesn't seem to be a way to use a variable name for the name of the table without triggering a PHPCS error. * Avoid interpolated passing interpolated variables to __() * End inline comments with a full-stop
This commit is contained in:
parent
f4af1b7a84
commit
6377314b1b
@ -0,0 +1,4 @@
|
||||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix deprecated usage of ${var} in strings
|
@ -267,7 +267,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
|
||||
foreach ( $plugin_suggestions as $plugin_suggestion ) {
|
||||
$alt = str_replace( '.png', '', basename( $plugin_suggestion->image_72x72 ) );
|
||||
// phpcs:ignore
|
||||
echo "<img src='{$plugin_suggestion->image_72x72}' alt='${alt}' width='24' height='24' style='vertical-align: middle; margin-right: 8px;'/>";
|
||||
echo "<img src='{$plugin_suggestion->image_72x72}' alt='{$alt}' width='24' height='24' style='vertical-align: middle; margin-right: 8px;'/>";
|
||||
}
|
||||
echo '& more.';
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ foreach ( $tools as $action_name => $tool ) {
|
||||
echo wp_kses_post( $selector['description'] );
|
||||
}
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo " <select style='width: 300px;' form='form_$action_name' id='selector_$action_name' data-allow_clear='true' class='${selector['class']}' name='${selector['name']}' data-placeholder='${selector['placeholder']}' data-action='${selector['search_action']}'></select>";
|
||||
echo " <select style='width: 300px;' form='form_$action_name' id='selector_$action_name' data-allow_clear='true' class='{$selector['class']}' name='{$selector['name']}' data-placeholder='{$selector['placeholder']}' data-action='{$selector['search_action']}'></select>";
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
|
@ -1701,8 +1701,11 @@ function wc_get_shipping_method_count( $include_legacy = false, $enabled_only =
|
||||
return absint( $transient_value['value'] );
|
||||
}
|
||||
|
||||
$where_clause = $enabled_only ? 'WHERE is_enabled=1' : '';
|
||||
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods ${where_clause}" ) );
|
||||
if ( $enabled_only ) {
|
||||
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods WHERE is_enabled=1" ) );
|
||||
} else {
|
||||
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods" ) );
|
||||
}
|
||||
|
||||
if ( $include_legacy ) {
|
||||
// Count activated methods that don't support shipping zones.
|
||||
|
@ -118,7 +118,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
||||
|
||||
if ( $query_args['customer_type'] ) {
|
||||
$returning_customer = 'returning' === $query_args['customer_type'] ? 1 : 0;
|
||||
$where_subquery[] = "{$order_stats_lookup_table}.returning_customer = ${returning_customer}";
|
||||
$where_subquery[] = "{$order_stats_lookup_table}.returning_customer = {$returning_customer}";
|
||||
}
|
||||
|
||||
$refund_subquery = $this->get_refund_subquery( $query_args );
|
||||
|
@ -378,7 +378,7 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
||||
$this->update_intervals_sql_params( $query_args, $db_interval_count, $expected_interval_count, $table_name );
|
||||
$this->interval_query->add_sql_clause( 'order_by', $this->get_sql_clause( 'order_by' ) );
|
||||
$this->interval_query->add_sql_clause( 'limit', $this->get_sql_clause( 'limit' ) );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX(${table_name}.date_created) AS datetime_anchor" );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX({$table_name}.date_created) AS datetime_anchor" );
|
||||
if ( '' !== $selections ) {
|
||||
$this->interval_query->add_sql_clause( 'select', ', ' . $selections );
|
||||
}
|
||||
@ -697,7 +697,10 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE ${orders_stats_table} SET returning_customer = CASE WHEN order_id = %d THEN false ELSE true END WHERE customer_id = %d",
|
||||
// phpcs:ignore Generic.Commenting.Todo.TaskFound
|
||||
// TODO: use the %i placeholder to prepare the table name when available in the the minimum required WordPress version.
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
"UPDATE {$orders_stats_table} SET returning_customer = CASE WHEN order_id = %d THEN false ELSE true END WHERE customer_id = %d",
|
||||
$order_id,
|
||||
$customer_id
|
||||
)
|
||||
|
@ -188,7 +188,7 @@ class DataStore extends ProductsDataStore implements DataStoreInterface {
|
||||
|
||||
$this->interval_query->add_sql_clause( 'order_by', $this->get_sql_clause( 'order_by' ) );
|
||||
$this->interval_query->add_sql_clause( 'limit', $this->get_sql_clause( 'limit' ) );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX(${table_name}.date_created) AS datetime_anchor" );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX({$table_name}.date_created) AS datetime_anchor" );
|
||||
if ( '' !== $selections ) {
|
||||
$this->interval_query->add_sql_clause( 'select', ', ' . $selections );
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ class DataStore extends VariationsDataStore implements DataStoreInterface {
|
||||
|
||||
$this->interval_query->add_sql_clause( 'order_by', $this->get_sql_clause( 'order_by' ) );
|
||||
$this->interval_query->add_sql_clause( 'limit', $this->get_sql_clause( 'limit' ) );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX(${table_name}.date_created) AS datetime_anchor" );
|
||||
$this->interval_query->add_sql_clause( 'select', ", MAX({$table_name}.date_created) AS datetime_anchor" );
|
||||
if ( '' !== $selections ) {
|
||||
$this->interval_query->add_sql_clause( 'select', ', ' . $selections );
|
||||
}
|
||||
|
@ -463,10 +463,10 @@ class Menu {
|
||||
? "&post_type={$taxonomy_object->object_type[0]}"
|
||||
: '';
|
||||
$match_expression = 'term.php'; // Match term.php pages.
|
||||
$match_expression .= "(?=.*[?|&]taxonomy=${taxonomy}(&|$|#))"; // Lookahead to match a taxonomy URL param.
|
||||
$match_expression .= "(?=.*[?|&]taxonomy={$taxonomy}(&|$|#))"; // Lookahead to match a taxonomy URL param.
|
||||
$match_expression .= '|'; // Or.
|
||||
$match_expression .= 'edit-tags.php'; // Match edit-tags.php pages.
|
||||
$match_expression .= "(?=.*[?|&]taxonomy=${taxonomy}(&|$|#))"; // Lookahead to match a taxonomy URL param.
|
||||
$match_expression .= "(?=.*[?|&]taxonomy={$taxonomy}(&|$|#))"; // Lookahead to match a taxonomy URL param.
|
||||
|
||||
return array(
|
||||
'default' => array_merge(
|
||||
|
@ -146,7 +146,11 @@ class CustomOrdersTableController {
|
||||
$class_and_method = ( new \ReflectionClass( $this ) )->getShortName() . '::' . __FUNCTION__;
|
||||
wc_doing_it_wrong(
|
||||
$class_and_method,
|
||||
__( "${class_and_method}: The visibility of the custom orders table feature is now handled by the WooCommerce features engine. See the FeaturesController class, or go to WooCommerce - Settings - Advanced - Features.", 'woocommerce' ),
|
||||
sprintf(
|
||||
// translators: %1$s the name of the class and method used.
|
||||
__( '%1$s: The visibility of the custom orders table feature is now handled by the WooCommerce features engine. See the FeaturesController class, or go to WooCommerce - Settings - Advanced - Features.', 'woocommerce' ),
|
||||
$class_and_method
|
||||
),
|
||||
'7.0'
|
||||
);
|
||||
}
|
||||
@ -160,7 +164,11 @@ class CustomOrdersTableController {
|
||||
$class_and_method = ( new \ReflectionClass( $this ) )->getShortName() . '::' . __FUNCTION__;
|
||||
wc_doing_it_wrong(
|
||||
$class_and_method,
|
||||
__( "${class_and_method}: The visibility of the custom orders table feature is now handled by the WooCommerce features engine. See the FeaturesController class, or go to WooCommerce - Settings - Advanced - Features.", 'woocommerce' ),
|
||||
sprintf(
|
||||
// translators: %1$s the name of the class and method used.
|
||||
__( '%1$s: The visibility of the custom orders table feature is now handled by the WooCommerce features engine. See the FeaturesController class, or go to WooCommerce - Settings - Advanced - Features.', 'woocommerce' ),
|
||||
$class_and_method
|
||||
),
|
||||
'7.0'
|
||||
);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class DownloadPermissionsAdjuster {
|
||||
'file' => $file,
|
||||
'data' => (array) $permission->data,
|
||||
);
|
||||
$result['permission_data_by_file_order_user'][ "${file}:${permission_data['user_id']}:${permission_data['order_id']}" ] = $data;
|
||||
$result['permission_data_by_file_order_user'][ "{$file}:{$permission_data['user_id']}:{$permission_data['order_id']}" ] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ class FeaturesController {
|
||||
return NewProductManagementExperience::TOGGLE_OPTION_NAME;
|
||||
}
|
||||
|
||||
return "woocommerce_feature_${feature_id}_enabled";
|
||||
return "woocommerce_feature_{$feature_id}_enabled";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ class FeaturesUtil {
|
||||
|
||||
if ( ! $plugin_id ) {
|
||||
$logger = wc_get_logger();
|
||||
$logger->error( "FeaturesUtil::declare_compatibility: ${plugin_file} is not a known WordPress plugin." );
|
||||
$logger->error( "FeaturesUtil::declare_compatibility: {$plugin_file} is not a known WordPress plugin." );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,13 @@ use ReflectionClass;
|
||||
* executed inside tests (and thus the above example won't stack-overflow).
|
||||
*/
|
||||
final class FunctionsMockerHack extends CodeHack {
|
||||
/**
|
||||
* An array containing the names of the functions that will become mockable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mockable_functions;
|
||||
|
||||
/**
|
||||
* Tokens that precede a non-standalone-function identifier.
|
||||
*
|
||||
|
@ -35,6 +35,12 @@ namespace Automattic\WooCommerce\Testing\Tools\CodeHacking\Hacks;
|
||||
* executed inside tests (and thus the above example won't stack-overflow).
|
||||
*/
|
||||
final class StaticMockerHack extends CodeHack {
|
||||
/**
|
||||
* An associative array of class name => array of class methods.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mockable_classes;
|
||||
|
||||
/**
|
||||
* @var StaticMockerHack Holds the only existing instance of the class.
|
||||
|
@ -165,7 +165,7 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
|
||||
);
|
||||
|
||||
foreach ( $required_strings as $required_string ) {
|
||||
$this->assertRegexp( "/${required_string}/", $html );
|
||||
$this->assertRegexp( "/{$required_string}/", $html );
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ class WC_Admin_Dashboard_Setup_Test extends WC_Unit_Test_Case {
|
||||
if ( $completed_tasks_count === $tasks_count ) {
|
||||
$this->assertEmpty( $this->get_widget_output() );
|
||||
} else {
|
||||
$this->assertRegexp( "/Step ${step_number} of 6/", $this->get_widget_output() );
|
||||
$this->assertRegexp( "/Step {$step_number} of 6/", $this->get_widget_output() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class WC_Settings_Example extends WC_Settings_Page {
|
||||
}
|
||||
|
||||
protected function get_settings_for_section_core( $section_id ) {
|
||||
return array( "${section_id}_key" => "${section_id}_value" );
|
||||
return array( "{$section_id}_key" => "{$section_id}_value" );
|
||||
}
|
||||
|
||||
protected function get_own_sections() {
|
||||
|
@ -419,8 +419,8 @@ class AccessiblePrivateMethodsTest extends \WC_Unit_Test_Case {
|
||||
use AccessiblePrivateMethods;
|
||||
};
|
||||
|
||||
$method_name = "add_${action_or_filter}";
|
||||
$proper_method_name = "add_static_${action_or_filter}";
|
||||
$method_name = "add_{$action_or_filter}";
|
||||
$proper_method_name = "add_static_{$action_or_filter}";
|
||||
|
||||
$this->expectException( \Error::class );
|
||||
$this->expectExceptionMessage( get_class( $sut ) . '::' . "$method_name can't be called statically, did you mean '$proper_method_name'?" );
|
||||
|
@ -70,9 +70,9 @@ if ( $verbose ) {
|
||||
*/
|
||||
function debug( ...$args ) {
|
||||
if ( getenv( 'CI' ) ) {
|
||||
$args[0] = "\e[34m${args[0]}\e[0m\n";
|
||||
$args[0] = "\e[34m{$args[0]}\e[0m\n";
|
||||
} else {
|
||||
$args[0] = "\e[1;30m${args[0]}\e[0m\n";
|
||||
$args[0] = "\e[1;30m{$args[0]}\e[0m\n";
|
||||
}
|
||||
fprintf( STDERR, ...$args );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user