nunomaduro / larastan
Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel
Fund package maintenance!
canvural
Installs: 37 961 644
Dependents: 2 529
Suggesters: 7
Security: 0
Stars: 5 591
Watchers: 51
Forks: 425
Open Issues: 65
Type:phpstan-extension
Requires
- php: ^8.2
- ext-json: *
- illuminate/console: ^11.15.0
- illuminate/container: ^11.15.0
- illuminate/contracts: ^11.15.0
- illuminate/database: ^11.15.0
- illuminate/http: ^11.15.0
- illuminate/pipeline: ^11.15.0
- illuminate/support: ^11.15.0
- phpmyadmin/sql-parser: ^5.9.0
- phpstan/phpstan: ^2.0.2
Requires (Dev)
- doctrine/coding-standard: ^12.0
- laravel/framework: ^11.15.0
- mockery/mockery: ^1.6
- nikic/php-parser: ^5.3
- orchestra/canvas: ^v9.1.3
- orchestra/testbench-core: ^9.5.2
- phpstan/phpstan-deprecation-rules: ^2.0.0
- phpunit/phpunit: ^10.5.16
Suggests
- orchestra/testbench: Using Larastan for analysing a package needs Testbench
- 3.x-dev
- v3.0.2
- v3.0.1
- v3.0.0
- 2.x-dev
- v2.9.12
- v2.9.11
- v2.9.10
- v2.9.9
- v2.9.8
- v2.9.7
- v2.9.6
- v2.9.5
- v2.9.4
- v2.9.3
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.1
- v2.8.0
- v2.7.0
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.9
- 2.2.8
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- v2.2.0
- v2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- 2.0.0
- 1.x-dev
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- v0.7.15
- v0.7.14
- v0.7.13
- v0.7.12
- v0.7.11
- v0.7.10
- v0.7.9
- v0.7.8
- v0.7.7
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.13
- v0.6.12
- v0.6.11
- v0.6.10
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.21
- v0.3.20
- v0.3.19
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-seb
- dev-parameter-closure-types
- dev-route-name-type
- dev-szepeviktor-patch-1
- dev-unused-translations
This package is auto-updated.
Last update: 2024-11-29 12:19:01 UTC
README
⚗️ About Larastan
Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural and Viktor Szépe, and is a PHPStan extension 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
- Supports most of Laravel's beautiful magic
- Discovers bugs in your code
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".
Supported Laravel versions
✨ Getting Started In 3 Steps
Requires:
1: First, you may use Composer to install Larastan as a development dependency into your Laravel project:
composer require --dev "larastan/larastan:^3.0"
Using Larastan for analysing Laravel packages? You may need to install
orchestra/testbench
.
2: Then, create a phpstan.neon
or phpstan.neon.dist
file in the root of your application. It might look like this:
includes:
- vendor/larastan/larastan/extension.neon
- vendor/nesbot/carbon/extension.neon
parameters:
paths:
- app/
# Level 10 is the highest level
level: 5
# ignoreErrors:
# - '#PHPDoc tag @var#'
#
# excludePaths:
# - ./*/*/FileToBeExcluded.php
For all available options, please take a look at the PHPStan documentation: https://phpstan.org/config-reference
3: Finally, you may start analyzing your code using the phpstan console command:
./vendor/bin/phpstan analyse
If you are getting the error Allowed memory size exhausted
, then you can use the --memory-limit
option fix the problem:
./vendor/bin/phpstan analyse --memory-limit=2G
Ignoring errors
Ignoring a specific error can be done either with a php comment or in the configuration file:
// @phpstan-ignore-next-line $test->badMethod(); $test->badMethod(); // @phpstan-ignore-line
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.
Features
A list of Larastan features 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
👊🏻 Contributing
Thank you for considering contributing to Larastan. All the contribution guidelines are mentioned here.
📖 License
Larastan is an open-sourced software licensed under the MIT license.