Make WordPress Core

Changeset 63487


Ignore:
Timestamp:
09/05/2026 12:36:18 AM (2 months ago)
Author:
westonruter
Message:

Code Quality: Refine the dual-mode template tag annotations.

  • Restore void to the @return unions of wpdb::print_error() and wpdb::check_database_version(), which r62177 replaced with null.
  • Add the null that fifteen tags describe in prose but omit from a @return listing only string|void.
  • Match every falsy spelling of a display flag, and every argument shape reaching a bail, so those calls resolve to void; a query string still cannot be read, tracked in #66049.
  • Narrow the deprecated param for trackback_url() so that static analysis catches the obsolete usage.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13371.
Follow-up to r32568, r61766, r61768, r62177, r62178, r63440, r63441.

Props marian1, westonruter.
See #64703, #64704, #65817, #66049.

Location:
trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/inc/template-tags.php

    r63441 r63487  
    108108 *
    109109 * @param bool $display Display or return the HTML.
    110  * @return string|void The HTML when `$display` is false, null when the site has no
    111  *                     description. Nothing otherwise.
     110 * @return string|null|void The HTML when `$display` is false, null when the site has no
     111 *                          description. Nothing otherwise.
    112112 * @phpstan-return ( $display is true ? void : string|null )
    113113 */
  • trunk/src/wp-includes/author-template.php

    r63441 r63487  
    454454 *     $args is array{ echo: false|0|''|'0', ... }
    455455 *         ? string
    456  *         : ( $args is ''|array ? void : string|null )
     456 *         : ( $args is ''|'0'|array ? void : string|null )
    457457 * )
    458458 */
  • trunk/src/wp-includes/bookmark-template.php

    r63441 r63487  
    211211 *     $args is array{ echo: false|0|''|'0', ... }
    212212 *         ? string
    213  *         : ( $args is ''|array ? void : string|null )
     213 *         : ( $args is ''|'0'|array ? void : string|null )
    214214 * )
    215215 */
  • trunk/src/wp-includes/category-template.php

    r63441 r63487  
    711711 *     @type bool   $echo      Whether or not to echo the return value. Default true.
    712712 * }
    713  * @return string|string[]|void Tag cloud as a string, or as an array when the 'format' argument
    714  *                              is 'array'. Null on failure. Nothing when 'echo' is true and
    715  *                              'format' is not 'array'.
     713 * @return string|string[]|null|void Tag cloud as a string, or as an array when the 'format'
     714 *                                   argument is 'array'. Null on failure. Nothing when 'echo' is
     715 *                                   true and 'format' is not 'array'.
    716716 * @phpstan-return (
    717717 *     $args is array{ format: 'array', ... }
    … …  
    719719 *         : ( $args is array{ echo: false|0|''|'0', ... }
    720720 *             ? string|null
    721  *             : ( $args is ''|array ? void : string|string[]|null ) )
     721 *             : ( $args is ''|'0'|array ? void : string|string[]|null ) )
    722722 * )
    723723 */
  • trunk/src/wp-includes/class-wpdb.php

    r63420 r63487  
    17951795         *
    17961796         * @param string $str The error to display.
    1797          * @return null|false Null if the showing of errors is enabled, false if disabled.
     1797         * @return void|false Void if the showing of errors is enabled, false if disabled.
    17981798         */
    17991799        public function print_error( $str = '' ) {
    … …  
    18561856                        );
    18571857                }
    1858 
    1859                 return null;
    18601858        }
    18611859
    … …  
    40694067         *
    40704068         * @global string $required_mysql_version The minimum required MySQL version string.
    4071          * @return WP_Error|null
     4069         * @return void|WP_Error Void if the server meets the minimum version, WP_Error if not.
    40724070         */
    40734071        public function check_database_version() {
    … …  
    40804078                        return new WP_Error( 'database_version', sprintf( __( '<strong>Error:</strong> WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) );
    40814079                }
    4082 
    4083                 return null;
    40844080        }
    40854081
  • trunk/src/wp-includes/comment-template.php

    r63441 r63487  
    12451245 * @see get_trackback_url()
    12461246 *
    1247  * @param bool $deprecated_echo Deprecated. Use {@see get_trackback_url()}. Echo the URL or
     1247 * @param true $deprecated_echo Deprecated. Use {@see get_trackback_url()}. Echo the URL or
    12481248 *                              return it. Default true.
    12491249 * @return string|void The trackback URL when `$deprecated_echo` is false, nothing otherwise.
    12501250 * @phpstan-return ( $deprecated_echo is true ? void : string )
     1251 *
     1252 * @phpstan-ignore conditionalType.alwaysTrue (Typed `true` to flag the deprecated argument.)
    12511253 */
    12521254function trackback_url( $deprecated_echo = true ) {
    … …  
    22342236 * }
    22352237 * @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Default null.
    2236  * @return string|void HTML list of comments when 'echo' is false, null when there are no
    2237  *                     comments to list. Nothing otherwise.
     2238 * @return string|null|void HTML list of comments when 'echo' is false, null when there are
     2239 *                          no comments to list. Nothing otherwise.
    22382240 * @phpstan-return (
    22392241 *     $args is array{ echo: false|0|''|'0', ... }
    22402242 *         ? string|null
    2241  *         : ( $args is ''|array ? void : string|null )
     2243 *         : ( $args is ''|'0'|array ? void : string|null )
    22422244 * )
    22432245 */
  • trunk/src/wp-includes/functions.php

    r63461 r63487  
    87468746 * @param string $after   Markup to output after the annotation. Default `</p>`.
    87478747 * @param bool   $display Whether to echo or return the markup. Default `true` for echo.
    8748  * @return string|void Update PHP page annotation when `$display` is false, null when no
    8749  *                     annotation is available. Nothing otherwise.
     8748 * @return string|null|void Update PHP page annotation when `$display` is false, null when
     8749 *                          no annotation is available. Nothing otherwise.
    87508750 * @phpstan-return ( $display is true ? void : string|null )
    87518751 */
  • trunk/src/wp-includes/general-template.php

    r63441 r63487  
    17061706 * @param string $prefix  Optional. What to display before the title.
    17071707 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
    1708  * @return string|void Title when retrieving, null on failure.
    1709  *                     Nothing when displaying.
     1708 * @return string|null|void Title when retrieving, null on failure.
     1709 *                          Nothing when displaying.
    17101710 * @phpstan-return ( $display is true ? void : string|null )
    17111711 */
    … …  
    17441744 * @param string $prefix  Optional. What to display before the title.
    17451745 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
    1746  * @return string|void Title when retrieving, null on failure.
    1747  *                     Nothing when displaying.
     1746 * @return string|null|void Title when retrieving, null on failure.
     1747 *                          Nothing when displaying.
    17481748 * @phpstan-return ( $display is true ? void : string|null )
    17491749 */
    … …  
    17881788 * @param string $prefix  Optional. What to display before the title.
    17891789 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
    1790  * @return string|void Title when retrieving, null on failure.
    1791  *                     Nothing when displaying.
     1790 * @return string|null|void Title when retrieving, null on failure.
     1791 *                          Nothing when displaying.
    17921792 * @phpstan-return ( $display is true ? void : string|null )
    17931793 */
    … …  
    18111811 * @param string $prefix  Optional. What to display before the title.
    18121812 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
    1813  * @return string|void Title when retrieving, null on failure.
    1814  *                     Nothing when displaying.
     1813 * @return string|null|void Title when retrieving, null on failure.
     1814 *                          Nothing when displaying.
    18151815 * @phpstan-return ( $display is true ? void : string|null )
    18161816 */
    … …  
    18341834 * @param string $prefix  Optional. What to display before the title.
    18351835 * @param bool   $display Optional. Whether to display or retrieve title. Default true.
    1836  * @return string|void Title when retrieving, null on failure.
    1837  *                     Nothing when displaying.
     1836 * @return string|null|void Title when retrieving, null on failure.
     1837 *                          Nothing when displaying.
    18381838 * @phpstan-return ( $display is true ? void : string|null )
    18391839 */
    … …  
    22362236 *     @type string     $w               Week. Default current week.
    22372237 * }
    2238  * @return string|void Archive links when 'echo' is false, null when the post type is
    2239  *                     not viewable. Nothing otherwise.
     2238 * @return string|null|void Archive links when 'echo' is false, null when the post type is
     2239 *                          not viewable. Nothing otherwise.
    22402240 * @phpstan-return (
    22412241 *     $args is array{ echo: false|0|''|'0', ... }
    22422242 *         ? string|null
    2243  *         : ( $args is ''|array ? void : string|null )
     2243 *         : ( $args is ''|'0'|array ? void : string|null )
    22442244 * )
    22452245 */
    … …  
    25122512 *     @type string $post_type Optional. Post type. Default 'post'.
    25132513 * }
    2514  * @return string|void Calendar HTML when `$display` is false, null when the site has
    2515  *                     no posts. Nothing otherwise.
     2514 * @return string|null|void Calendar HTML when `$display` is false, null when the site has
     2515 *                          no posts. Nothing otherwise.
    25162516 * @phpstan-return ( $args is array{ display: false|0|''|'0', ... } ? string|null : void )
    25172517 */
    … …  
    29282928 * @param string $after   Optional. Output after the date. Default empty.
    29292929 * @param bool   $display Optional. Whether to echo the date or return it. Default true.
    2930  * @return string|void String if retrieving.
     2930 * @return string|void The date when `$display` is false, or an empty string when the post's
     2931 *                     date matches the previously output one. Nothing otherwise.
    29312932 * @phpstan-return ( $display is true ? void : string )
    29322933 */
    … …  
    30043005 * @param string $after   Optional. Output after the date. Default empty.
    30053006 * @param bool   $display Optional. Whether to echo the date or return it. Default true.
    3006  * @return string|void String if retrieving.
     3007 * @return string|void The modified date when `$display` is false, nothing otherwise.
    30073008 * @phpstan-return ( $display is true ? void : string )
    30083009 */
  • trunk/src/wp-includes/l10n.php

    r63441 r63487  
    17371737 * }
    17381738 * @return string|void HTML dropdown list of languages. Always returned, whether or not
    1739  *                     'echo' is true; nothing is returned when the required `id` or `name`
    1740  *                     argument is missing.
     1739 *                     'echo' is true; nothing is returned when the 'id' or 'name'
     1740 *                     argument is empty.
     1741 * @phpstan-return (
     1742 *     $args is array{ id: ''|'0', ... }
     1743 *         ? void
     1744 *         : ( $args is array{ name: ''|'0', ... }
     1745 *             ? void
     1746 *             : ( $args is array ? string : string|void ) )
     1747 * )
    17411748 */
    17421749function wp_dropdown_languages( $args = array() ) {
  • trunk/src/wp-includes/link-template.php

    r63441 r63487  
    11321132 * @param int|WP_Term|null $term    Optional. Term ID or object. If null, the queried object will be inspected. Default null.
    11331133 * @param bool             $display Optional. Whether or not to echo the return. Default true.
    1134  * @return string|void HTML content when retrieving, null on failure or without the
    1135  *                     capability to edit the term. Nothing when displaying.
     1134 * @return string|null|void HTML content when retrieving, null on failure or without the
     1135 *                          capability to edit the term. Nothing when displaying.
    11361136 * @phpstan-return ( $display is true ? void : string|null )
    11371137 */
    … …  
    32693269 *
    32703270 * @param string|array $args Optional args. See paginate_links(). Default empty array.
    3271  * @return string|string[]|void Markup for comment page links, or an array of them when the 'type'
    3272  *                              argument is 'array'. Null if the query is not for an existing single
    3273  *                              post of any post type. Nothing when 'echo' is true and 'type' is not
    3274  *                              'array'.
     3271 * @return string|string[]|null|void Markup for comment page links, or an array of them when
     3272 *                                   the 'type' argument is 'array'. Null if the query is not for
     3273 *                                   an existing single post of any post type. Nothing when 'echo'
     3274 *                                   is true and 'type' is not 'array'.
    32753275 * @phpstan-return (
    32763276 *     $args is array{ type: 'array', ... }
    … …  
    32783278 *         : ( $args is array{ echo: false|0|''|'0', ... }
    32793279 *             ? string|null
    3280  *             : ( $args is ''|array ? void : string|string[]|null ) )
     3280 *             : ( $args is ''|'0'|array ? void : string|string[]|null ) )
    32813281 * )
    32823282 */
  • trunk/src/wp-includes/post-template.php

    r63441 r63487  
    3838 * @param string $after   Optional. Markup to append to the title. Default empty.
    3939 * @param bool   $display Optional. Whether to echo or return the title. Default true for echo.
    40  * @return string|void Current post title when `$display` is false, null when the title
    41  *                     is empty. Nothing otherwise.
     40 * @return string|null|void Current post title when `$display` is false, null when the
     41 *                          title is empty. Nothing otherwise.
    4242 * @phpstan-return ( $display is true ? void : string|null )
    4343 */
    … …  
    7878 *     @type WP_Post $post   Current post object to retrieve the title for.
    7979 * }
    80  * @return string|void The title attribute when 'echo' is false, null when the title is
    81  *                     empty. Nothing otherwise.
     80 * @return string|null|void The title attribute when 'echo' is false, null when the title
     81 *                          is empty. Nothing otherwise.
    8282 * @phpstan-return (
    8383 *     $args is array{ echo: false|0|''|'0', ... }
    8484 *         ? string|null
    85  *         : ( $args is ''|array ? void : string|null )
     85 *         : ( $args is ''|'0'|array ? void : string|null )
    8686 * )
    8787 */
    … …  
    13101310 *     $args is array{ echo: false|0|''|'0', ... }
    13111311 *         ? string
    1312  *         : ( $args is ''|array ? void : string|null )
     1312 *         : ( $args is ''|'0'|array ? void : string|null )
    13131313 * )
    13141314 */
    … …  
    14381438 *     $args is array{ echo: false|0|''|'0', ... }
    14391439 *         ? string
    1440  *         : ( $args is ''|array ? void : string|null )
     1440 *         : ( $args is ''|'0'|array ? void : string|null )
    14411441 * )
    14421442 */
  • trunk/src/wp-includes/user.php

    r63441 r63487  
    912912 *     $args is array{ echo: false|0|''|'0', ... }
    913913 *         ? string
    914  *         : ( $args is ''|array ? void : string|null )
     914 *         : ( $args is ''|'0'|array ? void : string|null )
    915915 * )
    916916 */
Note: See TracChangeset for help on using the changeset viewer.