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/phpstan.neon.dist

    r63367 r63379  
    7777        - tests/phpstan/baselines/property.private.neon
    7878        - tests/phpstan/baselines/property.protected.neon
    79         - tests/phpstan/baselines/return.missing.neon
    8079        - tests/phpstan/baselines/return.type.neon
    8180        - tests/phpstan/baselines/return.unusedType.neon
Note: See TracChangeset for help on using the changeset viewer.