Weave 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

Dead Code Detector Laravel Package

shipmonk/dead-code-detector

PHPStan extension that finds unused PHP code: dead methods, constants, enum cases, properties, dead cycles, and transitively dead members. Detects dead tested code and can automatically remove unused code. Supports Symfony and other libraries with customizable usage providers.

View on GitHub
Deep Wiki
Context7

shipmonk/dead-code-detector is a PHPStan extension that spots unused PHP code in your project, including dead cycles, transitively dead members, and dead code covered only by tests. It also supports automatic removal of unused code, so you can clean up your codebase quickly.

  • Built-in support for Symfony and other popular libraries via usage providers
  • Detects dead methods, constants, enum cases, and properties (never read/written)
  • Configurable rules via phpstan.neon, with extension-installer support
  • Requires analysing your whole codebase (e.g. src and tests) for accurate results
Frequently asked questions about Dead Code Detector
What is shipmonk/dead-code-detector and how does it work?
It is a PHPStan extension that analyzes your codebase for unused class members and dead cycles, including transitive dead code and members referenced only by tests. It works by loading PHPStan rules and usage providers, then reports dead code during a normal PHPStan run. For Laravel projects it adds framework-aware usage detection so container calls, routes, events, and attributes are not flagged incorrectly.
How do I install shipmonk/dead-code-detector in a Laravel project?
Install it as a dev dependency with composer require --dev shipmonk/dead-code-detector. Then include vendor/shipmonk/dead-code-detector/rules.neon in phpstan.neon.dist, or rely on PHPStan's official extension-installer. Run vendor/bin/phpstan against both src and tests so all usages can be discovered.
Does shipmonk/dead-code-detector support Laravel?
Yes, it is designed to fit Laravel codebases and includes Laravel-aware usage detection for Eloquent, routes, events, console commands, and attributes. For dynamic Laravel patterns it misses, you can add or adjust usage providers. It runs as part of PHPStan, so it does not modify your application runtime.
How do I configure dead-code-detector in phpstan.neon?
Add the rules.neon include and configure the shipmonkDeadCode parameters. You can toggle detection of deadMethods, deadConstants, deadEnumCases, and deadProperties with neverRead and neverWritten options, and you can configure usageProviders. Keep the default providers unless you need to exclude vendor or reflection-related usage.
Can shipmonk/dead-code-detector detect code that is only used in tests?
Yes. If you analyze both src and tests, it can distinguish members used only by tests and report them as dead tested code. You can enable the tests usage excluder so test-only references are not treated as production usage. This helps surface code that exists only to satisfy tests.
Will it produce false positives for Laravel dynamic features like app()->make() or magic methods?
It can, because Laravel relies on dynamic calls, magic methods, route binding, and container resolution that static analysis cannot always see. The package mitigates this with Laravel and library usage providers plus configurable exclusions. If you hit false positives, implement a custom MemberUsageProvider or disable problematic providers, and review baseline changes carefully.
Can shipmonk/dead-code-detector automatically remove dead code?
Yes, it supports an --error-format removeDeadCode mode that can automatically remove unused PHP code. Automated removal should be gated behind manual review or a dedicated PR because it can break tests or dynamic behavior. Prefer running it on a clean branch and verifying with your full test suite.
Which libraries and class members does shipmonk/dead-code-detector support?
It detects unused methods, constants, properties with never read and never written modes, enum cases, dead cycles, and transitive dead members. It supports Laravel plus libraries such as Symfony, Doctrine, Twig, and PHPUnit, with integrations auto-enabled when those dependencies are present. Supported library features include attributes for commands, listeners, routes, and scheduled tasks where applicable.
How does shipmonk/dead-code-detector perform on large Laravel codebases?
Performance depends on codebase size and PHPStan configuration; large Laravel monoliths can be slower because PHPStan analyzes the whole codebase. Run analysis incrementally, use PHPStan parallelism where available, and exclude vendor, storage, and generated paths. Start with a baseline and address new dead code in CI rather than blocking on the whole legacy backlog.
Is shipmonk/dead-code-detector actively maintained, and what should I watch for with PHPStan updates?
It is actively maintained and tracks PHPStan's evolving extension API, so pin the package version and review release notes before upgrading PHPStan. There is no exact Laravel version matrix in the package description, so check Composer constraints for PHP and PHPStan compatibility. For alternatives, you can combine PHPStan strict rules with other dead-code tools, but this package's Laravel-aware providers and auto-removal are its differentiators.
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.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin