Make WordPress Core


Ignore:
Timestamp:
08/26/2026 09:44:34 PM (33 hours ago)
Author:
westonruter
Message:

Code Quality: Resolve the isset.variable PHPStan errors.

Each of the six baselined errors was an isset() on a variable that is always defined and not nullable, or never defined at all. The $_POST superglobal is always set, so the checks on it in Custom_Image_Header::step_2() and get_media_item() were unconditional; the latter becomes ! empty( $_POST ), which is what isset() plus count() already meant. PHP_VERSION_ID is constant within a request, so the guard above the $loader check in WP_oEmbed::_parse_xml() already decides it. The namespace group in WP_Block_Parser::next_token() is a non-trailing optional group under PREG_OFFSET_CAPTURE, which PHP always populates. In wp_edit_theme_plugin_file() the only assignment to $stylesheet is guarded by a ! empty() on the argument it comes from, so a truthiness test cannot diverge from isset().

The remaining error is the reverse case: $s in load_template() is undefined to static analysis because it arrives through extract(). Assigning the query vars to a local first, and annotating that local as array{ s?: scalar, ... }, resolves both that report and the inline @phpstan-ignore above it. The annotation is deliberately local rather than on WP_Query::$query_vars, where an unsealed shape makes every unnamed key "might not exist" and reports more than it resolves. scalar rather than string is what WP_Query::parse_query() actually guarantees, since it gates the value only with is_scalar().

With the last entry fixed, the baseline file and its entry in the includes of phpstan.neon.dist are removed.

Developed in https://github.com/WordPress/wordpress-develop/pull/13023.
Follow-up to r28407, r32298, r41721, r48789, r60351, r61504, r61699, r63019.

Props westonruter, apermo.
See #65817.

File:
1 edited

Legend:

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

    r63338 r63351  
    17741774        if ( isset( $_GET['post_id'] ) ) {
    17751775                $calling_post_id = absint( $_GET['post_id'] );
    1776         } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set.
     1776        } elseif ( ! empty( $_POST ) ) { // Like for async-upload where $_GET['post_id'] isn't set.
    17771777                $calling_post_id = $post->post_parent;
    17781778        }
Note: See TracChangeset for help on using the changeset viewer.