Skip to content

Extract ComposerIntrospector to deduplicate vendor dir and composer.json handling#399

Merged
janedbal merged 2 commits into
masterfrom
extract-composer-root-locator
Jul 13, 2026
Merged

Extract ComposerIntrospector to deduplicate vendor dir and composer.json handling#399
janedbal merged 2 commits into
masterfrom
extract-composer-root-locator

Conversation

@janedbal

@janedbal janedbal commented Jul 13, 2026

Copy link
Copy Markdown
Member

Follow-up to #397, which added a third identical copy of the "single registered vendor dir" autodetection snippet and a second copy of the composer.json read + decode block.

Changes

  • New ShipMonk\PHPStan\DeadCode\Composer\ComposerIntrospector service (registered in rules.neon) with:
    • autodetectVendorDir() — the shared ClassLoader::getRegisteredLoaders() / phar-filter / single-loader logic
    • autodetectComposerJsonPath()vendorDir/../composer.json + is_file check
    • parseComposerJson() — read + json_decode + error handling
  • TestsUsageExcluder, ComposerUsageProvider and SymfonyUsageProvider now inject it instead of carrying private copies (Symfony only needs autodetectVendorDir() for its ../config derivation).
  • TestsUsageExcluder::extractAutoloadPaths() now takes mixed and validates the structure itself, since the shared parseComposerJson() no longer pretends to know the autoload-dev shape via a PhpDoc array shape.

No behavior change for any composer.json that composer itself accepts; the only difference is that a few degenerate inputs (scalar top-level JSON, malformed autoload-dev shapes) which previously crashed TestsUsageExcluder with a TypeError now degrade to "no dev paths detected". VendorUsageProvider is intentionally untouched as it needs all vendor dirs including the phar one.

Co-Authored-By: Claude Code

janedbal added 2 commits July 13, 2026 17:30
…on handling

Three copies of the "single registered vendor dir" autodetection
(TestsUsageExcluder, SymfonyUsageProvider, ComposerUsageProvider) and two
copies of the composer.json read+decode block are replaced by a single
ComposerRootLocator service.

Co-Authored-By: Claude Code
@janedbal janedbal changed the title Extract ComposerRootLocator to deduplicate vendor dir and composer.json handling Extract ComposerIntrospector to deduplicate vendor dir and composer.json handling Jul 13, 2026
@janedbal janedbal marked this pull request as ready for review July 13, 2026 19:15
@janedbal janedbal merged commit 0487c20 into master Jul 13, 2026
33 checks passed
@janedbal janedbal deleted the extract-composer-root-locator branch July 13, 2026 19:16
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.

1 participant