mediact / testing-suite

Collection of PHP code testing packages.
MIT License
14 stars 4 forks source link

Set PHPStan level to max #20

Open janmartenjongerius opened 5 years ago

janmartenjongerius commented 5 years ago

The PHPStan level is currently set to 4:

    phpstan:
      autoload_file: ~
      configuration: ./phpstan.neon
      level: 4

At the time of implementing it, this was known as the highest level available.

As PHPStan is still growing and expanding, so are the levels it supports. Currently, there are 8 levels available.

To both have the most in-depth analysis and keep up with new developments, the level can be set to max. The following is an excerpt of the current documentation of PHPStan:

If you want to use PHPStan but your codebase isn't up to speed with strong typing and PHPStan's strict checks, you can choose from currently 8 levels (0 is the loosest and 7 is the strictest) by passing --level to analyse command. Default level is 0.

This feature enables incremental adoption of PHPStan checks. You can start using PHPStan with a lower rule level and increase it when you feel like it.

You can also use --level max as an alias for the highest level. This will ensure that you will always use the highest level when upgrading to new versions of PHPStan. Please note that this can create a significant obstacle when upgrading to a newer version because you might have to fix a lot of code to bring the number of errors down to zero.

When introducing PHPStan in our testing suite and CI environments, we immediately went to the highest level available and, to the best of my knowledge, this was very well accepted by end-users. Setting it to max reduces maintenance and increases code quality for those who use it.

    phpstan:
      autoload_file: ~
      configuration: ./phpstan.neon
      level: max

I have not looked into if the GrumPHP task for PHPStan would prevent using a non-numeric value for the level. If that is the case, we can choose to patch it or first to only upgrade to a few levels higher.

ksangers commented 5 years ago

An initial test shows that GrumPHP doesn't support the max level, the 7 level works. Due to the nature of our projects it's likely we will be some versions behind the latest version of PHPStan, my initial test showed 0.8.5 which contains this level.

Feel free to make a pull request for this.