Repository navigation
Update PHPStan to 2.x and exclude includes/ from analysis - #972
Merged
Merged
Conversation
Bumps szepeviktor/phpstan-wordpress to ^2.0, which pulls in PHPStan 2.2 and the updated WordPress stubs. CI was warning that the 1.12.x series had been unmaintained for over a year. The includes/ directory is dropped from the analysed paths: those files are taken over from WordPress core and are already checked upstream. PHPStan 2 infers types more aggressively, which surfaced a handful of alreadyNarrowedType errors. treatPhpDocTypesAsCertain is disabled since runtime values in WordPress are not guaranteed to match documented types, and the redundant class_exists()/method_exists() guard around Two_Factor_Core::get_providers() is removed.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Collaborator
Author
|
after merging the PR #974 of @georgestephanis this is green now. ready for a review! |
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.
Why
CI was emitting an upgrade warning on every
lint:phpstanrun:The run also failed with a single error in
includes/function.login-footer.php(if.alwaysFalse).What
szepeviktor/phpstan-wordpressgoes from^1.3to^2.0, which pulls inphpstan/phpstan2.2.13 (was 1.12.34) andphp-stubs/wordpress-stubs7.1.0 (was 6.9.4). PHPStan itself stays a transitive dependency of the extension.includes/from the analysed paths — those files are taken over from WordPress core and are already checked upstream. This also resolves theif.alwaysFalsefailure without touching code that is intentionally kept close to core.treatPhpDocTypesAsCertain: false— PHPStan 2 infers types more aggressively and started reportingalreadyNarrowedTypeon defensive runtime checks. Runtime values in WordPress are not guaranteed to match the documented PHPDoc types, so the defensive checks stay and the check is relaxed instead.class_exists( 'Two_Factor_Core' ) && method_exists( 'Two_Factor_Core', 'get_providers' )is statically always true (the class is loaded unconditionally bytwo-factor.php). This was the one error not covered bytreatPhpDocTypesAsCertain. Theis_array()fallback on the return value is kept.No baseline entries,
@phpstan-ignorecomments, or type casts were added.Testing
composer lint-phpstan— no errorscomposer lint(PHPCS) — 22/22 clean