WordPress.org

Make WordPress Core


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

    r47461 r47550  
    27352735    $ext2type = wp_get_ext_types();
    27362736    foreach ( $ext2type as $type => $exts ) {
    2737         if ( in_array( $ext, $exts ) ) {
     2737        if ( in_array( $ext, $exts, true ) ) {
    27382738            return $type;
    27392739        }
     
    28822882        if ( in_array( $real_mime, $nonspecific_types, true ) ) {
    28832883            // File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
    2884             if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
     2884            if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ), true ) ) {
    28852885                $type = false;
    28862886                $ext  = false;
     
    29062906                    'text/tsv',
    29072907                    'text/vtt',
    2908                 )
     2908                ),
     2909                true
    29092910            )
    29102911            ) {
     
    29202921                    'text/plain',
    29212922                    'application/rtf',
    2922                 )
     2923                ),
     2924                true
    29232925            )
    29242926            ) {
     
    29422944        $allowed = get_allowed_mime_types();
    29432945
    2944         if ( ! in_array( $type, $allowed ) ) {
     2946        if ( ! in_array( $type, $allowed, true ) ) {
    29452947            $type = false;
    29462948            $ext  = false;
     
    52365238    if ( function_exists( 'apache_get_modules' ) ) {
    52375239        $mods = apache_get_modules();
    5238         if ( in_array( $mod, $mods ) ) {
     5240        if ( in_array( $mod, $mods, true ) ) {
    52395241            return true;
    52405242        }
     
    53185320
    53195321    // Files not in the allowed file list are not allowed:
    5320     if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) {
     5322    if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files, true ) ) {
    53215323        return 3;
    53225324    }
     
    57295731    foreach ( timezone_identifiers_list() as $zone ) {
    57305732        $zone = explode( '/', $zone );
    5731         if ( ! in_array( $zone[0], $continents ) ) {
     5733        if ( ! in_array( $zone[0], $continents, true ) ) {
    57325734            continue;
    57335735        }
     
    63176319            $caller[] = "{$call['class']}{$call['type']}{$call['function']}";
    63186320        } else {
    6319             if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ) ) ) {
     6321            if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
    63206322                $caller[] = "{$call['function']}('{$call['args'][0]}')";
    6321             } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
     6323            } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
    63226324                $filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
    63236325                $caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
     
    64486450    $screen = get_current_screen();
    64496451    $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
    6450     $show   = ! in_array( $screen->id, $hidden );
     6452    $show   = ! in_array( $screen->id, $hidden, true );
    64516453
    64526454    /**
Note: See TracChangeset for help on using the changeset viewer.