Fix handling of dynamic constants#286
Merged
szepeviktor merged 7 commits intoszepeviktor:2.xfrom Jul 25, 2025
Merged
Conversation
Owner
|
I need comments to merge this. |
Contributor
Author
|
Sure! This PR still needs some tests anyway, hence it’s a draft. |
Owner
|
I mean comments from others. |
Contributor
Author
|
Yes, I had already understood you meant comments from others. |
This reverts commit 96deab8. It is handled separately in szepeviktor#287.
|
LGTM :) |
johnbillion
approved these changes
Jul 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the handling of dynamic constants by adding those defined in
bootstrap.phpto thedynamicConstantNameslist inextension.neon. This change ensures that PHPStan generalises the types of these constants. In particular, for directory constants, this prevents theRequireFileExistsRulefrom reporting errors about non-existent WordPress core files.Regarding
WP_DEBUG_LOG: although it is currently generalised tobool, it may in fact hold either a boolean or a string value. Includingdefine('WP_DEBUG_LOG', true);incorrectly narrows its type tobool. However, PHPStan does not currently support dynamic constants with multiple types. RemovingWP_DEBUG_LOGfrombootstrap.phpwould result in constant.notFound errors being reported. As no users have reported issues with the current type, it has been retained for the time being.Furthermore, this PR begins to use WordPress’s actual default values (see discussion).
I have added "tests" (see commit dbbd206); however, these serve mainly to demonstrate PHPStan’s behaviour, rather than testing the functionality of this extension itself. For this reason, I would recommend removing them prior to merging.
Fixes #282, fixes #239
Closes #283
Related #239