Add method to classmap to detect ambiguous namespaces - #44
Open
PrinsFrank wants to merge 2 commits into
Open
Conversation
PrinsFrank
force-pushed
the
add-ambigous-namespace-detection
branch
2 times, most recently
from
July 30, 2026 19:19
52b36ed to
6c5e143
Compare
PrinsFrank
force-pushed
the
add-ambigous-namespace-detection
branch
from
July 31, 2026 06:51
6c5e143 to
2a159db
Compare
Member
|
Thanks, please see PrinsFrank#1 |
getAmbiguousNamespaces() compared namespace strings and never looked at the paths the ClassMap already holds, so it reported namespaces which only differ in casing even when they live in folders that do not fold into each other. That fires on aws/aws-sdk-php, which uses the Aws namespace, together with its required aws/aws-crt-php dependency, which uses AWS. Their folders are aws-sdk-php/src and aws-crt-php/src/AWS, so nothing collides on any filesystem, yet every project depending on the AWS SDK would have been warned about it, and with composer/composer#13007 dump-autoload --strict-ambiguous would have exited 2. Fold path prefixes rather than namespace prefixes, which reports nothing on the aws tree while still catching the case this is meant to catch. Renamed to getAmbiguousFolders() as it now returns the paths involved, which also lets the consumer point at the folders to rename. Comparing paths additionally catches files that only differ in casing (Foo\Bar and Foo\bar are the same class to PHP, and neither getAmbiguousClasses() nor the old method saw those) and PSR-0 underscore pseudo-namespaces, which never contained a backslash to split on. Also: - stop at the topmost difference in a path, one renamed folder no longer gets reported once per namespace below it - sort the output, it followed Symfony Finder traversal order and so varied between machines - accept a $duplicatesFilter like getAmbiguousClasses() does, so ambiguity in dependencies you do not control can be filtered out. This is only possible now that paths are what gets compared - fold ASCII only, strtolower() is locale dependent before PHP 8.2 and this library supports 7.2+ Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MZmJZgxdTKD4zekKJDrmi9
Contributor
Author
|
@Seldaek Thanks! I've rebased the commits into this PR, was that your intention? If not, I think you do have permission to (force) push to this fork, but I can also fix up the commits in a way you'd prefer. I've also updated composer/composer#13007 with the changes from here! Let me know if you want me to do anything else! |
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.
Supporting PR for composer/composer#13007