Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dead Code Detector Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install with composer require --dev shipmonk/dead-code-detector.
  2. Enable in PHPStan by adding vendor/shipmonk/dead-code-detector/rules.neon to your includes in phpstan.neon.dist.
  3. Run analysis on all source and test files — analysis scope must be complete to avoid false positives: vendor/bin/phpstan analyse src tests.
  4. First real-world use: run on a small submodule to see what gets flagged; adjust detect config if needed (e.g. enable deadProperties or deadEnumCases only after verifying false positives).

Implementation Patterns

  • Adopt incrementally: enable in CI with failing threshold (e.g. --error-format checkstyle | grep -c "dead"), fix top-level dead methods first.
  • Library integrations are automatic: no extra config needed for Symfony/Doctrine/PHPUnit — just ensure required PHPStan extensions (e.g. phpstan-symfony) are installed and configured.
  • Leverage auto-removal for low-risk cleanup: vendor/bin/phpstan analyse --error-format removeDeadCode after review, especially after refactors or migrations.
  • Custom usage providers when magic patterns exist:
    • Use ReflectionBasedMemberUsageProvider for simple reflection-based needs (e.g. dynamic calls on known marker interfaces).
    • Use full MemberUsageProvider for AST-based detection (e.g. custom deserialization or CLI argument binding).
  • Exclude test-only usages for strict src coverage: enable usageExcluders.tests to distinguish dead in prod vs dead in codebase — useful for maintenance-heavy codebases where tests may lag behind.

Gotchas and Tips

  • Scope matters: missing 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.
  • Enum and property detection is off by default — enable only after verifying custom deserializers or hydrators aren’t introducing false positives.
  • Dead cycles & transitivity: initial report shows first dead member; toggle reportTransitivelyDeadMethodAsSeparateError for granular visibility — helpful for large refactors.
  • IDE links in removal mode: set editorUrl (e.g. vscode://file/%path%:%line%) to jump directly to excluded test usages in removal output.
  • Debug with -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").
  • Version warning: interfaces and tags changed in v0.7 — if stuck with PHPStan 1.x, pin to compatible release (e.g. ^0.5.0).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport