Check written case of single-part class names imported with use statements - #6271
Merged
ondrejmirtes merged 2 commits intoAug 26, 2026
Merged
Conversation
…ments NameResolver replaces a single-part imported name with the use statement's spelling. The written case survives only in the originalName attribute. ClassCaseSensitivityCheck now reconstructs the written name from that attribute. This makes the check work for attributes, instantiation, class constants, instanceof, extends, implements and catch. FunctionDefinitionCheck now shares the same reconstruction logic.
janedbal
marked this pull request as ready for review
August 26, 2026 08:47
Collaborator
|
This pull request has been marked as ready for review. |
Member
|
Thank you! |
Member
|
FYI decided this causes too many errors in existing projects and it will be a bleeding edge feature: #6285 (enabled for everyone in PHPStan 3.0). |
ondrejmirtes
added a commit
that referenced
this pull request
Aug 27, 2026
The written-case reconstruction from PR #6271 is now gated behind the new checkImportedClassNameCase feature toggle, enabled in bleedingEdge.neon. With the toggle off, ClassCaseSensitivityCheck and FunctionDefinitionCheck behave exactly as before that PR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MGaekUJQDX9kJR9PdJtQu
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.
NameResolver replaces a single-part imported name with the use statement's spelling. The written case survives only in the
originalNameattribute.ClassCaseSensitivityChecknow reconstructs the written name from that attribute.Because every affected rule goes through this check, one change fixes the case check for attributes,
new,::class,instanceof,extends,implements, trait use andcatch. Multi-part, fully qualified and relative names keep their written case in the resolved name, so the reconstruction applies only to single-part unqualified names. The existingUseAliasVisitorskip keeps explicituse ... asaliases exempt (phpstan/phpstan#14205 stays fixed).FunctionDefinitionChecknow shares the same reconstruction logic instead of its own copy. This also fixes its old splice logic, which produced non-existent names likeApp\S\FOOfor aliased namespace prefixes and silently skipped the check.Closes phpstan/phpstan#12827
Integration-test triage: the new
nameCaseerrors in doctrine/dbal, neos/flow, drupal and efabrica/phpstan-latte are true positives (e.g. dbal importsSQLitePlatformand writesextends SqlitePlatform; neos importsMySQLPlatformand writesinstanceof MySqlPlatform). The rector, larastan, phpstan-laravel and phpstan-doctrine failures come from unrelated2.2.xchanges (toMutatingScope()deprecation, model property message), and thee2e/bug-11826job already fails on2.2.x.