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 analyzewith 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¶
BrowserTestBase.defaultThemeRequired:drupal/browser-test-default-theme
CacheableDependencyRule¶
cacheable.dependency:drupal/cacheable-dependency
ClassExtendsInternalClassRule¶
classExtendsInternalClass.classExtendsInternalClass:drupal/internal-class-extension
ConfigEntityConfigExportRule¶
configEntityConfigExport.noConfigExportKey:drupal/config-entity-export
ConfigGetUnknownKeyRule¶
drupal.configGetUnknownKey:drupal/config-unknown-key
Off by default in phpstan-drupal.
DependencySerializationTraitPropertyRule¶
dependencySerializationTraitProperty.unsupportedPrivateProperty:drupal/dependency-serialization-propertydependencySerializationTraitProperty.unsupportedReadOnlyProperty:drupal/dependency-serialization-property
DeprecatedHookImplementation¶
deprecatedHookImplementation.other:drupal/deprecated-hookdeprecatedHookImplementation.useHookFieldWidgetCompleteFormAlter:drupal/deprecated-hookdeprecatedHookImplementation.useHookFieldWidgetMulitValueWidgetTypeFormAlter:drupal/deprecated-hook
phpstan-drupal runs it only when a project adds it to rules.
DiscouragedFunctionsRule¶
discouragedFunctions.discouragedFunctionCalled:drupal/discouraged-function
EntityListBuilderOperationsCacheabilityRule¶
drupal.entityListBuilderMissingCacheabilityParameter:drupal/list-builder-cacheability
EntityQueryHasAccessCheckRule¶
entityQueryHasAccessCheck.noAccessCheck:drupal/entity-query-access-check
EntityStorageDirectInjectionRule¶
drupal.entityStorageDirectInjection:drupal/entity-storage-injection
EntityStoragePropertyAssignmentRule¶
drupal.entityStoragePropertyAssignment:drupal/entity-storage-property
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¶
fieldTypeCategory.translatable:drupal/field-type-category
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-callbackformApiCallback.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, seedrupal/unknown-callback.formApiCallback.notInstantiable:drupal/invalid-callbackformApiCallback.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¶
getDeprecatedService.deprecated:drupal/deprecated-service
GlobalDrupalDependencyInjectionRule¶
globalDrupalDependencyInjection.useDependencyInjection:drupal/global-drupal-call, partly
HookEntityOperationCacheabilityRule¶
drupal.hookEntityOperationAlterMissingCacheabilityParameter:drupal/hook-entity-operation-cacheabilitydrupal.hookEntityOperationMissingCacheabilityParameter:drupal/hook-entity-operation-cacheability
HookFormAlterRule¶
hookFormAlter.formParameterNotByRef:drupal/hook-form-alter-signaturehookFormAlter.invalidFormIdParameterType:drupal/hook-form-alter-signaturehookFormAlter.invalidFormParameterType:drupal/hook-form-alter-signaturehookFormAlter.invalidFormStateParameterType:drupal/hook-form-alter-signaturehookFormAlter.invalidParameterCount:drupal/hook-form-alter-signature
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 forNULLand for a string that isn't a number. phpstan-drupal compares every scalar argument with the parameter's type.lazyBuilder.invalidStructure:drupal/lazy-builderlazyBuilder.nonArrayReturn:drupal/lazy-builderlazyBuilder.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-builderlazyBuilder.unsupportedProperty:drupal/lazy-builder
Off by default in phpstan-drupal.
LoadIncludes¶
loadIncludes.fileNotLoadable:drupal/load-includeloadIncludes.moduleNotFound:drupal/load-include
LoggerFromFactoryPropertyAssignmentRule¶
loggerFromFactory.propertyAssignment:drupal/logger-from-factory
ModuleLoadInclude¶
moduleLoadInclude.moduleNotFound: nothingmoduleLoadInclude.moduleNotLoadable: nothing
Drupal 11 removed module_load_include(), and Mago reports a call to it as non-existent-function.
PhpDocSeeReferenceRule¶
phpDocSee.classNotFound:drupal/see-reference, partly. Reported for a class of core, of an installed module or of a package, when the name isn't a namespace on disk.phpDocSee.functionNotFound:drupal/see-reference, partly. Reported for a function named after an installed module or afterdrupal.phpDocSee.memberNotFound:drupal/see-referencephpDocSee.methodNotFound:drupal/see-referencephpDocSee.methodWithoutClass:drupal/see-reference
Off by default in phpstan-drupal.
PluginAnnotationContextDefinitionsRule¶
pluginAnnotationContextDefinitions.useContextDefinitionsKey:drupal/plugin-annotation-context
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¶
pluginManager.attributeDiscoveryMissing:drupal/plugin-manager-attribute-discovery
PluginManagerInspectionRule¶
pluginManagerInspection.alterInfoMissing:drupal/plugin-manager-alter-infopluginManagerInspection.yamlPluginManagersInvokesParentConstructor: nothing. A plugin manager with YAML discovery that callsparent::__construct(). The call is harmless, since the parent constructor only stores its arguments.
Off by default in phpstan-drupal.
PluginManagerSetsCacheBackendRule¶
pluginManagerSetsCacheBackend.missingCacheBackend:drupal/plugin-manager-cache-backend
ProceduralHookEntityOperationCacheabilityRule¶
drupal.proceduralHookEntityOperationAlterMissingCacheabilityParameter:drupal/hook-entity-operation-cacheabilitydrupal.proceduralHookEntityOperationMissingCacheabilityParameter:drupal/hook-entity-operation-cacheability
RenderCallbackRule¶
renderCallback.callbackNotImplementsTrustedCallback:drupal/untrusted-callbackrenderCallback.callbackNotImplementsTrustedCallbackInterface:drupal/untrusted-callbackrenderCallback.containsClosure:drupal/form-closure-callbackrenderCallback.expectsArrayOfCallbacks:drupal/render-callbackrenderCallback.expectsCallableArrayWithArguments:drupal/render-callbackrenderCallback.invalidKeyValue:drupal/invalid-callback, partlyrenderCallback.nonCallableCallback:drupal/unknown-callback,drupal/invalid-callbackrenderCallback.nonTrustedCallback:drupal/render-callback
RenderCallbackTrustedCallbacksRule¶
renderCallback.methodNotInTrustedCallbacks:drupal/untrusted-callback
StaticServiceDeprecatedServiceRule¶
staticServiceDeprecatedService.deprecated:drupal/deprecated-service
SymfonyYamlParseRule¶
drupal.symfonyYamlParse:drupal/symfony-yaml-parse
TestClassesProtectedPropertyModulesRule¶
testClass.propertyModulesNonProtected:drupal/test-modules-visibility
TestClassSuffixNameRule¶
nonAbstractTestClass.NameNoSuffixTest:drupal/test-class-suffix,drupal/test-class-name
TodoCommentWithIssueUrlRule¶
drupal.todoCurrentIssue:drupal/todo-current-issue
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 queriesConfigGetDynamicReturnTypeExtension: 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 lookupsContainerParameterResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, seeConfigSchemaResultCacheValueExtension.DeprecationHelperScope: Deprecations: Deprecation scopesDrupalClassResolverDynamicReturnTypeExtension: Services: Container lookupsDrupalClassResolverDynamicStaticReturnTypeExtension: Services: Container lookupsDrupalServiceDynamicReturnTypeExtension: Services: Container lookupsDrupalStaticEntityQueryDynamicReturnTypeExtension: Entities: Entity queriesDrupalStubFilesExtension: Core types and stubs: Stub files, partly. Not every stub is translated, see Not ported from phpstan-drupal.EntityAccessControlHandlerReturnTypeExtension: Entities: Access checksEntityFieldMethodsViaMagicReflectionExtension: Entities: Magic entity fieldsEntityFieldsViaMagicReflectionExtension: Entities: Magic entity fieldsEntityIdNarrowedByNew: nothing.id()isn't null onceisNew()is false. A stub can't say it: Mago and PHPStan read a docblock assertion both ways, so@psalm-assert-if-falseonisNew()would also makeid()null whenisNew()is true. A check onid()itself narrows the later calls, see Stub files and Not ported from phpstan-drupal.EntityQueryAccessCheckDynamicReturnTypeExtension: Entities: Entity queriesEntityQueryDynamicReturnTypeExtension: Entities: Entity queriesEntityRepositoryReturnTypeExtension: Entities: Handlers and storageEntityStorageDynamicReturnTypeExtension: Entities: Handlers and storageEntityTypeIdTypeNodeResolverExtension: nothing. Theentity-type-iddocblock type. Mago reports it as an unknown class, so writestringinstead. phpstan-drupal 2.5.0 accepts any string for it, sostringdoesn't lose any check.EntityTypeKeyByExistence: Entities: Entity type keys, partly.getKey()is a string for the keys that every entity type has. AhasKey()check for the same key doesn't narrow it, but the reports about a possiblefalsefrom agetKey()call that such a check guards in anifor an&&chain are dropped.EntityTypeLinkTemplateByExistence: Entities: Entity type keys, partly. AhasLinkTemplate()check for the same template doesn't narrowgetLinkTemplate(), but the reports about a possiblefalsefrom agetLinkTemplate()call that such a check guards in anifor an&&chain are dropped. A false check doesn't narrow the call tofalse.EntityTypeManagerGetStorageDynamicReturnTypeExtension: Entities: Handlers and storageExtensionListResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, seeConfigSchemaResultCacheValueExtension.GetQueryReturnTypeExtension: Entities: Entity queriesGroupLegacyScope: Deprecations: Deprecation scopesIgnoreDeprecationsScope: Deprecations: Deprecation scopesInspectorTypeExtension: Core types and stubs: Inspector assertionsServiceResultCacheValueExtension: nothing. It invalidates PHPStan's result cache, seeConfigSchemaResultCacheValueExtension.