Make WordPress Core

Changeset 63378


Ignore:
Timestamp:
08/27/2026 10:33:18 PM (3 days ago)
Author:
westonruter
Message:

Code Quality: Add the documented return null; to 14 functions.

PHPStan reports return.missing where a documented return type obliges a function to return a value on every path, but one path falls off the end instead. Adding the return null; that the annotation already implies resolves the report without changing behavior, since PHP was returning null implicitly anyway. This is the shape r61716 used on get_category_by_path(), which replaced a bare return; in that same function; its remaining path is now handled too.

Covered here are get_category_by_path(), wp_list_users(), single_month_title(), WP_Customize_Manager::get_setting(), get_panel(), get_section() and get_control(), WP_Customize_Widgets::get_setting_type(), WP_Customize_Header_Image_Control::get_current_image_src(), WP_Image_Editor_Imagick::set_imagick_time_limit(), and the four pagination helpers in link-template.php.

Every change is a pure append, leaving the diff additive at 30 insertions and no deletions. Two further groups of return.missing fixes from the same pull request carry more risk and will follow separately.

The baseline tests/phpstan/baselines/return.missing.neon drops from 41 entries covering 44 errors to 27 covering 29, so the file and its entry in phpstan.neon.dist both remain for now.

Developed in https://github.com/WordPress/wordpress-develop/pull/13082.
Follow-up to r61716, r63020.

Props dpantazis, dmsnell.
See #65817.

Location:
trunk
Files:
9 edited

