Problem/Motivation

The Drupal 12 change record on PHPUnit attributes recommends module developers to enable two of Core's PHPStan rules to detect obsolete PHPUnit annotations.

These rules, however, live under core/tests/PHPStan/, which Drupal 12 release packages omit. Even when Core is installed from source, Composer projects do not inherit the Core repository's autoload-dev mapping. Adding the rules to a module's phpstan.neon therefore assumes its autoloader can already find them.

The types and rules proposed in #3642960: [PP-1] Introduce reusable PHPStan types, including string patterns with typed placeholders face the same limitation.

Proposed resolution

  • Ship the reusable PHPStan extensions with drupal/core,
  • register their namespace in the package's autoload section, and
  • expose their shared configuration through extra.phpstan.includes.

Projects using the PHPStan extension installer can then load it automatically.

The default configuration should work for projects that run PHPStan without PHPUnit. Keep Core-specific checks in Core's own configuration.

Remaining tasks

Decide which rules, types, and formatters to ship and where to place them so their tests and fixtures remain excluded from release packages.

Decide which rules to enable by default and document how projects can enable the others.

Verify automatic loading in a contrib project with both source and dist installations of Core. Include a project that already registers a Core rule manually.

User interface changes

None.

Introduced terminology

None.

API changes

drupal/core exposes its shared PHPStan configuration through extra.phpstan.includes.

Data model changes

None.

Release notes snippet

Contrib projects using the PHPStan extension installer can now load Drupal Core's shared PHPStan extensions without a Core source checkout or manual configuration.

Comments

pancho created an issue.