shipmonk/dead-code-detector
PHPStan extension that detects unused PHP code: dead methods, properties, constants, and enum cases. Finds dead cycles and transitive dead members, can flag dead tested code, supports popular frameworks (e.g., Symfony), and offers customizable usage providers with optional auto-removal.
Codebase Health & Maintainability:
Roadmap Prioritization:
Use Cases:
#[AsEventListener]) to reduce attack surface.Cross-Team Alignment:
phpstan/extension-installer: For basic dead-code detection without removal.*"This tool automates the cleanup of unused PHP code—like a ‘spring cleaning’ for our codebase. For every 10% of dead code we remove:
- Dev productivity improves by reducing context-switching time (studies show unused code increases onboarding time by 20–30%).
- CI/CD speeds up by shrinking test suites and analysis scope (target: 15–20% faster builds).
- Technical debt decreases, lowering future refactoring costs.
Cost: Minimal (one-time setup + ~5 dev-hours/year for maintenance). ROI: 3–5x in saved engineering time. We’ll pilot it in [High-Maintenance Module X] and measure impact before scaling."*
*"This is a PHPStan extension that detects and removes dead code—methods, properties, constants, and even framework-specific cruft (e.g., unused Symfony event listeners or Laravel routes). It’s non-destructive by default (shows what it would remove before acting) and supports:
- Framework integrations: Symfony, Laravel, Doctrine, PHPUnit, Twig, etc.
- Customization: Extend it for your DI container or runtime magic (e.g.,
#[AsTwigComponent]).- Safe removal: Exclude test-only usages and handle transitive dead code (e.g., if
MethodAcallsMethodB, both are removed).Why now?
- Our [Module Y] has Z% dead code (from manual audit), slowing down PR reviews.
- [Team Z] spends ~X hours/week manually cleaning up unused callbacks.
- It integrates with our existing PHPStan setup (no new tools).
Next steps:
- Run it in dry mode against [Target Module] to validate false-positive rate.
- Automate removal in CI for low-risk files (e.g., non-test classes).
- Expand to other modules based on impact."*
*"Imagine running a command that:
- Finds unused methods, properties, and constants (even in tests!).
- Automatically removes them with one flag (
--removeDeadCode).- Works with Symfony/Laravel/Eloquent out of the box (no config for 90% of use cases).
- Safe for tests: Exclude usages only in
tests/if needed.Example workflow:
# Step 1: Find dead code (dry run) vendor/bin/phpstan analyse --error-format=removeDeadCode --no-progress # Step 2: Review changes (IDE will show diffs) # Step 3: Remove for real vendor/bin/phpstan analyse --error-format=removeDeadCodePro tip: Add it to your pre-commit hook for critical paths or run weekly in CI to keep the codebase lean.
Try it today: Just add it to
composer.jsonand updatephpstan.neon!"*
How can I help you explore Laravel packages today?