Closed
Conversation
Adds a new MemberUsageProvider for Laravel that suppresses false
positives from dead code detection for framework-specific patterns.
Detects as used:
- Controller methods registered via Route::get/post/etc(), supporting
both [Controller::class, 'method'] array and 'Controller@method'
string syntax
- handle() in Artisan command classes (Illuminate\Console\Command)
- register() and boot() in service provider classes
(Illuminate\Support\ServiceProvider)
- get*Attribute() and set*Attribute() accessor/mutator methods in
Eloquent model classes (Illuminate\Database\Eloquent\Model)
The provider is auto-enabled when laravel/framework is detected in the
project's installed packages. It can be forced on/off via:
parameters:
shipmonkDeadCode:
usageProviders:
laravel:
enabled: true
…atives str_contains(), str_starts_with(), str_ends_with() require PHP 8.0. Replace with strpos()/substr() to maintain PHP 7.4 compatibility. Also fixes PHPStan 'Offset 1 might not exist on non-empty-list<string>' by replacing explode() destructuring with explicit strpos()/substr().
- Move constants before properties (ClassStructure) - Split multi-parameter method signatures to multiple lines - Sort use statements alphabetically - Remove duplicate spaces in comments
Member
|
Hello, I tried bigger-scope in #294, it should cover all your cases. Can you try it out? Thank you!
|
Author
|
For the next few days I'll be traveling. In about a week I'll be able to test the Eloquent and Laravel rules on a real project and provide feedback. Should I close my PR for now? |
Member
|
I think we can close this one, thanks anyway! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for this package.
I started using dead-code-detector in my Laravel projects and immediately ran into a wall of false positives. Laravel relies heavily on convention-based invocation: the framework calls controller methods, Artisan command handlers, service provider lifecycle hooks, and Eloquent accessors/mutators through its own runtime machinery — none of which is visible to PHPStan as a static call.
What this covers
Pattern Mechanism Example
Route-registered controller methods AST: StaticCall on Route::get/post/... Route::get('/home', [HomeController::class, 'index']) and 'HomeController@index' string syntax
Artisan command handle() ClassMethod + reflection Classes extending Illuminate\Console\Command
Service provider lifecycle ClassMethod + reflection register() / boot() in classes extending Illuminate\Support\ServiceProvider
Eloquent accessors & mutators ClassMethod + reflection getAttribute() / setAttribute() in classes extending Illuminate\Database\Eloquent\Model
The provid
TODO / known limitations
The following patterns are not yet handled and are candidates for follow-up PRs:
Form Request validation — rules() and authorize() methods in classes extending Illuminate\Foundation\Http\FormRequest
Event Listeners — handle() in classes implementing Illuminate\Contracts\Events\ShouldHandleEventsAfterCommit or registered via Event::listen()
I am open to feedback on the approach and happy to extend the coverage before merging if the maintainers prefer.