Skip to content

phpstan-drupal

This page lists every rule and extension registered by phpstan-drupal 2.2.2, and what takes its place in a Mago setup with this extension. To find a check, search for the identifier printed by PHPStan with an error, or named in a baseline or an @phpstan-ignore comment.

Each identifier and extension is followed by what handles it:

  • an analyzer check of this extension, such as drupal/config-unknown-key. Its entry under Analyzer says where it differs from phpstan-drupal;
  • a linter rule of this extension, such as drupal/discouraged-function, for a check that needs no types. Its entry is under Linter rules;
  • mago analyze with one of Mago's own issues;
  • a section of the analyzer docs, for an extension that types Drupal's APIs;
  • nothing, when no tool checks it yet. The note says why.

The analyzer checks run by default, including the ones whose phpstan-drupal rule is off by default. To turn one off, use [analyzer] ignore, as Turning rules off shows. A @phpstan-ignore comment with one of phpstan-drupal's identifiers doesn't drop the matching Mago issue, see PHPStan ignores.

Rules

AccessResultConditionRule

  • identical.alwaysFalse: mago analyze (redundant-comparison)
  • notIdentical.alwaysFalse: mago analyze (redundant-comparison)

Mago reports a strict comparison that is always true or always false anywhere, not only as the condition of AccessResult::allowedIf() or forbiddenIf().

BrowserTestBaseDefaultThemeRule

CacheableDependencyRule

ClassExtendsInternalClassRule

ConfigEntityConfigExportRule

ConfigGetUnknownKeyRule

Off by default in phpstan-drupal.

DependencySerializationTraitPropertyRule

DeprecatedHookImplementation

phpstan-drupal runs it only when a project adds it to rules.

DiscouragedFunctionsRule

EntityListBuilderOperationsCacheabilityRule

EntityQueryHasAccessCheckRule

EntityStorageDirectInjectionRule

EntityStoragePropertyAssignmentRule

GetDeprecatedServiceRule

GlobalDrupalDependencyInjectionRule

HookEntityOperationCacheabilityRule

HookFormAlterRule

LoadIncludes

LoggerFromFactoryPropertyAssignmentRule

ModuleLoadInclude

  • moduleLoadInclude.moduleNotFound: nothing
  • moduleLoadInclude.moduleNotLoadable: nothing

Drupal 11 removed module_load_include(), and Mago reports a call to it as non-existent-function.

PluginAnnotationContextDefinitionsRule

PluginManagerInspectionRule

  • pluginManagerInspection.alterInfoMissing: drupal/plugin-manager-alter-info
  • pluginManagerInspection.yamlPluginManagersInvokesParentConstructor: nothing. A plugin manager with YAML discovery that calls parent::__construct(). The call is harmless, since the parent constructor only stores its arguments.

Off by default in phpstan-drupal.

PluginManagerSetsCacheBackendRule

ProceduralHookEntityOperationCacheabilityRule

RenderCallbackRule

StaticServiceDeprecatedServiceRule

SymfonyYamlParseRule

TestClassesProtectedPropertyModulesRule

TestClassSuffixNameRule

TodoCommentWithIssueUrlRule

phpstan-drupal runs it only when a project adds it to rules.

Extensions

phpstan-drupal's extensions type what Drupal's APIs return, read entity fields as properties, replace core's docblocks with stub files and decide where a deprecated call is allowed. The analyzer plugin does the same work, and the linked section says how.