Open
Conversation
This commit adds Larastan (PHPStan for Laravel) to the project with level 5 analysis. Larastan is configured to analyze the app, config, database, routes, and tests directories. The analysis is integrated into the CI workflow and will run on all pull requests. This will help catch type errors, undefined properties, and other static analysis issues before they reach production. Currently finds 82 issues to address. This is an experimental integration to evaluate whether Larastan provides value for this project.
Replace env() calls with config() calls in accordance with Laravel best
practices. When config is cached, env() returns null outside of config files.
- FileShareController: Remove redundant environment_vars logging section
- routes/web.php: Use config('app.env') instead of env('APP_ENV')
Fixes 7 Larastan issues (larastan.noEnvCallsOutsideOfConfig)
- MediaTypeName: Remove null from getLabel() return type as it never returns null - MediaResource: Change numeric() thousandsSeparator from false to '' to match expected type - RowHandler: Cast year from int to string and format DateTimeImmutable to string for timestamps - ShowNotePage: Abort with 404 instead of assigning null to non-nullable $note property - Scorecards/Detail: Add object type hint to map callback to resolve undefined property errors - User model: Change PHPDoc from array<int, string> to list<string> for $fillable and $hidden - LogbookQuery: Optimize by calling pluck() directly on query instead of on collection Fixes 12 Larastan issues (type mismatches, unnecessary collection calls, dead code)
- create_notes_table: Change slug from text() to string() as text() doesn't accept length parameter - create_pages_table: Change slug from text() to string() as text() doesn't accept length parameter - MediaEventFactory: Wrap loser callback to match Lottery::loser() signature expecting callable - DatabaseSeeder: Add int $key parameter to each() callback to match expected signature - create_pulse_tables: Add default cases to all match expressions to handle unknown database drivers Fixes 6 Larastan issues (argument count, argument type, unhandled match cases)
…sitives Test Code Fixes: - Remove useless ExampleTest that asserts true === true - Convert model factory tests to use Pest expectations instead of PHPUnit assertions - Remove always-true assertNotNull checks on non-nullable factory results - Add type hints for Eloquent relationships to help PHPStan understand property access - Fix unnecessary collection call (Note::all()->count() -> Note::count()) PHPStan Configuration: - Add ignoreErrors rules for common test patterns that are false positives: * Pest test context methods (artisan, actingAs, etc.) * Eloquent magic properties * Protected method calls in test context * Spatie Feed protected properties * Test response methods This pragmatic approach follows Laravel/Pest best practices while maintaining strict type checking for application code. Fixes remaining test-related Larastan issues
Code Fixes: - RowHandler: Use Carbon::parse() for timestamp properties to satisfy type requirements - DatabaseSeeder: Add type hint for players collection to help PHPStan - Scorecards/Detail: Add PHPDoc for raw SQL query result properties PHPStan Configuration: - Update actingAs pattern to catch all variations - Add ignoreErrors for unavoidable false positives: * VideoGame match arm (PHPStan bug) * Raw SQL object shape not matching Score model type All 82 Larastan issues are now resolved!
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.
This commit adds Larastan (PHPStan for Laravel) to the project with level 5
analysis. Larastan is configured to analyze the app, config, database, routes,
and tests directories.
The analysis is integrated into the CI workflow and will run on all pull
requests. This will help catch type errors, undefined properties, and other
static analysis issues before they reach production.
Currently finds 82 issues to address. This is an experimental integration
to evaluate whether Larastan provides value for this project.