WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (11 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r47783 r47808  
    380380            $sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
    381381        }
    382         if ( '"' == $needle && false !== strpos( $sentence, '"' ) ) {
     382        if ( '"' === $needle && false !== strpos( $sentence, '"' ) ) {
    383383            $sentence = str_replace( '"', $close_quote, $sentence );
    384384        }
     
    19391939        $locale = get_locale();
    19401940
    1941         if ( 'de_DE' == $locale || 'de_DE_formal' == $locale || 'de_CH' == $locale || 'de_CH_informal' == $locale ) {
     1941        if ( in_array( $locale, array( 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal' ), true ) ) {
    19421942            $chars['Ä'] = 'Ae';
    19431943            $chars['ä'] = 'ae';
     
    21802180    $raw_title = $title;
    21812181
    2182     if ( 'save' == $context ) {
     2182    if ( 'save' === $context ) {
    21832183        $title = remove_accents( $title );
    21842184    }
     
    22472247    $title = strtolower( $title );
    22482248
    2249     if ( 'save' == $context ) {
     2249    if ( 'save' === $context ) {
    22502250        // Convert &nbsp, &ndash, and &mdash to hyphens.
    22512251        $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
     
    23552355    $sanitized = preg_replace( '/[^A-Za-z0-9_-]/', '', $sanitized );
    23562356
    2357     if ( '' == $sanitized && $fallback ) {
     2357    if ( '' === $sanitized && $fallback ) {
    23582358        return sanitize_html_class( $fallback );
    23592359    }
     
    28372837    $url = $matches[2];
    28382838
    2839     if ( ')' == $matches[3] && strpos( $url, '(' ) ) {
     2839    if ( ')' === $matches[3] && strpos( $url, '(' ) ) {
    28402840        // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it,
    28412841        // add the closing parenthesis to the URL. Then we can let the parenthesis balancer do its thing below.
     
    33713371
    33723372            // If we're in an ignore block, wait until we find its closing tag.
    3373             if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
     3373            if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
    33743374                $ignore_block_element = $matches[1];
    33753375            }
    33763376
    33773377            // If it's not a tag and not in ignore block.
    3378             if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] ) {
     3378            if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] ) {
    33793379                $content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
    33803380            }
    33813381
    33823382            // Did we exit ignore block?
    3383             if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
     3383            if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
    33843384                $ignore_block_element = '';
    33853385            }
     
    35743574        $offset = 0;
    35753575    } else {
    3576         $sign    = ( substr( $timezone, 0, 1 ) == '+' ) ? 1 : -1;
     3576        $sign    = ( '+' === substr( $timezone, 0, 1 ) ) ? 1 : -1;
    35773577        $hours   = intval( substr( $timezone, 1, 2 ) );
    35783578        $minutes = intval( substr( $timezone, 3, 4 ) ) / 60;
     
    38143814function wp_trim_excerpt( $text = '', $post = null ) {
    38153815    $raw_excerpt = $text;
    3816     if ( '' == $text ) {
     3816
     3817    if ( '' === $text ) {
    38173818        $post = get_post( $post );
    38183819        $text = get_the_content( '', false, $post );
     
    43084309    $original_url = $url;
    43094310
    4310     if ( '' == $url ) {
     4311    if ( '' === $url ) {
    43114312        return $url;
    43124313    }
     
    43364337
    43374338    // Replace ampersands and single quotes only when displaying.
    4338     if ( 'display' == $_context ) {
     4339    if ( 'display' === $_context ) {
    43394340        $url = wp_kses_normalize_entities( $url );
    43404341        $url = str_replace( '&amp;', '&#038;', $url );
     
    46464647        case 'default_comment_status':
    46474648            // Options that if not there have 0 value but need to be something like "closed".
    4648             if ( '0' == $value || '' == $value ) {
     4649            if ( '0' == $value || '' === $value ) {
    46494650                $value = 'closed';
    46504651            }
     
    49784979
    49794980        // Literal %: append and continue.
    4980         if ( substr( $pattern, $start, 2 ) == '%%' ) {
     4981        if ( '%%' === substr( $pattern, $start, 2 ) ) {
    49814982            $start  += 2;
    49824983            $result .= '%';
     
    50445045function wp_sprintf_l( $pattern, $args ) {
    50455046    // Not a match.
    5046     if ( substr( $pattern, 0, 2 ) != '%l' ) {
     5047    if ( '%l' !== substr( $pattern, 0, 2 ) ) {
    50475048        return $pattern;
    50485049    }
     
    58075808
    58085809        // If we're in an ignore block, wait until we find its closing tag.
    5809         if ( '' == $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
     5810        if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
    58105811            $ignore_block_element = $matches[1];
    58115812        }
    58125813
    58135814        // If it's not a tag and not in ignore block.
    5814         if ( '' == $ignore_block_element && strlen( $content ) > 0 && '<' != $content[0] && false !== strpos( $content, '&#x' ) ) {
     5815        if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] && false !== strpos( $content, '&#x' ) ) {
    58155816            foreach ( $possible_emoji as $emojum => $emoji_char ) {
    58165817                if ( false === strpos( $content, $emojum ) ) {
     
    58285829
    58295830        // Did we exit ignore block?
    5830         if ( '' != $ignore_block_element && '</' . $ignore_block_element . '>' == $content ) {
     5831        if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
    58315832            $ignore_block_element = '';
    58325833        }
Note: See TracChangeset for help on using the changeset viewer.