PHPStan is a static analysis tool for PHP. It is designed to find errors in your code without actually running it. PHPStan is capable of detecting classes of bugs even before you write tests for the code. This makes PHP development a lot more efficient and moves PHP closer to compiled languages by allowing the correctness of each line of code to be checked before it is run. PHPStan is an invaluable tool for maintaining code quality and bug prevention.
PHPStan is easy to use. To start using PHPStan, you need to require it in your project using Composer via the require
command:
composer require --dev phpstan/phpstan
Once PHPStan is installed, you can analyse your project's code using the analyse
command:
vendor/bin/phpstan analyse src
Here, "src" would be the directory you want to analyse. If you have a directory structure, you can include multiple directories separated by a space.
The comprehensive documentation for PHPStan is conveniently hosted on the phpstan.org website. This includes the 'Getting Started' guide, User Guides, Config Reference, PHPDocs Basics, API Reference, and several more essential resources. All information related to PHPStan, such as developing extensions, a library of extensions, configuration options, and usage best practices can be found in these documentation pages, making it the go-to source for any PHPStan-related queries.