diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5766f8a98a6b0..4292aa4ddb408 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -76,7 +76,6 @@ includes: - tests/phpstan/baselines/property.phpDocType.neon - tests/phpstan/baselines/property.private.neon - tests/phpstan/baselines/property.protected.neon - - tests/phpstan/baselines/return.missing.neon - tests/phpstan/baselines/return.type.neon - tests/phpstan/baselines/return.unusedType.neon - tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon diff --git a/src/wp-includes/class-wp-widget.php b/src/wp-includes/class-wp-widget.php index dc84f54774162..b131c50db3226 100644 --- a/src/wp-includes/class-wp-widget.php +++ b/src/wp-includes/class-wp-widget.php @@ -138,7 +138,8 @@ public function update( $new_instance, $old_instance ) { * @since 2.8.0 * * @param array $instance The settings for the particular instance of the widget. - * @return string|null Default return is 'noform'. A subclass may opt to return null. + * @return string|void Default return is 'noform'. A subclass which echoes its own + * form returns nothing. */ public function form( $instance ) { echo '

' . __( 'There are no options for this widget.' ) . '

'; diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index dae87c6aa8005..b626b5ca605ce 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1673,11 +1673,13 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) { $title = apply_filters( 'wp_title', $title, $sep, $seplocation ); // Send it out. - if ( $display ) { - echo $title; - } else { + if ( ! $display ) { return $title; } + + echo $title; + + return null; } /** @@ -1712,11 +1714,14 @@ function single_post_title( $prefix = '', $display = true ) { * @param WP_Post $_post The current post. */ $title = apply_filters( 'single_post_title', $_post->post_title, $_post ); - if ( $display ) { - echo $prefix . $title; - } else { + + if ( ! $display ) { return $prefix . $title; } + + echo $prefix . $title; + + return null; } /** @@ -1753,11 +1758,13 @@ function post_type_archive_title( $prefix = '', $display = true ) { */ $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); - if ( $display ) { - echo $prefix . $title; - } else { + if ( ! $display ) { return $prefix . $title; } + + echo $prefix . $title; + + return null; } /** @@ -1849,11 +1856,13 @@ function single_term_title( $prefix = '', $display = true ) { return null; } - if ( $display ) { - echo $prefix . $term_name; - } else { + if ( ! $display ) { return $prefix . $term_name; } + + echo $prefix . $term_name; + + return null; } /** @@ -2913,11 +2922,13 @@ function the_date( $format = '', $before = '', $after = '', $display = true ) { */ $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after ); - if ( $display ) { - echo $the_date; - } else { + if ( ! $display ) { return $the_date; } + + echo $the_date; + + return null; } /** @@ -2981,11 +2992,13 @@ function the_modified_date( $format = '', $before = '', $after = '', $display = */ $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after ); - if ( $display ) { - echo $the_modified_date; - } else { + if ( ! $display ) { return $the_modified_date; } + + echo $the_modified_date; + + return null; } /** diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 0f332b3101148..4c6b1fa929586 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -1164,11 +1164,13 @@ function edit_term_link( $link = '', $before = '', $after = '', $term = null, $d */ $link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; - if ( $display ) { - echo $link; - } else { + if ( ! $display ) { return $link; } + + echo $link; + + return null; } /** @@ -2547,11 +2549,13 @@ function next_posts( $max_page = 0, $display = true ) { $link = get_next_posts_page_link( $max_page ); $output = $link ? esc_url( $link ) : ''; - if ( $display ) { - echo $output; - } else { + if ( ! $display ) { return $output; } + + echo $output; + + return null; } /** @@ -2657,11 +2661,13 @@ function previous_posts( $display = true ) { $link = get_previous_posts_page_link(); $output = $link ? esc_url( $link ) : ''; - if ( $display ) { - echo $output; - } else { + if ( ! $display ) { return $output; } + + echo $output; + + return null; } /** diff --git a/tests/phpstan/baselines/return.missing.neon b/tests/phpstan/baselines/return.missing.neon deleted file mode 100644 index 64fe066c133cb..0000000000000 --- a/tests/phpstan/baselines/return.missing.neon +++ /dev/null @@ -1,155 +0,0 @@ -# PHPStan baseline for the `return.missing` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/return.missing -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=return.missing -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Method Twenty_Eleven_Ephemera_Widget\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-content/themes/twentyeleven/inc/widgets.php - - - message: '#^Method Twenty_Fourteen_Ephemera_Widget\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-content/themes/twentyfourteen/inc/widgets.php - - - message: '#^Function post_type_archive_title\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function single_post_title\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function single_term_title\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function the_date\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function the_modified_date\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function wp_title\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/general-template.php - - - message: '#^Function edit_term_link\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/link-template.php - - - message: '#^Function next_posts\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/link-template.php - - - message: '#^Function previous_posts\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/link-template.php - - - message: '#^Method WP_Nav_Menu_Widget\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-nav-menu-widget.php - - - message: '#^Method WP_Widget_Archives\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-archives.php - - - message: '#^Method WP_Widget_Block\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-block.php - - - message: '#^Method WP_Widget_Calendar\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-calendar.php - - - message: '#^Method WP_Widget_Categories\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-categories.php - - - message: '#^Method WP_Widget_Custom_HTML\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-custom-html.php - - - message: '#^Method WP_Widget_Links\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-links.php - - - message: '#^Method WP_Widget_Media\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-media.php - - - message: '#^Method WP_Widget_Meta\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-meta.php - - - message: '#^Method WP_Widget_Pages\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-pages.php - - - message: '#^Method WP_Widget_Recent_Comments\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-recent-comments.php - - - message: '#^Method WP_Widget_Recent_Posts\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-recent-posts.php - - - message: '#^Method WP_Widget_RSS\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-rss.php - - - message: '#^Method WP_Widget_Search\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 1 - path: ../../../src/wp-includes/widgets/class-wp-widget-search.php - - - message: '#^Method WP_Widget_Tag_Cloud\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 2 - path: ../../../src/wp-includes/widgets/class-wp-widget-tag-cloud.php - - - message: '#^Method WP_Widget_Text\:\:form\(\) should return string\|null but return statement is missing\.$#' - identifier: return.missing - count: 2 - path: ../../../src/wp-includes/widgets/class-wp-widget-text.php