Skip to content

Conversation

@IanDelMar
Copy link
Contributor

@IanDelMar IanDelMar commented Jul 7, 2025

This PR improves the handling of dynamic constants by adding those defined in bootstrap.php to the dynamicConstantNames list in extension.neon. This change ensures that PHPStan generalises the types of these constants. In particular, for directory constants, this prevents the RequireFileExistsRule from reporting errors about non-existent WordPress core files.

Regarding WP_DEBUG_LOG: although it is currently generalised to bool, it may in fact hold either a boolean or a string value. Including define('WP_DEBUG_LOG', true); incorrectly narrows its type to bool. However, PHPStan does not currently support dynamic constants with multiple types. Removing WP_DEBUG_LOG from bootstrap.php would 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

@szepeviktor
Copy link
Owner

I need comments to merge this.

@IanDelMar
Copy link
Contributor Author

Sure! This PR still needs some tests anyway, hence it’s a draft.

@szepeviktor
Copy link
Owner

I mean comments from others.

@IanDelMar
Copy link
Contributor Author

Yes, I had already understood you meant comments from others.

@IanDelMar IanDelMar marked this pull request as ready for review July 8, 2025 01:32
@slaFFik
Copy link

slaFFik commented Jul 8, 2025

LGTM :)

@szepeviktor szepeviktor merged commit 1d6d3f3 into szepeviktor:2.x Jul 25, 2025
1 of 2 checks passed
@IanDelMar IanDelMar deleted the dynamic-constants branch July 31, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Most constants for paths like are set incorrectly PHPStan 1.12.1 requireFile new rule

4 participants