Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-wp-site-health.php`.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:
* Renames the `$class` parameter to `$class_name` in `WP_Site_Health::test_php_extension_availability()`.
* Renames some other parameters for consistency.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@53117


git-svn-id: http://core.svn.wordpress.org/trunk@52706 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-04-10 14:29:04 +00:00
parent 483a0e38e8
commit 0c12438eed
2 changed files with 23 additions and 17 deletions

View File

@ -802,30 +802,33 @@ class WP_Site_Health {
* Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.
*
* @since 5.2.0
* @since 5.3.0 The `$constant` and `$class` parameters were added.
* @since 5.3.0 The `$constant_name` and `$class_name` parameters were added.
*
* @param string $extension Optional. The extension name to test. Default null.
* @param string $function Optional. The function name to test. Default null.
* @param string $constant Optional. The constant name to test for. Default null.
* @param string $class Optional. The class name to test for. Default null.
* @param string $extension_name Optional. The extension name to test. Default null.
* @param string $function_name Optional. The function name to test. Default null.
* @param string $constant_name Optional. The constant name to test for. Default null.
* @param string $class_name Optional. The class name to test for. Default null.
* @return bool Whether or not the extension and function are available.
*/
private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
private function test_php_extension_availability( $extension_name = null, $function_name = null, $constant_name = null, $class_name = null ) {
// If no extension or function is passed, claim to fail testing, as we have nothing to test against.
if ( ! $extension && ! $function && ! $constant && ! $class ) {
if ( ! $extension_name && ! $function_name && ! $constant_name && ! $class_name ) {
return false;
}
if ( $extension && ! extension_loaded( $extension ) ) {
if ( $extension_name && ! extension_loaded( $extension_name ) ) {
return false;
}
if ( $function && ! function_exists( $function ) ) {
if ( $function_name && ! function_exists( $function_name ) ) {
return false;
}
if ( $constant && ! defined( $constant ) ) {
if ( $constant_name && ! defined( $constant_name ) ) {
return false;
}
if ( $class && ! class_exists( $class ) ) {
if ( $class_name && ! class_exists( $class_name ) ) {
return false;
}
@ -994,10 +997,10 @@ class WP_Site_Health {
$failures = array();
foreach ( $modules as $library => $module ) {
$extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
$function = ( isset( $module['function'] ) ? $module['function'] : null );
$constant = ( isset( $module['constant'] ) ? $module['constant'] : null );
$class_name = ( isset( $module['class'] ) ? $module['class'] : null );
$extension_name = ( isset( $module['extension'] ) ? $module['extension'] : null );
$function_name = ( isset( $module['function'] ) ? $module['function'] : null );
$constant_name = ( isset( $module['constant'] ) ? $module['constant'] : null );
$class_name = ( isset( $module['class'] ) ? $module['class'] : null );
// If this module is a fallback for another function, check if that other function passed.
if ( isset( $module['fallback_for'] ) ) {
@ -1012,7 +1015,10 @@ class WP_Site_Health {
}
}
if ( ! $this->test_php_extension_availability( $extension, $function, $constant, $class_name ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
if ( ! $this->test_php_extension_availability( $extension_name, $function_name, $constant_name, $class_name )
&& ( ! isset( $module['php_bundled_version'] )
|| version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) )
) {
if ( $module['required'] ) {
$result['status'] = 'critical';

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53116';
$wp_version = '6.0-alpha-53117';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.