[wp-trac] [WordPress Trac] #64238: PHPStan code quality improvements for 7.0

WordPress Trac noreply at wordpress.org
Wed Feb 18 22:49:54 UTC 2026


#64238: PHPStan code quality improvements for 7.0
--------------------------------------+-------------------------------
 Reporter:  SergeyBiryukov            |       Owner:  (none)
     Type:  task (blessed)            |      Status:  new
 Priority:  normal                    |   Milestone:  7.0
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  coding-standards
--------------------------------------+-------------------------------

Comment (by westonruter):

 Another patch we should land to improve static analysis:


 {{{#!diff
 diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
 index 70d78ed33c..5951b1906c 100644
 --- a/src/wp-includes/comment.php
 +++ b/src/wp-includes/comment.php
 @@ -217,6 +217,10 @@ function get_approved_comments( $post_id, $args =
 array() ) {
   *                                       correspond to a WP_Comment
 object, an associative array, or a numeric array,
   *                                       respectively. Default OBJECT.
   * @return WP_Comment|array|null Depends on $output value.
 + * @phpstan-return (
 + *     $output is 'ARRAY_A' ? non-empty-array<string, mixed>
 + *                          : ( $output is 'ARRAY_N' ? non-empty-
 array<int, mixed>
 + *                                                   : WP_Comment|null )
 )
   */
  function get_comment( $comment = null, $output = OBJECT ) {
         if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
 diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
 index 1b36ad58fc..50130770a3 100644
 --- a/src/wp-includes/post.php
 +++ b/src/wp-includes/post.php
 @@ -1640,6 +1640,7 @@ function get_post_type_object( $post_type ) {
   *                               element from the array needs to match;
 'and' means all elements
   *                               must match; 'not' means no elements may
 match. Default 'and'.
   * @return string[]|WP_Post_Type[] An array of post type names or
 objects.
 + * @phpstan-return ( $output is 'names' ? string[] : WP_Post_Type[] )
   */
  function get_post_types( $args = array(), $output = 'names', $operator =
 'and' ) {
         global $wp_post_types;
 }}}

 That first change is for `get_comment()` and a similar change could be
 made for `get_post()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64238#comment:71>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list