Skip to content
Snippets Groups Projects
Dave Long's avatar
Issue #3486713 by ptmkenny, mondrake, spokje: Bump PHPStan to version 2.0.4
Dave Long authored
22098897
History
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Drupal custom PHPStan rules

This directory contains PHPStan rules specifically developed for Drupal.

Subdirectories

  • Rules: contains the actual rules.
  • tests: contains PHPUnit tests for the rules.
  • fixtures: contains fixture files for the PHPUnit tests of the rules.

Enabling rules

Rules are executed when they are added to the the phpstan.neon(.dist) configuration file of a PHPStan scan run. You need to add them under the rules entry in the file, specifying the fully qualified class name of the rule. For example:


rules:
  - Drupal\PHPStan\Rules\ComponentTestDoesNotExtendCoreTest

Testing rules

PHPStan rules must be tested in the context of the PHPStan testing framework, that differs in terms of dependencies from Drupal's one.

Note that for this reason, these tests are run separately from Drupal core tests.

A composer.json file is present in this directory, indicating the required packages for the execution of the tests. Installing via composer

$ composer install

builds a vendor subdirectory that includes all the packages required. Note this packages' codebase is totally independent from Drupal core's one.

In the context of this directory, you can then execute the rule tests like

$ vendor/bin/phpunit tests