Download the PHP package tomasvotruba/type-coverage without Composer
On this page you can find all versions of the php package tomasvotruba/type-coverage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tomasvotruba/type-coverage
More information about tomasvotruba/type-coverage
Files in tomasvotruba/type-coverage
Package type-coverage
Short Description Measure type coverage of your project
License MIT
Informations about the package type-coverage
Require Minimal Type Coverage
A PHPStan extension, to check and require minimal type coverage of PHP code.
The type coverage rate = total count of defined type declarations / total count of possible type declarations.
E.g. we have 10 methods, but only 7 have defined return type = 70 % return type coverage.
PHPStan uses type declarations to determine the type of variables, properties and other expression. Sometimes it's hard to see what PHPStan errors are the important ones among thousands of others.
Instead of fixing all PHPStan errors at once, we can start with minimal require type coverage.
How to increase type coverage?
Here we have 3 possible type declarations:
- property,
- param
- and return type
The param type is defined as array
.
1 defined / 3 possible = 33.3 % type coverage
Our code quality is only at one-third of its potential. Let's get to 100 %!
This technique is very simple to start even on legacy project. Also, you're now aware exactly how high coverage your project has.
Install
The package is available on PHP 7.2+.
Usage
With PHPStan extension installer, everything is ready to run.
Enable each item on their own:
Measure Strict Declares coverage
Once you've reached 100 % type coverage, make sure your code is strict and uses types:
Again, raise level percent by percent in your own pace:
Full Paths only
If you run PHPStan only on some subpaths that are different from your setup in phpstan.neon
, e.g.:
This package could show false positives, as classes in the src/Controller
could be slightly less typed. This would be spamming whole PHPStan output and make hard to see any other errors you look for.
That's why this package only triggers if there are full paths, e.g.:
`
Happy coding!