shipmonk/dead-code-detector
PHPStan extension that finds and can auto-remove unused PHP code: dead methods/properties/constants/enum cases, dead cycles, transitive dead members, and even dead tested code. Supports popular libs like Symfony and Doctrine with customizable usage providers.
composer require --dev shipmonk/dead-code-detector.vendor/shipmonk/dead-code-detector/rules.neon to your includes in phpstan.neon.dist.vendor/bin/phpstan analyse src tests.detect config if needed (e.g. enable deadProperties or deadEnumCases only after verifying false positives).--error-format checkstyle | grep -c "dead"), fix top-level dead methods first.phpstan-symfony) are installed and configured.vendor/bin/phpstan analyse --error-format removeDeadCode after review, especially after refactors or migrations.ReflectionBasedMemberUsageProvider for simple reflection-based needs (e.g. dynamic calls on known marker interfaces).MemberUsageProvider for AST-based detection (e.g. custom deserialization or CLI argument binding).src coverage: enable usageExcluders.tests to distinguish dead in prod vs dead in codebase — useful for maintenance-heavy codebases where tests may lag behind.tests in analysis = many methods falsely flagged as dead; always run over full scope.usageOverMixed pitfalls: disabling mixed-based magic calls ($obj->$method) reduces false positives in strict codebases — use usageExcluders.usageOverMixed to opt out.reportTransitivelyDeadMethodAsSeparateError for granular visibility — helpful for large refactors.editorUrl (e.g. vscode://file/%path%:%line%) to jump directly to excluded test usages in removal output.-vvv: to diagnose why a method is considered used, run analysis with verbosity to see usage origins (e.g., "Used via #[AsCommand] from App\Command\MyCommand").^0.5.0).How can I help you explore Laravel packages today?