Get error count for each PHPStan level!
First, we look into the project root for phpstan.neon file.
/src, /app, /tests, etc.Then we run PHPStan for each level from 0 to 8. We count errors and display them in a table.
composer require tomasvotruba/phpstan-bodyscan --devRun tool in your project. It will take some time, as it will run full PHPStan analysis for each level.
vendor/bin/phpstan-bodyscan↓
To get errors count per level:
+-------+-------------+-----------+
| Level | Error count | Increment |
+-------+-------------+-----------+
| 0 | 0 | - |
| 1 | 35 | + 35 |
| 2 | 59 | + 24 |
| 3 | 59 | - |
| 4 | 120 | + 61 |
| 5 | 120 | - |
| 6 | 253 | + 133 |
| 7 | 350 | + 97 |
| 8 | 359 | + 9 |
+-------+-------------+-----------;vendor/bin/phpstan-bodyscan --no-ignorevendor/bin/phpstan-bodyscan --bareWe got you covered:
vendor/bin/phpstan-bodyscan --json↓
[
{
"level": 0,
"error_count": 0,
"increment_count": 0
},
{
"level": 1,
"error_count": 5,
"increment_count": 5
},
{
"level": 2,
"error_count": 25,
"increment_count": 20
}
]Are you interested only in a few levels? You can limit ranges by the options:
vendor/bin/phpstan-bodyscan run --min-level 0 --max-level 3Experimental!
Are you interested in learning param, return and property type declaration coverage of the project?
Run type-coverage command ↓
vendor/bin/phpstan-bodyscan type-coverage --json↓
[
{
"category": "param type",
"relative_covered": 100,
"total_count": 54
},
{
"category": "property type",
"relative_covered": 100,
"total_count": 1
},
{
"category": "return type",
"relative_covered": 100,
"total_count": 33
},
{
"category": "strict declares",
"relative_covered": 100,
"total_count": 18
}
]Based on type-coverage package.
Some projects need to load .env file to run PHPStan. You can do it like this:
vendor/bin/phpstan-bodyscan run --env-file some-parameters.envRunning PHPStan on a new project you don't know might crash. To save data from finished levels, we dump them to the bodyscan-log.txt file.
If the run crashes for any reason, the PHPStan error output is also dumped to the same file.
Happy coding!