shipmonk/dead-code-detector
PHPStan extension that finds unused PHP code: dead methods, properties, constants, enum cases, cycles, and transitive “dead-tested” members. Supports popular frameworks like Symfony and can auto-remove dead code. Configurable detection and usage providers.
#[AsCommand], #[ObservedBy]).composer require --dev), and integration requires minimal configuration (adding includes to phpstan.neon). No runtime dependencies or framework modifications are needed.--error-format removeDeadCode flag enables automated cleanup, though this should be gated behind manual review.handle() in controllers) may trigger false positives. The package mitigates this with customizable usage providers, but edge cases (e.g., app()->make() calls) might require manual exclusion.MemberUsageExcluder interface or configure shipmonkDeadCode.usageProviders to disable problematic providers (e.g., vendor, reflection).--generate-baseline) or exclude specific paths (e.g., vendor/, storage/) from the scan.#[AsPeriodicTask]) may require updates.composer.json.tests usage excluder to avoid false positives.app()->bind(), macro() calls) that might bypass static analysis? If so, implement a custom MemberUsageProvider.--error-format removeDeadCode) or reviewed manually first? Automated removal risks breaking tests or logic.tests excluder but verify that test-only usages are clearly marked (e.g., Unused X (all usages excluded by tests excluder)).--parallel) or split by module?Route::get(), resource(), controller@method syntax.Event::listen(), Schedule::job(), #[AsCommand].--dev) and run against a subset of modules (e.g., a single feature branch).phpstan.neon with minimal settings:
includes:
- vendor/shipmonk/dead-code-detector/rules.neon
parameters:
shipmonkDeadCode:
usageExcluders:
tests:
enabled: true
main).--error-format=github for actionable feedback.vendor/bin/phpstan analyse --error-format=removeDeadCode --level=max
git diff --exit-code || echo "Dead code removal failed"
#[AsPeriodicTask]).phpstan/phpstan:^1.10).phpstan/phpstan-symfony) interact unexpectedly.app()->make(), macro()) that might cause false positives.phpstan.neon to exclude non-critical paths (e.g., storage/logs/, bootstrap/cache/).--level=max to catch all potential dead code.MemberUsageProvider for unsupported patterns (e.g., custom middleware invocations).shipmonkDeadCode parameters to disable problematic providers (e.g., vendor if using app()->make() heavily).#[AsPeriodicTask]) may require updates to the package or custom providers.MemberUsageProvider implementations may break if PHPStan’s internals change.MemberUsageExcluder for common patterns (e.g., exclude all app()->make() calls) and document exclusions in phpstan.neon.--debug flag and the package’s detailed error messages (e.g., transitive dead code tips).How can I help you explore Laravel packages today?