Legend:

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

    r61716 r63378  
    177177                return $category;
    178178        }
     179
     180        return null;
    179181}
    180182
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r62878 r63378  
    38763876                        return $this->settings[ $id ];
    38773877                }
     3878
     3879                return null;
    38783880        }
    38793881
     
    39283930                        return $this->panels[ $id ];
    39293931                }
     3932
     3933                return null;
    39303934        }
    39313935
     
    40244028                        return $this->sections[ $id ];
    40254029                }
     4030
     4031                return null;
    40264032        }
    40274033
     
    41034109                        return $this->controls[ $id ];
    41044110                }
     4111
     4112                return null;
    41054113        }
    41064114
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r62704 r63378  
    190190                        }
    191191                }
     192
     193                return null;
    192194        }
    193195
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r63369 r63378  
    532532                        return $limit;
    533533                }
     534
     535                return null;
    534536        }
    535537
  • trunk/src/wp-includes/customize/class-wp-customize-header-image-control.php

    r61767 r63378  
    202202                        return $src;
    203203                }
     204
     205                return null;
    204206        }
    205207
  • trunk/src/wp-includes/general-template.php

    r62953 r63378  
    18971897                return $result;
    18981898        }
     1899
    18991900        echo $result;
     1901
     1902        return null;
    19001903}
    19011904
  • trunk/src/wp-includes/link-template.php

    r63177 r63378  
    25312531                }
    25322532        }
     2533
     2534        return null;
    25332535}
    25342536
     
    25992601                );
    26002602        }
     2603
     2604        return null;
    26012605}
    26022606
     
    26382642                return get_pagenum_link( $previous_page );
    26392643        }
     2644
     2645        return null;
    26402646}
    26412647
     
    26932699                );
    26942700        }
     2701
     2702        return null;
    26952703}
    26962704
  • trunk/src/wp-includes/user.php

    r63320 r63378  
    10141014                return $return;
    10151015        }
     1016
    10161017        echo $return;
     1018
     1019        return null;
    10171020}
    10181021
  • trunk/tests/phpstan/baselines/return.missing.neon

    r63020 r63378  
    3030                        path: ../../../src/wp-content/themes/twentyfourteen/inc/widgets.php
    3131                -
    32                         message: '#^Function get_category_by_path\(\) should return array\|WP_Error\|WP_Term\|null but return statement is missing\.$#'
    33                         identifier: return.missing
    34                         count: 1
    35                         path: ../../../src/wp-includes/category.php
    36                 -
    37                         message: '#^Method WP_Customize_Manager\:\:get_control\(\) should return WP_Customize_Control\|null but return statement is missing\.$#'
    38                         identifier: return.missing
    39                         count: 1
    40                         path: ../../../src/wp-includes/class-wp-customize-manager.php
    41                 -
    42                         message: '#^Method WP_Customize_Manager\:\:get_panel\(\) should return WP_Customize_Panel\|null but return statement is missing\.$#'
    43                         identifier: return.missing
    44                         count: 1
    45                         path: ../../../src/wp-includes/class-wp-customize-manager.php
    46                 -
    47                         message: '#^Method WP_Customize_Manager\:\:get_section\(\) should return WP_Customize_Section\|null but return statement is missing\.$#'
    48                         identifier: return.missing
    49                         count: 1
    50                         path: ../../../src/wp-includes/class-wp-customize-manager.php
    51                 -
    52                         message: '#^Method WP_Customize_Manager\:\:get_setting\(\) should return WP_Customize_Setting\|null but return statement is missing\.$#'
    53                         identifier: return.missing
    54                         count: 1
    55                         path: ../../../src/wp-includes/class-wp-customize-manager.php
    56                 -
    57                         message: '#^Method WP_Customize_Widgets\:\:get_setting_type\(\) should return string\|null but return statement is missing\.$#'
    58                         identifier: return.missing
    59                         count: 1
    60                         path: ../../../src/wp-includes/class-wp-customize-widgets.php
    61                 -
    62                         message: '#^Method WP_Image_Editor_Imagick\:\:set_imagick_time_limit\(\) should return int\|null but return statement is missing\.$#'
    63                         identifier: return.missing
    64                         count: 1
    65                         path: ../../../src/wp-includes/class-wp-image-editor-imagick.php
    66                 -
    67                         message: '#^Method WP_Customize_Header_Image_Control\:\:get_current_image_src\(\) should return string\|null but return statement is missing\.$#'
    68                         identifier: return.missing
    69                         count: 1
    70                         path: ../../../src/wp-includes/customize/class-wp-customize-header-image-control.php
    71                 -
    7232                        message: '#^Function post_type_archive_title\(\) should return string\|null but return statement is missing\.$#'
    73                         identifier: return.missing
    74                         count: 1
    75                         path: ../../../src/wp-includes/general-template.php
    76                 -
    77                         message: '#^Function single_month_title\(\) should return string\|false\|null but return statement is missing\.$#'
    7833                        identifier: return.missing
    7934                        count: 1
     
    11065                        path: ../../../src/wp-includes/link-template.php
    11166                -
    112                         message: '#^Function get_next_posts_link\(\) should return string\|null but return statement is missing\.$#'
    113                         identifier: return.missing
    114                         count: 1
    115                         path: ../../../src/wp-includes/link-template.php
    116                 -
    117                         message: '#^Function get_next_posts_page_link\(\) should return string\|null but return statement is missing\.$#'
    118                         identifier: return.missing
    119                         count: 2
    120                         path: ../../../src/wp-includes/link-template.php
    121                 -
    122                         message: '#^Function get_previous_posts_link\(\) should return string\|null but return statement is missing\.$#'
    123                         identifier: return.missing
    124                         count: 1
    125                         path: ../../../src/wp-includes/link-template.php
    126                 -
    127                         message: '#^Function get_previous_posts_page_link\(\) should return string\|null but return statement is missing\.$#'
    128                         identifier: return.missing
    129                         count: 1
    130                         path: ../../../src/wp-includes/link-template.php
    131                 -
    13267                        message: '#^Function next_posts\(\) should return string\|null but return statement is missing\.$#'
    13368                        identifier: return.missing
     
    13974                        count: 1
    14075                        path: ../../../src/wp-includes/link-template.php
    141                 -
    142                         message: '#^Function wp_list_users\(\) should return string\|null but return statement is missing\.$#'
    143                         identifier: return.missing
    144                         count: 1
    145                         path: ../../../src/wp-includes/user.php
    14676                -
    14777                        message: '#^Method WP_Nav_Menu_Widget\:\:form\(\) should return string\|null but return statement is missing\.$#'
Note: See TracChangeset for help on using the changeset viewer.