PHPStan Reached Version 1.0 After 6 Years of Development

PHPStan gained a milestone release 1.0 with new features, added rules, and a lot of performance optimizations.

Introducing static code analysis into your process should improve the quality of your code and make the QA process more efficient due to finding errors earlier on.

PHPStan is an open source tool with 10.4K GitHub stars and 737 GitHub forks. It is probably the most popular static analysis system for PHP projects, which finds bugs in your codebase by inspecting the source files. In other words, you donโ€™t need to run your code or manually write tests to discover issues.

Related: How to Configure Nginx to Work with PHP via PHP-FPM

PHPStan will read the PHP code from the passed files. If it encounters unknown classes, then it will try to autoload them and understand their interface by reflection. On top of that you can also configure a path to the Bootstrap file via which you can configure autoload, as well as include() some additional files in order to simplify the PHPStan analysis.

PHPStan

Furthermore, PHPStan doesnโ€™t only perform autoload in the case of unknown classes, but it also does so for all classes. 

PHPStan 1.0 was released earlier this month as the first stable release for this leading open-source PHP static analysis tool. Let’s take a brief look at what’s new.

PHPStan 1.0 Highlights

The flagship feature of PHPStan 1.0 is a brand-new level 9. It includes all the rules from level 8 and lower, as well as one extra check: strict mixed type comparisons.

If youโ€™re not familiar, the fundamental way of how PHPStan handles and accommodates analysis of codebases of varying quality is the concept of rule levels.

If you want to use PHPStan but your codebase isnโ€™t up to speed with strong typing and PHPStanโ€™s strict checks, you can currently choose from 10 levels, where 0 is the loosest and 9 is the strictest.

Moreover PHPStan 1.0 now remembers when you call a function for a second time and the function is supposed to return the same value. On top of that you can also allows extending PHPStanโ€™s comprehension of your code where you might declare seemingly unused properties and constants for good reasons.

Last but not least, the new version brings a lot of stability improvements and performance optimizations.

You can Learn more about the PHPStan 1.0 PHP static analyzer release on the project’s website

Installation and Usage

To run PHPStan 1.0, youโ€™ll need to have PHP 7.1 or newer. This requirement only applies to the version of PHP used to execute PHPStan itself. The tool is capable of analyzing source files targeting older versions of PHP.

To start performing analysis on your code, require PHPStan in Composer, which is dependency manager for PHP.

composer require --dev phpstan/phpstanCode language: JavaScript (javascript)

Composer will install PHPStanโ€™s executable in its bin-dir which defaults to vendor/bin.

The PHPStan binary will be added to your project at vendor/bin/phpstan. You can now use it to analyze your codebase:

vendor/bin/phpstan analyse filename.php
Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 69%