Make WordPress Core


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

    r47461 r47550  
    425425
    426426    // Handle disabled tags.
    427     if ( in_array( $tag, $disabled_elements ) ) {
     427    if ( in_array( $tag, $disabled_elements, true ) ) {
    428428        if ( $opening_tag ) {
    429429            /*
     
    979979    }
    980980
    981     if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
     981    if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ), true ) ) {
    982982        $charset = 'UTF-8';
    983983    }
     
    11241124    static $is_utf8 = null;
    11251125    if ( ! isset( $is_utf8 ) ) {
    1126         $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
     1126        $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ), true );
    11271127    }
    11281128    if ( ! $is_utf8 ) {
     
    28772877
    28782878    // Removed trailing [.,;:)] from URL.
    2879     if ( in_array( substr( $dest, -1 ), array( '.', ',', ';', ':', ')' ) ) === true ) {
    2880         $ret  = substr( $dest, -1 );
     2879    $last_char = substr( $dest, -1 );
     2880    if ( in_array( $last_char, array( '.', ',', ';', ':', ')' ), true ) === true ) {
     2881        $ret  = $last_char;
    28812882        $dest = substr( $dest, 0, strlen( $dest ) - 1 );
    28822883    }
     
    33063307
    33073308    // Don't convert smilies that aren't images - they're probably emoji.
    3308     if ( ! in_array( $ext, $image_exts ) ) {
     3309    if ( ! in_array( $ext, $image_exts, true ) ) {
    33093310        return $img;
    33103311    }
     
    43124313     * starting with /, # or ?, or a PHP file).
    43134314     */
    4314     if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
     4315    if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
    43154316        ! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) ) {
    43164317        $url = 'http://' . $url;
     
    47164717                $allowed[] = WPLANG;
    47174718            }
    4718             if ( ! in_array( $value, $allowed ) && ! empty( $value ) ) {
     4719            if ( ! in_array( $value, $allowed, true ) && ! empty( $value ) ) {
    47194720                $value = get_option( $option );
    47204721            }
     
    47644765        case 'timezone_string':
    47654766            $allowed_zones = timezone_identifiers_list();
    4766             if ( ! in_array( $value, $allowed_zones ) && ! empty( $value ) ) {
     4767            if ( ! in_array( $value, $allowed_zones, true ) && ! empty( $value ) ) {
    47674768                $error = __( 'The timezone you have entered is not valid. Please select a valid timezone.' );
    47684769            }
     
    51465147    // 1 = attribute name  2 = quotation mark  3 = URL.
    51475148    return $m[1] . '=' . $m[2] .
    5148         ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols() ) ?
     5149        ( preg_match( '#^(\w{1,20}):#', $m[3], $protocol ) && in_array( $protocol[1], wp_allowed_protocols(), true ) ?
    51495150            $m[3] :
    51505151            WP_Http::make_absolute_url( $m[3], $_links_add_base )
Note: See TracChangeset for help on using the changeset viewer.