Make WordPress Core


Ignore:
Timestamp:
08/27/2026 10:54:07 PM (3 months ago)
Author:
westonruter
Message:

Code Quality: Resolve the remaining return.missing PHPStan errors.

Nine template functions take a $display parameter and either echo their result or return it. Each is documented as returning string|null, but the echoing branch fell off the end without returning, which is what PHPStan reports as return.missing. Inverting the condition lets the value-returning path exit first and the echoing path fall through to an explicit return null;, the same shape single_month_title() received in r63378. Affected are wp_title(), single_post_title(), post_type_archive_title(), single_term_title(), the_date(), the_modified_date(), edit_term_link(), next_posts() and previous_posts(). No behavior changes.

WP_Widget::form() is documented as string|void again. r59336 added the void deliberately, noting that unlike its siblings it is the child classes which return nothing when the method is correctly implemented. r62178 replaced it with null on the premise that void cannot belong to a union, which holds for PHP's native return types but not for PHPDoc, where PHPStan reads void in a union as "may not return at all". Under string|null the annotation instead obliged every override to return, putting all 18 of them in breach, two of which live in bundled themes that r62178 did not touch.

With no occurrences left, tests/phpstan/baselines/return.missing.neon is deleted along with its entry in phpstan.neon.dist, completing the work begun in r63378.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13082.
Follow-up to r59336, r62178, r63020, r63378.

Props dpantazis, dmsnell.
See #65817, #64704.

File:
1 edited

Legend:

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

    r62178 r63379  
    139139         *
    140140         * @param array $instance The settings for the particular instance of the widget.
    141          * @return string|null Default return is 'noform'. A subclass may opt to return null.
     141         * @return string|void Default return is 'noform'. A subclass which echoes its own
     142         *                     form returns nothing.
    142143         */
    143144        public function form( $instance ) {
Note: See TracChangeset for help on using the changeset viewer.