Coding Standards: Use strict comparison where static strings are involved.

This reduces the number of `WordPress.PHP.StrictComparisons.LooseComparison` issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.

git-svn-id: https://develop.svn.wordpress.org/trunk@47808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-05-16 18:40:52 +00:00
parent 36e4db6b01
commit 6742d0d7a6
160 changed files with 1143 additions and 1007 deletions
+24 -17
View File
@@ -640,7 +640,7 @@ function is_serialized( $data, $strict = true ) {
return false;
}
$data = trim( $data );
if ( 'N;' == $data ) {
if ( 'N;' === $data ) {
return true;
}
if ( strlen( $data ) < 4 ) {
@@ -1517,7 +1517,7 @@ function get_num_queries() {
* @return bool True if yes, false on anything else.
*/
function bool_from_yn( $yn ) {
return ( strtolower( $yn ) == 'y' );
return ( 'y' === strtolower( $yn ) );
}
/**
@@ -1540,7 +1540,7 @@ function do_feed() {
// Remove the pad, if present.
$feed = preg_replace( '/^_+/', '', $feed );
if ( '' == $feed || 'feed' === $feed ) {
if ( '' === $feed || 'feed' === $feed ) {
$feed = get_default_feed();
}
@@ -1841,6 +1841,7 @@ function wp_referer_field( $echo = true ) {
if ( $echo ) {
echo $referer_field;
}
return $referer_field;
}
@@ -1860,13 +1861,17 @@ function wp_referer_field( $echo = true ) {
*/
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
$ref = wp_get_original_referer();
if ( ! $ref ) {
$ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
$ref = ( 'previous' === $jump_back_to ) ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
}
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
if ( $echo ) {
echo $orig_referer_field;
}
return $orig_referer_field;
}
@@ -1972,7 +1977,7 @@ function wp_mkdir_p( $target ) {
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
@@ -2334,7 +2339,7 @@ function _wp_upload_dir( $time = null ) {
$siteurl = get_option( 'siteurl' );
$upload_path = trim( get_option( 'upload_path' ) );
if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
$dir = WP_CONTENT_DIR . '/uploads';
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH.
@@ -2345,7 +2350,7 @@ function _wp_upload_dir( $time = null ) {
$url = get_option( 'upload_url_path' );
if ( ! $url ) {
if ( empty( $upload_path ) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) {
if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) {
$url = WP_CONTENT_URL . '/uploads';
} else {
$url = trailingslashit( $siteurl ) . $upload_path;
@@ -3211,7 +3216,7 @@ function get_allowed_mime_types( $user = null ) {
* @param string $action The nonce action.
*/
function wp_nonce_ays( $action ) {
if ( 'log-out' == $action ) {
if ( 'log-out' === $action ) {
$html = sprintf(
/* translators: %s: Site title. */
__( 'You are attempting to log out of %s' ),
@@ -3539,7 +3544,7 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
}
<?php
if ( 'rtl' == $text_direction ) {
if ( 'rtl' === $text_direction ) {
echo 'body { font-family: Tahoma, Arial; }';
}
?>
@@ -4333,7 +4338,7 @@ function smilies_init() {
// New subpattern?
if ( $firstchar != $subchar ) {
if ( '' != $subchar ) {
if ( '' !== $subchar ) {
$wp_smiliessearch .= ')(?=' . $spaces . '|$)'; // End previous "subpattern".
$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
}
@@ -5214,7 +5219,8 @@ function _doing_it_wrong( $function, $message, $version ) {
function is_lighttpd_before_150() {
$server_parts = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
$server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
return 'lighttpd' == $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' );
return ( 'lighttpd' === $server_parts[0] && -1 == version_compare( $server_parts[1], '1.5.0' ) );
}
/**
@@ -5248,6 +5254,7 @@ function apache_mod_loaded( $mod, $default = false ) {
return true;
}
}
return $default;
}
@@ -5274,7 +5281,7 @@ function iis7_supports_permalinks() {
* Lastly we make sure that PHP is running via FastCGI. This is important because if it runs
* via ISAPI then pretty permalinks will not work.
*/
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( PHP_SAPI == 'cgi-fcgi' );
$supports_permalinks = class_exists( 'DOMDocument', false ) && isset( $_SERVER['IIS_UrlRewriteModule'] ) && ( 'cgi-fcgi' === PHP_SAPI );
}
/**
@@ -5324,7 +5331,7 @@ function validate_file( $file, $allowed_files = array() ) {
}
// Absolute Windows drive paths are not allowed:
if ( ':' == substr( $file, 1, 1 ) ) {
if ( ':' === substr( $file, 1, 1 ) ) {
return 2;
}
@@ -5364,7 +5371,7 @@ function force_ssl_admin( $force = null ) {
* @return string The guessed URL.
*/
function wp_guess_url() {
if ( defined( 'WP_SITEURL' ) && '' != WP_SITEURL ) {
if ( defined( 'WP_SITEURL' ) && '' !== WP_SITEURL ) {
$url = WP_SITEURL;
} else {
$abspath_fix = str_replace( '\\', '/', ABSPATH );
@@ -5375,7 +5382,7 @@ function wp_guess_url() {
$path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
// The request is for a file in ABSPATH.
} elseif ( $script_filename_dir . '/' == $abspath_fix ) {
} elseif ( $script_filename_dir . '/' === $abspath_fix ) {
// Strip off any file/query params in the path.
$path = preg_replace( '#/[^/]*$#i', '', $_SERVER['PHP_SELF'] );
@@ -5935,7 +5942,7 @@ function wp_scheduled_delete() {
$del_post = get_post( $post_id );
if ( ! $del_post || 'trash' != $del_post->post_status ) {
if ( ! $del_post || 'trash' !== $del_post->post_status ) {
delete_post_meta( $post_id, '_wp_trash_meta_status' );
delete_post_meta( $post_id, '_wp_trash_meta_time' );
} else {
@@ -5953,7 +5960,7 @@ function wp_scheduled_delete() {
$del_comment = get_comment( $comment_id );
if ( ! $del_comment || 'trash' != $del_comment->comment_approved ) {
if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
} else {