If you are using a Laravel version older than 9.x, please refer to Larastan v1.x.
Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural, Nuno Maduro, and Viktor Szépe, and is a PHPStan wrapper for Laravel. Larastan focuses on finding errors in your code. It catches whole classes of bugs even before you write tests for the code.
Adds static typing to Laravel to improve developer productivity and code quality
While by definition, "static analysis" doesn't load any of your application's code. Larastan boots your application's container, so it can resolve types that are only possible to compute at runtime. That's why we use the term "code analysis" instead of "static analysis".
When ignoring errors in PHPStan's configuration file, they are ignored by writing a regex based on error messages:
parameters:
ignoreErrors:
- '#Call to an undefined method .*badMethod\(\)#'
Baseline file
In older codebases it might be hard to spend the time fixing all the code to pass a high PHPStan Level.
To get around this a baseline file can be generated. The baseline file will create a configuration file with all of the current errors, so new code can be written following a higher standard than the old code. (PHPStan Docs)
./vendor/bin/phpstan analyse --generate-baseline
Rules
A list of configurable rules specific to Laravel can be found here.
Custom PHPDoc types
A list of PHPDoc types specific to Larastan can be found here.
Custom PHPStan config parameters
A list of custom config parameters that you can use in your PHPStan config file can be found here.
Errors To Ignore
Some parts of Laravel are currently too magical for Larastan/PHPStan to understand.
We listed common errors to ignore, add them as needed
请发表评论