dead-code-detector-laravel maintained by edalzell
Two usage providers for shipmonk/dead-code-detector, covering Laravel conventions its own providers do not: Eloquent trait hooks and #[Scope] attributes.
This is a PHPStan extension, not a Laravel package. There is no service provider and nothing to publish.
For lorisleiva/laravel-actions, see edalzell/dead-code-detector-laravel-actions.
Installation
composer require --dev edalzell/dead-code-detector-laravel
With phpstan/extension-installer the extension registers itself. Without it, add one line:
includes:
- vendor/shipmonk/dead-code-detector/rules.neon
- vendor/edalzell/dead-code-detector-laravel/extension.neon
What each extension does
EloquentTraitHooksUsageProvider — Eloquent invokes a trait's boot{Trait} and initialize{Trait} hooks reflectively. Shipmonk's Eloquent provider knows only Model::boot and Model::booted, so every hook a trait declares reads as dead.
EloquentScopeAttributeUsageProvider — a #[Scope] method is reached through the query builder, never called by name. Shipmonk's Eloquent provider recognises the older scopeName() convention only, so an attribute-declared scope reads as dead however many callers it has.
Testing
composer test
The suite runs PHPStan over tests/Fixtures three times: once with the shipped extension.neon, and once per extension with that one service left out. Each run asserts the exact set of members reported dead, so removing any extension turns a test red with a named fixture rather than quietly changing nothing.
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.