Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.

This reduces the number of WordPress.PHP.StrictInArray.MissingTrueStrict issues from 486 to 50.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r47280 r47550  
    19141914        if ( $wp_current_db_version < 29630 ) {
    19151915                if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
    1916                         if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages() ) ) {
     1916                        if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages(), true ) ) {
    19171917                                update_option( 'WPLANG', WPLANG );
    19181918                        } else {
     
    26362636        foreach ( $cqueries as $table => $qry ) {
    26372637                // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
    2638                 if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) {
     2638                if ( in_array( $table, $global_tables, true ) && ! wp_should_upgrade_global_tables() ) {
    26392639                        unset( $cqueries[ $table ], $for_update[ $table ] );
    26402640                        continue;
     
    28002800                                if ( $tablefield->Type != $fieldtype ) {
    28012801                                        $do_change = true;
    2802                                         if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) {
    2803                                                 if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) {
     2802                                        if ( in_array( $fieldtype_lowercased, $text_fields, true ) && in_array( $tablefield_type_lowercased, $text_fields, true ) ) {
     2803                                                if ( array_search( $fieldtype_lowercased, $text_fields, true ) < array_search( $tablefield_type_lowercased, $text_fields, true ) ) {
    28042804                                                        $do_change = false;
    28052805                                                }
    28062806                                        }
    28072807
    2808                                         if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) {
    2809                                                 if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) {
     2808                                        if ( in_array( $fieldtype_lowercased, $blob_fields, true ) && in_array( $tablefield_type_lowercased, $blob_fields, true ) ) {
     2809                                                if ( array_search( $fieldtype_lowercased, $blob_fields, true ) < array_search( $tablefield_type_lowercased, $blob_fields, true ) ) {
    28102810                                                        $do_change = false;
    28112811                                                }
     
    29022902
    29032903                                // Check if the index definition exists, ignoring subparts.
    2904                                 $aindex = array_search( $index_string, $indices_without_subparts );
     2904                                $aindex = array_search( $index_string, $indices_without_subparts, true );
    29052905                                if ( false !== $aindex ) {
    29062906                                        // If the index already exists (even with different subparts), we don't need to create it.
     
    32463246        foreach ( (array) $plugins as $plugin ) {
    32473247                if ( basename( $plugin ) == 'widgets.php' ) {
    3248                         array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
     3248                        array_splice( $plugins, array_search( $plugin, $plugins, true ), 1 );
    32493249                        update_option( 'active_plugins', $plugins );
    32503250                        break;
Note: See TracChangeset for help on using the changeset viewer.