Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/wp-includes/class-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,11 +1554,9 @@ protected function parse_search( &$query_vars ) {
$searchand = ' AND ';
}

if ( ! empty( $search ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I can see that it is never empty, because of this logic above:

if ( ! empty( $query_vars['sentence'] ) ) {
$query_vars['search_terms'] = array( $query_vars['s'] );
} else {
if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $query_vars['s'], $matches ) ) {
$query_vars['search_terms_count'] = count( $matches[0] );
$query_vars['search_terms'] = $this->parse_search_terms( $matches[0] );
// If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence.
if ( empty( $query_vars['search_terms'] ) || count( $query_vars['search_terms'] ) > 9 ) {
$query_vars['search_terms'] = array( $query_vars['s'] );
}
} else {
$query_vars['search_terms'] = array( $query_vars['s'] );
}
}

And PHPStan types $search as non-empty-array<string>.

$search = " AND ({$search}) ";
if ( ! is_user_logged_in() ) {
$search .= " AND ({$wpdb->posts}.post_password = '') ";
}
$search = " AND ({$search}) ";
if ( ! is_user_logged_in() ) {
$search .= " AND ({$wpdb->posts}.post_password = '') ";
}

return $search;
Expand Down Expand Up @@ -2784,9 +2782,7 @@ public function get_posts() {
$status_type_clauses[] = $type_where;
}

if ( ! empty( $status_type_clauses ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, PHPStan types this variable as non-empty-list<non-falsy-string>. It can never be empty because $queried_post_types is checked to see if it is not empty, and there is a foreach loop for each $queried_post_types which always appends an item to $status_type_clauses.

$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
}
$where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')';
} else {
$where .= ' AND 1=0 ';
}
Expand Down
9 changes: 4 additions & 5 deletions src/wp-includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,8 @@ function wp_remove_object_terms( $object_id, $terms, $taxonomy ) {
* @param string $slug The string that will be tried for a unique slug.
* @param object $term The term object that the `$slug` will belong to.
* @return string Will return a true unique slug.
*
* @phpstan-param object{ taxonomy: string, parent?: int, term_id?: int } $term
*/
function wp_unique_term_slug( $slug, $term ) {
global $wpdb;
Expand All @@ -3290,7 +3292,7 @@ function wp_unique_term_slug( $slug, $term ) {
$parent_suffix = '';
if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) {
$the_parent = $term->parent;
while ( ! empty( $the_parent ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, the ! empty( $term->parent ) check was just performed above, so it will always be true for the first iteration. Switching to do/while is a nice simplification.

do {
$parent_term = get_term( $the_parent, $term->taxonomy );
if ( is_wp_error( $parent_term ) || empty( $parent_term ) ) {
break;
Expand All @@ -3300,11 +3302,8 @@ function wp_unique_term_slug( $slug, $term ) {
break;
}

if ( empty( $parent_term->parent ) ) {
break;
}
$the_parent = $parent_term->parent;
}
} while ( ! empty( $the_parent ) );
}

// If we didn't get a unique slug, try appending a number to make it unique.
Expand Down
35 changes: 0 additions & 35 deletions tests/phpstan/baselines/empty.variable.neon

This file was deleted.

Loading