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 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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Codebase Health & Maintainability:

    • Enable automated dead code detection to reduce technical debt, improve readability, and accelerate future development.
    • Align with SOLID principles by removing unused methods/properties, reducing class bloat, and improving cohesion.
    • Support refactoring initiatives (e.g., breaking down monolithic classes) by identifying safe-to-remove code.
  • Developer Productivity:

    • Integrate into CI/CD pipelines to block merges of PRs introducing dead code (via PHPStan rules).
    • Reduce cognitive load for developers by automating cleanup of unused code (e.g., via removeDeadCode format).
    • Enable faster onboarding by ensuring the codebase is lean and self-documenting.
  • Framework-Specific Roadmaps:

    • Laravel/Symfony: Detect dead routes, event listeners, commands, or Eloquent observers/factories.
    • Testing: Identify test-specific dead code (e.g., unused data providers) without affecting production logic.
    • Twig/Doctrine: Remove unused filters, listeners, or enum cases tied to templates/ORM.
  • Build vs. Buy:

    • Buy: Avoid reinventing dead-code detection (e.g., custom static analysis tools) by leveraging this mature, library-aware solution.
    • Customize: Extend via usage providers/excluders for edge cases (e.g., dynamic method calls via reflection).
  • Use Cases:

    • Pre-release cleanup: Run before major versions to remove cruft.
    • Legacy modernization: Prioritize removal of dead code in large, unmaintained codebases.
    • Security: Reduce attack surface by eliminating unused endpoints, listeners, or sensitive methods.

When to Consider This Package

  • Adopt if:

    • Your PHP codebase (Laravel/Symfony/Twig/etc.) has grown organically with accumulated dead code.
    • You prioritize developer velocity and want to automate code hygiene.
    • Your team uses PHPStan and wants to extend its capabilities without heavy tooling overhead.
    • You need framework-specific dead-code detection (e.g., Laravel routes, Doctrine listeners).
    • You’re willing to invest in customization (e.g., usage providers) for niche use cases.
  • Look elsewhere if:

    • Your stack doesn’t use PHPStan (e.g., heavy JavaScript/TypeScript) or relies on non-PHP frameworks.
    • You need runtime dead-code detection (e.g., unused methods called via dynamic proxies).
    • Your codebase is highly dynamic (e.g., heavy use of eval(), create_function(), or magic methods like __call).
    • You require GUI/IDE integration (this is CLI/PHPStan-focused).
    • Your team lacks PHPStan familiarity (setup requires Neon config expertise).

How to Pitch It (Stakeholders)

For Executives:

*"This tool automates the cleanup of unused PHP code—like a 'git clean' for your logic. For every 10% of dead code removed, we reduce:

  • Developer onboarding time (less cruft to sift through).
  • Technical debt interest (fewer legacy methods to maintain).
  • Security risk (unused endpoints/listeners are attack vectors).

It integrates seamlessly with our existing PHPStan setup, requires no new infrastructure, and can be run in CI to block dead-code PRs. For Laravel/Symfony projects, it even understands framework-specific dead code (e.g., unused routes or Doctrine listeners). We can pilot it on [Module X] to measure impact before rolling out."*

For Engineering:

*"This is a PHPStan extension that detects and removes dead code—methods, properties, constants, and even enum cases—with framework-specific awareness (Laravel routes, Symfony event listeners, Twig filters, etc.). Key benefits:

  • Automated cleanup: Run phpstan --error-format=removeDeadCode to auto-remove unused code.
  • Transitive detection: Finds dead methods called only by other dead methods (with configurable reporting).
  • Test-aware: Optionally exclude test-only usages while keeping production code clean.
  • Extensible: Add custom usage providers for edge cases (e.g., dynamic reflection calls).

Setup:

  1. Add to composer.json: shipmonk/dead-code-detector.
  2. Include rules in phpstan.neon:
    includes:
        - vendor/shipmonk/dead-code-detector/rules.neon
    
  3. Run phpstan analyse to see dead code, or use --error-format=removeDeadCode to auto-clean.

Example Output:

Unused UserFacade::updateUserAddress
  🪪 Dead method (transitively unused: Address::setPostalCode, etc.)

Next Steps: Let’s run it on [Project Y] to validate false-positive rates before CI integration."*


Key Selling Points:

  • Zero new tools: Leverages existing PHPStan.
  • Framework-native: Understands Laravel/Symfony/Twig/Doctrine.
  • Actionable: Auto-remove or flag dead code.
  • Low risk: Start with analysis-only mode.
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.
codraw/entity-migrator
codraw/doctrine-extra
codraw/aws-tool-kit
codraw/validator
codraw/workflow
codraw/open-api
codraw/cron-job
codraw/process
codraw/log
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony