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

@@ -2156,7 +2156,7 @@ class WP_Query {
}
$post_status_join = true;
} elseif ( in_array( 'attachment', (array) $post_type ) ) {
} elseif ( in_array( 'attachment', (array) $post_type, true ) ) {
$post_status_join = true;
}
}
@@ -2177,7 +2177,7 @@ class WP_Query {
continue;
}
if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ) ) ) {
if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ), true ) ) {
$q['taxonomy'] = $queried_taxonomy;
if ( 'slug' === $queried_items['field'] ) {
@@ -2463,15 +2463,15 @@ class WP_Query {
$r_status = array();
$p_status = array();
$e_status = array();
if ( in_array( 'any', $q_status ) ) {
if ( in_array( 'any', $q_status, true ) ) {
foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) {
if ( ! in_array( $status, $q_status ) ) {
if ( ! in_array( $status, $q_status, true ) ) {
$e_status[] = "{$wpdb->posts}.post_status <> '$status'";
}
}
} else {
foreach ( get_post_stati() as $status ) {
if ( in_array( $status, $q_status ) ) {
if ( in_array( $status, $q_status, true ) ) {
if ( 'private' == $status ) {
$p_status[] = "{$wpdb->posts}.post_status = '$status'";
} else {
@@ -3083,7 +3083,7 @@ class WP_Query {
}
// If the post_status was specifically requested, let it pass through.
if ( ! in_array( $status, $q_status ) ) {
if ( ! in_array( $status, $q_status, true ) ) {
$post_status_obj = get_post_status_object( $status );
if ( $post_status_obj && ! $post_status_obj->public ) {
@@ -3564,7 +3564,7 @@ class WP_Query {
* @return mixed Property.
*/
public function __get( $name ) {
if ( in_array( $name, $this->compat_fields ) ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return $this->$name;
}
}
@@ -3578,7 +3578,7 @@ class WP_Query {
* @return bool Whether the property is set.
*/
public function __isset( $name ) {
if ( in_array( $name, $this->compat_fields ) ) {
if ( in_array( $name, $this->compat_fields, true ) ) {
return isset( $this->$name );
}
}
@@ -3593,7 +3593,7 @@ class WP_Query {
* @return mixed|false Return value of the callback, false otherwise.
*/
public function __call( $name, $arguments ) {
if ( in_array( $name, $this->compat_methods ) ) {
if ( in_array( $name, $this->compat_methods, true ) ) {
return $this->$name( ...$arguments );
}
return false;
@@ -3632,7 +3632,7 @@ class WP_Query {
}
$post_type_object = get_post_type_object( $post_type );
return in_array( $post_type_object->name, (array) $post_types );
return in_array( $post_type_object->name, (array) $post_types, true );
}
/**
@@ -3657,11 +3657,11 @@ class WP_Query {
$post_obj = $this->get_queried_object();
if ( in_array( (string) $post_obj->ID, $attachment ) ) {
if ( in_array( (string) $post_obj->ID, $attachment, true ) ) {
return true;
} elseif ( in_array( $post_obj->post_title, $attachment ) ) {
} elseif ( in_array( $post_obj->post_title, $attachment, true ) ) {
return true;
} elseif ( in_array( $post_obj->post_name, $attachment ) ) {
} elseif ( in_array( $post_obj->post_name, $attachment, true ) ) {
return true;
}
return false;
@@ -3692,11 +3692,11 @@ class WP_Query {
$author = array_map( 'strval', (array) $author );
if ( in_array( (string) $author_obj->ID, $author ) ) {
if ( in_array( (string) $author_obj->ID, $author, true ) ) {
return true;
} elseif ( in_array( $author_obj->nickname, $author ) ) {
} elseif ( in_array( $author_obj->nickname, $author, true ) ) {
return true;
} elseif ( in_array( $author_obj->user_nicename, $author ) ) {
} elseif ( in_array( $author_obj->user_nicename, $author, true ) ) {
return true;
}
@@ -3728,11 +3728,11 @@ class WP_Query {
$category = array_map( 'strval', (array) $category );
if ( in_array( (string) $cat_obj->term_id, $category ) ) {
if ( in_array( (string) $cat_obj->term_id, $category, true ) ) {
return true;
} elseif ( in_array( $cat_obj->name, $category ) ) {
} elseif ( in_array( $cat_obj->name, $category, true ) ) {
return true;
} elseif ( in_array( $cat_obj->slug, $category ) ) {
} elseif ( in_array( $cat_obj->slug, $category, true ) ) {
return true;
}
@@ -3764,11 +3764,11 @@ class WP_Query {
$tag = array_map( 'strval', (array) $tag );
if ( in_array( (string) $tag_obj->term_id, $tag ) ) {
if ( in_array( (string) $tag_obj->term_id, $tag, true ) ) {
return true;
} elseif ( in_array( $tag_obj->name, $tag ) ) {
} elseif ( in_array( $tag_obj->name, $tag, true ) ) {
return true;
} elseif ( in_array( $tag_obj->slug, $tag ) ) {
} elseif ( in_array( $tag_obj->slug, $tag, true ) ) {
return true;
}
@@ -3812,7 +3812,7 @@ class WP_Query {
$term_array = (array) $term;
// Check that the taxonomy matches.
if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) {
if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array, true ) ) ) {
return false;
}
@@ -3883,7 +3883,7 @@ class WP_Query {
if ( 'feed' == $qv ) {
$qv = get_default_feed();
}
return in_array( $qv, (array) $feeds );
return in_array( $qv, (array) $feeds, true );
}
/**
@@ -4004,11 +4004,11 @@ class WP_Query {
$page = array_map( 'strval', (array) $page );
if ( in_array( (string) $page_obj->ID, $page ) ) {
if ( in_array( (string) $page_obj->ID, $page, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_title, $page ) ) {
} elseif ( in_array( $page_obj->post_title, $page, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_name, $page ) ) {
} elseif ( in_array( $page_obj->post_name, $page, true ) ) {
return true;
} else {
foreach ( $page as $pagepath ) {
@@ -4111,11 +4111,11 @@ class WP_Query {
$post = array_map( 'strval', (array) $post );
if ( in_array( (string) $post_obj->ID, $post ) ) {
if ( in_array( (string) $post_obj->ID, $post, true ) ) {
return true;
} elseif ( in_array( $post_obj->post_title, $post ) ) {
} elseif ( in_array( $post_obj->post_title, $post, true ) ) {
return true;
} elseif ( in_array( $post_obj->post_name, $post ) ) {
} elseif ( in_array( $post_obj->post_name, $post, true ) ) {
return true;
} else {
foreach ( $post as $postpath ) {
@@ -4156,7 +4156,7 @@ class WP_Query {
$post_obj = $this->get_queried_object();
return in_array( $post_obj->post_type, (array) $post_types );
return in_array( $post_obj->post_type, (array) $post_types, true );
}
/**