Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (5 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/misc.php

    r47219 r47550  
    600600        if ( T_STRING == $tokens[ $t ][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {
    601601            // If it's a function or class defined locally, there's not going to be any docs available.
    602             if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) {
     602            if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) )
     603                || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] )
     604            ) {
    603605                $ignore_functions[] = $tokens[ $t ][1];
    604606            }
     
    624626    $out = array();
    625627    foreach ( $functions as $function ) {
    626         if ( in_array( $function, $ignore_functions ) ) {
     628        if ( in_array( $function, $ignore_functions, true ) ) {
    627629            continue;
    628630        }
     
    657659        $type       = str_replace( 'edit_', '', $map_option );
    658660        $type       = str_replace( '_per_page', '', $type );
    659         if ( in_array( $type, get_taxonomies() ) ) {
     661        if ( in_array( $type, get_taxonomies(), true ) ) {
    660662            $map_option = 'edit_tags_per_page';
    661         } elseif ( in_array( $type, get_post_types() ) ) {
     663        } elseif ( in_array( $type, get_post_types(), true ) ) {
    662664            $map_option = 'edit_per_page';
    663665        } else {
Note: See TracChangeset for help on using the changeset viewer.