Skip to content

phpstan-drupal

This page lists every rule and extension registered by phpstan-drupal 2.5.0, 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

ExtensionListDependencyRule

It doesn't report anything. It makes PHPStan's result cache depend on the list of Drupal extensions. Mago doesn't keep a result cache, see ConfigSchemaResultCacheValueExtension.

FieldTypeCategoryRule

FormApiCallbackAssignRule

Off by default in phpstan-drupal. It runs the checks of FormApiCallbackRule on a callback that is assigned or appended to a form key, as in $form['#submit'][] = '::save'. The checks listed there read those callbacks too.

FormApiCallbackRule

  • formApiCallback.nonPublicMethod: drupal/non-public-callback
  • formApiCallback.nonStaticMethod: drupal/non-static-callback, partly. A 'Class::method' string that names an instance method isn't reported on any Drupal version. phpstan-drupal reports it before Drupal 11.3, where PHP calls the method statically.
  • formApiCallback.notFound: drupal/unknown-callback, drupal/invalid-callback, partly. A function that doesn't exist is reported only when its name starts with the name of the module that the file is in, see drupal/unknown-callback.
  • formApiCallback.notInstantiable: drupal/invalid-callback
  • formApiCallback.privateService: nothing. A callback that names a private service, which the container doesn't hand out. An id that is also a class name is read as that class.
  • formApiCallback.serviceNotation: nothing. A 'service:method' callback on Drupal before 11.3, where the form API doesn't pass callbacks to the callable resolver. The checks of this notation, and of a class name or a service id alone, don't run there.

Off by default in phpstan-drupal.

GetDeprecatedServiceRule

GlobalDrupalDependencyInjectionRule

HookEntityOperationCacheabilityRule

HookFormAlterRule

LazyBuilderRule

  • lazyBuilder.argumentCount: drupal/lazy-builder, partly. A callback written as [$object, 'method'] isn't checked, for this identifier and the next one.
  • lazyBuilder.argumentType: drupal/lazy-builder, partly. Reported for NULL and for a string that isn't a number. phpstan-drupal compares every scalar argument with the parameter's type.
  • lazyBuilder.invalidStructure: drupal/lazy-builder
  • lazyBuilder.nonArrayReturn: drupal/lazy-builder
  • lazyBuilder.nonScalarArgument: drupal/lazy-builder, partly. An object or an array as an argument is reported. A closure, and arguments passed as a variable whose type lists its items, aren't.
  • lazyBuilder.placeholderWithoutCallback: drupal/lazy-builder
  • lazyBuilder.unsupportedProperty: drupal/lazy-builder

Off by default in phpstan-drupal.

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.

PhpDocSeeReferenceRule

Off by default in phpstan-drupal.

PluginAnnotationContextDefinitionsRule

PluginManagerAttributeDiscoveryDefaultRule

  • pluginManager.attributeDiscoveryMissingDefault: nothing

A static property or a constructor parameter that a plugin manager passes on as the attribute class, and whose default value names a class that isn't an attribute. drupal/plugin-manager-attribute-discovery reads the argument by its type, so it reports a class constant, a string and a variable that holds one, and not a default value.

PluginManagerAttributeDiscoveryRule

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

RenderCallbackTrustedCallbacksRule

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.

  • AccessCheckTypeSpecifyingExtension: Entities: Entity queries
  • ConfigGetDynamicReturnTypeExtension: Config: Config objects. Off by default in phpstan-drupal.
  • ConfigSchemaResultCacheValueExtension: nothing. They invalidate PHPStan's result cache: for one analyzed file when a service, a container parameter or a config schema that it reads changes, and for every file when the list of Drupal extensions changes. A one-shot run doesn't need anything in their place: Mago doesn't keep a result cache, and the analyzer keys its own index cache by the modification times and sizes of its files, see Index cache. A watch session re-analyzes only the PHP files that change, so an edit to one of those files shows on the PHP files that depend on it once they change or the session restarts.
  • ContainerDynamicReturnTypeExtension: Services: Container lookups
  • ContainerParameterResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, see ConfigSchemaResultCacheValueExtension.
  • DeprecationHelperScope: Deprecations: Deprecation scopes
  • DrupalClassResolverDynamicReturnTypeExtension: Services: Container lookups
  • DrupalClassResolverDynamicStaticReturnTypeExtension: Services: Container lookups
  • DrupalServiceDynamicReturnTypeExtension: Services: Container lookups
  • DrupalStaticEntityQueryDynamicReturnTypeExtension: Entities: Entity queries
  • DrupalStubFilesExtension: Core types and stubs: Stub files, partly. Not every stub is translated, see Not ported from phpstan-drupal.
  • EntityAccessControlHandlerReturnTypeExtension: Entities: Access checks
  • EntityFieldMethodsViaMagicReflectionExtension: Entities: Magic entity fields
  • EntityFieldsViaMagicReflectionExtension: Entities: Magic entity fields
  • EntityIdNarrowedByNew: nothing. id() isn't null once isNew() is false. A stub can't say it: Mago and PHPStan read a docblock assertion both ways, so @psalm-assert-if-false on isNew() would also make id() null when isNew() is true. A check on id() itself narrows the later calls, see Stub files and Not ported from phpstan-drupal.
  • EntityQueryAccessCheckDynamicReturnTypeExtension: Entities: Entity queries
  • EntityQueryDynamicReturnTypeExtension: Entities: Entity queries
  • EntityRepositoryReturnTypeExtension: Entities: Handlers and storage
  • EntityStorageDynamicReturnTypeExtension: Entities: Handlers and storage
  • EntityTypeIdTypeNodeResolverExtension: nothing. The entity-type-id docblock type. Mago reports it as an unknown class, so write string instead. phpstan-drupal 2.5.0 accepts any string for it, so string doesn't lose any check.
  • EntityTypeKeyByExistence: Entities: Entity type keys, partly. getKey() is a string for the keys that every entity type has. A hasKey() check for the same key doesn't narrow it, but the reports about a possible false from a getKey() call that such a check guards in an if or an && chain are dropped.
  • EntityTypeLinkTemplateByExistence: Entities: Entity type keys, partly. A hasLinkTemplate() check for the same template doesn't narrow getLinkTemplate(), but the reports about a possible false from a getLinkTemplate() call that such a check guards in an if or an && chain are dropped. A false check doesn't narrow the call to false.
  • EntityTypeManagerGetStorageDynamicReturnTypeExtension: Entities: Handlers and storage
  • ExtensionListResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, see ConfigSchemaResultCacheValueExtension.
  • GetQueryReturnTypeExtension: Entities: Entity queries
  • GroupLegacyScope: Deprecations: Deprecation scopes
  • IgnoreDeprecationsScope: Deprecations: Deprecation scopes
  • InspectorTypeExtension: Core types and stubs: Inspector assertions
  • ServiceResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, see ConfigSchemaResultCacheValueExtension.