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 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
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
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.
PluginAnnotationContextDefinitionsRule¶
pluginAnnotationContextDefinitions.useContextDefinitionsKey:drupal/plugin-annotation-context
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
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 queriesBootstrapResultCacheMetaExtension: nothing. It invalidates PHPStan's result cache when an extension's info file, a services file, a config schema file or the Drupal version changes. A one-shot run doesn't need anything in its 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.ConfigGetDynamicReturnTypeExtension: Config: Config objects. Off by default in phpstan-drupal.ContainerDynamicReturnTypeExtension: Services: Container lookupsDeprecationHelperScope: 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.2.2 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 storageGetQueryReturnTypeExtension: Entities: Entity queriesGroupLegacyScope: Deprecations: Deprecation scopesIgnoreDeprecationsScope: Deprecations: Deprecation scopesInspectorTypeExtension: Core types and stubs: Inspector assertions