PHPStan - PHP Static Analysis Tool¶
PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.
DrevOps comes with pre-configured PHPStan ruleset for Drupal projects.
PHPStan does not fix code. It only reports errors. To fix errors, use Rector. See Rector for more information.
All global configuration takes place in
By default, PHPStan will check with the Drupal context in mind thanks to mglaman/phpstan-drupal.
Targets include custom modules and themes, settings and tests.
Adding or removing targets:
Ignoring rules globally takes place in
- # Comment about why this rules is excluded.
# 'message' is a regular expression with `#` as begin and end delimiters.
message: '#.*no value type specified in iterable type array.#'
PHPStan does not support ignoring of all PHPStan rules within a file.
PHPStan does not support ignoring of a specific rule within a file.
PHPStan does not support ignoring of the code blocks.
To ignore only the current and the next line:
$a = 1;
Ignoring fail in CI¶
This tool runs in CI by default and fails the build if there are any violations.
DREVOPS_CI_PHPSTAN_IGNORE_FAILURE environment variable to
1 to ignore
failures. The tool will still run and report violations, if any.