Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (5 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/class-wp-date-query.php

    r47122 r47550  
    260260     */
    261261    public function get_compare( $query ) {
    262         if ( ! empty( $query['compare'] ) && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
     262        if ( ! empty( $query['compare'] )
     263            && in_array( $query['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true )
     264        ) {
    263265            return strtoupper( $query['compare'] );
    264266        }
     
    501503             *                                'user_registered'
    502504             */
    503             if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) ) {
     505            if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ), true ) ) {
    504506                $column = 'post_date';
    505507            }
     
    527529            // If it's a known column name, add the appropriate table prefix.
    528530            foreach ( $known_columns as $table_name => $table_columns ) {
    529                 if ( in_array( $column, $table_columns ) ) {
     531                if ( in_array( $column, $table_columns, true ) ) {
    530532                    $column = $table_name . '.' . $column;
    531533                    break;
     
    973975
    974976        // Complex combined queries aren't supported for multi-value queries.
    975         if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
     977        if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
    976978            $return = array();
    977979
Note: See TracChangeset for help on using the changeset viewer.