- How do I install shipmonk/dead-code-detector for Laravel?
- Run `composer require --dev shipmonk/dead-code-detector` and add `includes: - vendor/shipmonk/dead-code-detector/rules.neon` to your `phpstan.neon` file. No additional Laravel-specific setup is needed for basic usage.
- Does this package work with Laravel’s Eloquent, events, or jobs?
- Yes, it automatically detects dead code in Eloquent models, event listeners, jobs, and other Laravel patterns without manual configuration. Just run the analyzer on your full codebase (including tests).
- Will this tool flag false positives for Laravel’s dynamic method calls (e.g., `app()->make()`)?
- It can, but you can mitigate this by configuring custom `MemberUsageProvider` classes or excluding specific methods in `phpstan.neon`. The package supports Symfony’s DIC detection, which helps with Laravel’s service container.
- Can I automatically remove dead code in Laravel, or should I review changes first?
- You can use the `--error-format removeDeadCode` flag, but this is destructive. Test it in a branch first or use it as a warning-only check in CI. Always review removals manually before merging.
- Does this package support detecting dead code used *only* in tests (e.g., test doubles, mocks)?
- Yes, it detects dead code referenced exclusively in tests. However, analyze your entire codebase (src + tests) to ensure accurate results, as dead code might be used transitively.
- How does this integrate with Laravel’s CI/CD pipeline (e.g., GitHub Actions)?
- Add it to your CI workflow as a static analysis step. Use `vendor/bin/phpstan analyze` with `--memory-limit` flags for large projects. Fail builds on warnings or errors based on your team’s policy.
- Are there Laravel-specific configurations I should add to phpstan.neon?
- For Laravel, ensure `parameters.shipmonkDeadCode.usageProviders` includes Symfony’s container paths (if using `phpstan/phpstan-symfony`). Disable checks for dynamic patterns like `app()->make()` via exclusions if needed.
- What Laravel versions and PHPStan versions does this package support?
- It works with Laravel 8+ and PHPStan 1.0+. Check the [GitHub repo](https://github.com/shipmonk-rnd/dead-code-detector) for version-specific notes. Ensure your PHPStan version matches the package’s requirements.
- Can I exclude certain classes/methods from dead code detection in Laravel?
- Yes, use `parameters.shipmonkDeadCode.exclude` in `phpstan.neon` to exclude classes, methods, or namespaces. For example, exclude test-only classes or legacy code that’s intentionally unused.
- What are the alternatives to shipmonk/dead-code-detector for Laravel?
- Alternatives include PHPStan’s built-in `DeadCode` rule (less feature-rich), Psalm’s `UnusedCode` rule, or custom scripts with `phpmd` or `phpstan` + regex. This package stands out for its Laravel/Symfony integration and dead cycle detection.