A PHPStan extension that detects unused PHP code (methods, constants, properties, enum cases) and can automatically remove it.
Dead code detector is a PHPStan extension that finds unused PHP code in projects, including methods, constants, properties, and enum cases. It solves the problem of codebase bloat by identifying code that's no longer referenced, helping developers maintain cleaner and more maintainable projects. The tool can automatically remove confirmed dead code and understands complex usage patterns across popular PHP frameworks.
PHP developers working on medium to large codebases who want to maintain clean code and reduce technical debt. Particularly valuable for teams using Symfony, Laravel, Doctrine, or other popular PHP frameworks where framework-specific patterns can obscure code usage.
Developers choose this over basic static analysis tools because it deeply understands PHP framework patterns, minimizes false positives, and provides actionable results with automatic removal capabilities. Its extensible architecture allows customization for project-specific patterns that generic tools would miss.
💀 PHP unused code detection via PHPStan extension. Detects dead cycles, supports libs like Laravel, Symfony, Twig, Doctrine, PHPUnit etc. Can automatically remove dead PHP code. Able to detect dead code used only in tests. Finds unused methods, constants, properties and enum cases.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically detects code usage in Symfony, Laravel, Doctrine, and other popular libraries by understanding attributes, service container calls, and framework-specific patterns, reducing false positives.
Identifies dead cycles and transitively dead members, catching chains of unused methods that only call each other, ensuring comprehensive cleanup beyond isolated cases.
Can automatically delete confirmed dead code with a single command using the removeDeadCode error format in PHPStan, streamlining refactoring and reducing manual work.
Supports custom usage providers and excluders via interfaces, allowing teams to add detection logic for project-specific patterns like serialization or magic calls, as shown in the README examples.
Most magic methods (e.g., __get, __set) are ignored by default, so projects relying heavily on dynamic properties may have undetected dead code, requiring manual workarounds.
Properties accessed only through serialization (e.g., in JSON responses) can be falsely reported as unused, necessitating custom providers to handle these cases, as admitted in the Limitations section.
Dead code detection is automatically disabled during PHPStan's partial analysis, making it unsuitable for incremental development workflows and quick checks on changed files.