Skip to content

Detect static methods referenced in composer.json scripts - #397

Merged
janedbal merged 4 commits into
masterfrom
composer-scripts-provider
Jul 13, 2026
Merged

Detect static methods referenced in composer.json scripts#397
janedbal merged 4 commits into
masterfrom
composer-scripts-provider

Conversation

@janedbal

@janedbal janedbal commented Jul 8, 2026

Copy link
Copy Markdown
Member

Closes #396

Adds a new default-enabled ComposerUsageProvider that marks static methods referenced as PHP callbacks in the scripts section of composer.json (e.g. "post-install-cmd": "MyVendor\\MyClass::postInstall") as used.

  • Callback detection mirrors Composer\EventDispatcher\EventDispatcher::isPhpScript: an entry is a PHP callback iff it contains :: and no space; @script references and shell commands are ignored, leading backslash is trimmed
  • The root composer.json is autodetected from the registered autoloader's vendor dir; configurable via shipmonkDeadCode.usageProviders.composer.composerJsonPath (single path, since Composer only executes scripts of the root package)
  • Built on ReflectionBasedMemberUsageProvider; callbacks are resolved to their declaring class at load time via ReflectionProvider, so callbacks referencing inherited methods keep working

Co-Authored-By: Claude Code

janedbal added 3 commits July 8, 2026 16:31
Composer only executes scripts of the root package, so there is exactly
one relevant composer.json per autoloader.

Co-Authored-By: Claude Code
Script callbacks are resolved to their declaring class at load time via
ReflectionProvider (same approach as NetteUsageProvider), so callbacks
referencing inherited methods keep working.

Co-Authored-By: Claude Code
@janedbal
janedbal marked this pull request as ready for review July 10, 2026 09:53
@janedbal
janedbal merged commit 717d189 into master Jul 13, 2026
33 checks passed
@janedbal
janedbal deleted the composer-scripts-provider branch July 13, 2026 15:22
@staabm

staabm commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

thank you!

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.

classes used from composer scripts

2 participants