From f3a59972dacd2beb790a18526ed4cb971cd15380 Mon Sep 17 00:00:00 2001 From: Callum Bridgford-Whittick Date: Fri, 7 Aug 2026 19:54:42 +0100 Subject: [PATCH] Build/Test Tools: Treat DB_COLLATE and WP_DEVELOPMENT_MODE as dynamic constants. Both constants vary per installation, but PHPStan resolved each to the empty string it is given during analysis: `DB_COLLATE` from `wp-config-sample.php`, pulled in via `scanFiles`, and `WP_DEVELOPMENT_MODE` from `tests/phpstan/bootstrap.php`. Conditionals guarding either were therefore reported as having a constant result. `WP_DEVELOPMENT_MODE` accepts 'core', 'plugin', 'theme', 'all', or an empty string, and `DB_COLLATE` is set per site in `wp-config.php`, so both belong in `dynamicConstantNames` alongside comparable entries such as `WP_DEBUG` and `SCRIPT_DEBUG`. This resolves three baselined errors and empties two baselines, which are removed along with their `includes` entries in `phpstan.neon.dist`: * `ternary.alwaysFalse`: two occurrences in `class-wp-debug-data.php`. * `booleanAnd.rightAlwaysFalse`: one occurrence in `class-wpdb.php`. No source changes are needed; the conditionals were already correct and only the analysis was wrong. Props CallumBW95. See #65817. --- phpstan.neon.dist | 2 -- tests/phpstan/base.neon | 2 ++ .../booleanAnd.rightAlwaysFalse.neon | 25 ------------------- .../baselines/ternary.alwaysFalse.neon | 25 ------------------- 4 files changed, 2 insertions(+), 52 deletions(-) delete mode 100644 tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon delete mode 100644 tests/phpstan/baselines/ternary.alwaysFalse.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 3dcf0f6c2c0de..ad32c24f955fd 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -31,7 +31,6 @@ includes: - tests/phpstan/baselines/booleanAnd.alwaysFalse.neon - tests/phpstan/baselines/booleanAnd.alwaysTrue.neon - tests/phpstan/baselines/booleanAnd.leftAlwaysTrue.neon - - tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon - tests/phpstan/baselines/booleanAnd.rightAlwaysTrue.neon - tests/phpstan/baselines/booleanNot.alwaysFalse.neon - tests/phpstan/baselines/booleanNot.alwaysTrue.neon @@ -90,7 +89,6 @@ includes: - tests/phpstan/baselines/return.unusedType.neon - tests/phpstan/baselines/smallerOrEqual.alwaysTrue.neon - tests/phpstan/baselines/staticClassAccess.privateMethod.neon - - tests/phpstan/baselines/ternary.alwaysFalse.neon - tests/phpstan/baselines/ternary.alwaysTrue.neon - tests/phpstan/baselines/varTag.noVariable.neon - tests/phpstan/baselines/variable.undefined.neon diff --git a/tests/phpstan/base.neon b/tests/phpstan/base.neon index 1c416cb3fe643..ab07051c9ad7a 100644 --- a/tests/phpstan/base.neon +++ b/tests/phpstan/base.neon @@ -79,6 +79,7 @@ parameters: - BACKGROUND_IMAGE - COOKIEPATH - CUSTOM_TAGS + - DB_COLLATE - DISALLOW_FILE_EDIT - DISALLOW_UNFILTERED_HTML - EMPTY_TRASH_DAYS @@ -104,6 +105,7 @@ parameters: - WP_DEBUG - WP_DEBUG_DISPLAY - WP_DEBUG_LOG + - WP_DEVELOPMENT_MODE - WP_LANG_DIR - WP_NETWORK_ADMIN - WP_POST_REVISIONS diff --git a/tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon b/tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon deleted file mode 100644 index 367c8dd35051c..0000000000000 --- a/tests/phpstan/baselines/booleanAnd.rightAlwaysFalse.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `booleanAnd.rightAlwaysFalse` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/booleanAnd.rightAlwaysFalse -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=booleanAnd.rightAlwaysFalse -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Right side of && is always false\.$#' - identifier: booleanAnd.rightAlwaysFalse - count: 1 - path: ../../../src/wp-includes/class-wpdb.php diff --git a/tests/phpstan/baselines/ternary.alwaysFalse.neon b/tests/phpstan/baselines/ternary.alwaysFalse.neon deleted file mode 100644 index b73c48bc42724..0000000000000 --- a/tests/phpstan/baselines/ternary.alwaysFalse.neon +++ /dev/null @@ -1,25 +0,0 @@ -# PHPStan baseline for the `ternary.alwaysFalse` errors in WordPress core. -# -# https://phpstan.org/error-identifiers/ternary.alwaysFalse -# -# Each entry is scoped to a single file and carries an exact occurrence count, -# so that a new instance is reported as a new error rather than being absorbed -# silently. Fixing an occurrence therefore means decrementing or removing its -# entry here as part of the same change. -# -# The goal is to empty this file and delete it, along with the `includes` entry -# for it in phpstan.neon.dist. -# -# Generated by `composer phpstan:baselines`. Do not edit by hand; regenerate with -# -# composer phpstan:baselines -- --identifier=ternary.alwaysFalse -# -# which reruns the analysis with this file suppressed so the errors surface again. - -parameters: - ignoreErrors: - - - message: '#^Ternary operator condition is always false\.$#' - identifier: ternary.alwaysFalse - count: 2 - path: ../../../src/wp-admin/includes/class-wp-debug-data.php