Skip to content

Add method to classmap to detect ambiguous namespaces - #44

Open
PrinsFrank wants to merge 2 commits into
composer:mainfrom
PrinsFrank:add-ambigous-namespace-detection
Open

Add method to classmap to detect ambiguous namespaces#44
PrinsFrank wants to merge 2 commits into
composer:mainfrom
PrinsFrank:add-ambigous-namespace-detection

Conversation

@PrinsFrank

Copy link
Copy Markdown
Contributor

Supporting PR for composer/composer#13007

@PrinsFrank
PrinsFrank force-pushed the add-ambigous-namespace-detection branch 2 times, most recently from 52b36ed to 6c5e143 Compare July 30, 2026 19:19
@Seldaek

Seldaek commented Aug 2, 2026

Copy link
Copy Markdown
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
@PrinsFrank

Copy link
Copy Markdown
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!

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.

2 participants