Fix handling of dynamic constants #286
Merged
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