From 5491a49885f880efe9660b24387524e8f96dad7e Mon Sep 17 00:00:00 2001 From: Tyler Stokes Date: Sun, 16 Aug 2026 13:16:06 -0700 Subject: [PATCH] Code Quality: Annotate three more impure functions for PHPStan. PHPStan infers `current_theme_supports()`, `wp_installing()` and `is_front_page()` as pure, so it remembers what each returned and reuses that value at a later call in the same scope. All three read state that can change between calls: `current_theme_supports()` reads the `$_wp_theme_features` global and applies the `current_theme_supports-{$feature}` filter, `wp_installing()` reads a static that the same function can also set, and `is_front_page()` reads the `$wp_query` global. This resolves three baselined errors: the `! current_theme_supports( 'custom-header', 'flex-height' )` check in `Custom_Image_Header::step_1()`, the `! wp_installing()` branch in `get_transient()`, and the repeated `is_front_page()` call in `redirect_canonical()`. The baselines were regenerated with: {{{ composer phpstan:baselines -- --identifier=booleanNot.alwaysTrue,booleanAnd.leftAlwaysTrue }}} Props tstokes8040. See #65817. --- src/wp-includes/load.php | 2 ++ src/wp-includes/query.php | 2 ++ src/wp-includes/theme.php | 2 ++ tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon | 5 ----- tests/phpstan/baselines/booleanNot.alwaysTrue.neon | 10 ---------- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 27c58b57dd671..4b32257cfad5e 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1629,6 +1629,8 @@ function wp_load_translations_early() { * Omit this parameter if you only want to fetch the current status. * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will * report whether WP was in installing mode prior to the change to `$is_installing`. + * + * @phpstan-impure */ function wp_installing( $is_installing = null ) { static $installing = null; diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 60571c01cb880..8db70d585a493 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -462,6 +462,8 @@ function is_comment_feed() { * @global WP_Query $wp_query WordPress Query object. * * @return bool Whether the query is for the front page of the site. + * + * @phpstan-impure */ function is_front_page() { global $wp_query; diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 07869ae61d0ff..b19237098f788 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -3155,6 +3155,8 @@ function _remove_theme_support( $feature ) { * of possible values. * @param mixed ...$args Optional extra arguments to be checked against certain features. * @return bool True if the active theme supports the feature, false otherwise. + * + * @phpstan-impure */ function current_theme_supports( $feature, ...$args ) { global $_wp_theme_features; diff --git a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon index c64a48177e085..d93b0e1c6cad9 100644 --- a/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon +++ b/tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon @@ -33,11 +33,6 @@ parameters: identifier: booleanAnd.leftAlwaysTrue count: 1 path: ../../../src/wp-includes/block-template-utils.php - - - message: '#^Left side of && is always true\.$#' - identifier: booleanAnd.leftAlwaysTrue - count: 1 - path: ../../../src/wp-includes/canonical.php - message: '#^Left side of && is always true\.$#' identifier: booleanAnd.leftAlwaysTrue diff --git a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon index ae0b0afe52c56..d3ab0987d55f5 100644 --- a/tests/phpstan/baselines/booleanNot.alwaysTrue.neon +++ b/tests/phpstan/baselines/booleanNot.alwaysTrue.neon @@ -18,11 +18,6 @@ parameters: ignoreErrors: - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../src/wp-admin/includes/class-custom-image-header.php - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue @@ -53,8 +48,3 @@ parameters: identifier: booleanNot.alwaysTrue count: 1 path: ../../../src/wp-includes/general-template.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../src/wp-includes/option.php