Make WordPress Core


Ignore:
Timestamp:
04/10/2022 02:27:31 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r52978 r53117  
    803803     *
    804804     * @since 5.2.0
    805      * @since 5.3.0 The `$constant` and `$class` parameters were added.
    806      *
    807      * @param string $extension Optional. The extension name to test. Default null.
    808      * @param string $function  Optional. The function name to test. Default null.
    809      * @param string $constant  Optional. The constant name to test for. Default null.
    810      * @param string $class     Optional. The class name to test for. Default null.
     805     * @since 5.3.0 The `$constant_name` and `$class_name` parameters were added.
     806     *
     807     * @param string $extension_name Optional. The extension name to test. Default null.
     808     * @param string $function_name  Optional. The function name to test. Default null.
     809     * @param string $constant_name  Optional. The constant name to test for. Default null.
     810     * @param string $class_name     Optional. The class name to test for. Default null.
    811811     * @return bool Whether or not the extension and function are available.
    812812     */
    813     private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
     813    private function test_php_extension_availability( $extension_name = null, $function_name = null, $constant_name = null, $class_name = null ) {
    814814        // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
    815         if ( ! $extension && ! $function && ! $constant && ! $class ) {
     815        if ( ! $extension_name && ! $function_name && ! $constant_name && ! $class_name ) {
    816816            return false;
    817817        }
    818818
    819         if ( $extension && ! extension_loaded( $extension ) ) {
     819        if ( $extension_name && ! extension_loaded( $extension_name ) ) {
    820820            return false;
    821821        }
    822         if ( $function && ! function_exists( $function ) ) {
     822
     823        if ( $function_name && ! function_exists( $function_name ) ) {
    823824            return false;
    824825        }
    825         if ( $constant && ! defined( $constant ) ) {
     826
     827        if ( $constant_name && ! defined( $constant_name ) ) {
    826828            return false;
    827829        }
    828         if ( $class && ! class_exists( $class ) ) {
     830
     831        if ( $class_name && ! class_exists( $class_name ) ) {
    829832            return false;
    830833        }
     
    995998
    996999        foreach ( $modules as $library => $module ) {
    997             $extension  = ( isset( $module['extension'] ) ? $module['extension'] : null );
    998             $function   = ( isset( $module['function'] ) ? $module['function'] : null );
    999             $constant   = ( isset( $module['constant'] ) ? $module['constant'] : null );
    1000             $class_name = ( isset( $module['class'] ) ? $module['class'] : null );
     1000            $extension_name = ( isset( $module['extension'] ) ? $module['extension'] : null );
     1001            $function_name  = ( isset( $module['function'] ) ? $module['function'] : null );
     1002            $constant_name  = ( isset( $module['constant'] ) ? $module['constant'] : null );
     1003            $class_name     = ( isset( $module['class'] ) ? $module['class'] : null );
    10011004
    10021005            // If this module is a fallback for another function, check if that other function passed.
     
    10131016            }
    10141017
    1015             if ( ! $this->test_php_extension_availability( $extension, $function, $constant, $class_name ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
     1018            if ( ! $this->test_php_extension_availability( $extension_name, $function_name, $constant_name, $class_name )
     1019                && ( ! isset( $module['php_bundled_version'] )
     1020                    || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) )
     1021            ) {
    10161022                if ( $module['required'] ) {
    10171023                    $result['status'] = 'critical';
Note: See TracChangeset for help on using the changeset viewer.