Skip to content

2.4.0

Latest

Choose a tag to compare

@mglaman mglaman released this 09 Nov 21:10
· 10 commits to main since this release
174a0d7

Upgrading

This release reports new errors by default. Expect them in modules with annotation-only plugin managers, and in code that calls \Drupal::entityQueryAggregate() without accessCheck().

Drupal 12: plugin managers without attribute discovery

Drupal 12 throws an exception for plugin managers that only support annotation discovery. Drupal 11.2 deprecated them with @trigger_error(), so no @deprecated tag reported them until now. phpstan-drupal reports a DefaultPluginManager subclass that passes an annotation class as the fifth argument to parent::__construct():

parent::__construct(
  'Plugin/Example',
  $namespaces,
  $module_handler,
  ExampleInterface::class,
  Example::class, // An annotation class: reported.
);

To fix it, pass the attribute class as the fifth argument and keep the annotation class as the sixth. This works on Drupal 10.2 and later.

Identifier Reported when
pluginManager.attributeDiscoveryMissing The argument is a ::class constant, a string, or a local variable holding one
pluginManager.attributeDiscoveryMissingDefault The argument comes from a static property or a constructor parameter default

Managers that pick the class at runtime, like class_exists(Attr::class) ? Attr::class : Annotation::class, are reported too, even though they work on Drupal 12. Ignore them by identifier. The README has an example.

Deprecation rules turn off with phpstan-deprecation-rules

phpstan-drupal's own deprecation rules now run only when phpstan/phpstan-deprecation-rules is loaded. That covers the plugin manager rules above, and the rules for deprecated services and the context plugin annotation key. They're still on by default, because phpstan-drupal requires phpstan-deprecation-rules.

If you turn off deprecation checks with the extension-installer ignore setting, these rules now turn off too. They have no drupal.rules.* parameters. To ignore one, use its identifier.

Aggregate entity queries

execute() on an aggregate query now returns list<array<string, string|null>>, one array per result row. It returned the entity ID type, array<int, string>, so code like array_column($rows, 'type') was reported as always empty.

\Drupal::entityQueryAggregate() gets the same type, and a missing accessCheck() on it is now reported, like on \Drupal::entityQuery().

Bleeding edge

bleedingEdge.neon now enables configGetUnknownKeyRule, which reports Config::get() calls with a key that isn't in the config schema.

What's Changed

  • Register deprecation rules only when phpstan-deprecation-rules is loaded by @mglaman in #1081
  • Add rules to detect plugin managers without attribute discovery by @bbrala in #1068
  • Move agent instructions from CLAUDE.md to AGENTS.md by @mglaman in #1083
  • Add RuleConventionsTest to enforce rule registration conventions by @mglaman in #992
  • Fix aggregate entity query return type. by @travis-bradbury in #1063

Full Changelog: 2.3.0...2.4.0