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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47550 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-04-05 03:00:44 +00:00
parent 2e589142eb
commit 0b4e2c4604
140 changed files with 584 additions and 484 deletions

View File

@@ -2734,7 +2734,7 @@ function wp_ext2type( $ext ) {
$ext2type = wp_get_ext_types();
foreach ( $ext2type as $type => $exts ) {
if ( in_array( $ext, $exts ) ) {
if ( in_array( $ext, $exts, true ) ) {
return $type;
}
}
@@ -2881,7 +2881,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
*/
if ( in_array( $real_mime, $nonspecific_types, true ) ) {
// File is a non-specific binary type. That's ok if it's a type that generally tends to be binary.
if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ) ) ) {
if ( ! in_array( substr( $type, 0, strcspn( $type, '/' ) ), array( 'application', 'video', 'audio' ), true ) ) {
$type = false;
$ext = false;
}
@@ -2905,7 +2905,8 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
'text/richtext',
'text/tsv',
'text/vtt',
)
),
true
)
) {
$type = false;
@@ -2919,7 +2920,8 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
'text/rtf',
'text/plain',
'application/rtf',
)
),
true
)
) {
$type = false;
@@ -2941,7 +2943,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
if ( $type ) {
$allowed = get_allowed_mime_types();
if ( ! in_array( $type, $allowed ) ) {
if ( ! in_array( $type, $allowed, true ) ) {
$type = false;
$ext = false;
}
@@ -5235,7 +5237,7 @@ function apache_mod_loaded( $mod, $default = false ) {
if ( function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
if ( in_array( $mod, $mods ) ) {
if ( in_array( $mod, $mods, true ) ) {
return true;
}
} elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) {
@@ -5317,7 +5319,7 @@ function validate_file( $file, $allowed_files = array() ) {
}
// Files not in the allowed file list are not allowed:
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files ) ) {
if ( ! empty( $allowed_files ) && ! in_array( $file, $allowed_files, true ) ) {
return 3;
}
@@ -5728,7 +5730,7 @@ function wp_timezone_choice( $selected_zone, $locale = null ) {
$zonen = array();
foreach ( timezone_identifiers_list() as $zone ) {
$zone = explode( '/', $zone );
if ( ! in_array( $zone[0], $continents ) ) {
if ( ! in_array( $zone[0], $continents, true ) ) {
continue;
}
@@ -6316,9 +6318,9 @@ function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr
$caller[] = "{$call['class']}{$call['type']}{$call['function']}";
} else {
if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ) ) ) {
if ( in_array( $call['function'], array( 'do_action', 'apply_filters', 'do_action_ref_array', 'apply_filters_ref_array' ), true ) ) {
$caller[] = "{$call['function']}('{$call['args'][0]}')";
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ) ) ) {
} elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
$filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
$caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
} else {
@@ -6447,7 +6449,7 @@ function wp_auth_check_load() {
$screen = get_current_screen();
$hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
$show = ! in_array( $screen->id, $hidden );
$show = ! in_array( $screen->id, $hidden, true );
/**
* Filters whether to load the authentication check.