Problem/Motivation
We have bumped the PHPStan level to level 3. This is great and avoids new L3 errors (and lower) to be introduced in the baseline.
Preferably we update our PHPStan level even more, but we do want to avoid dragging a huge baseline of old errors. Hence it is good to try to do a cleanup of the current baseline first. A lot of issues in the baseline are simple to fix, and do not require BC-breaks. Some need type hinting to be added, those are more difficult. We probably do not need an empty baseline before upping the PHPStan level, but a greatly reduced one is needed.
Proposed resolution
Go through the statistics of the baseline, and see per error type in PHPStan what can be removed in a BC-safe way. Removing issues that would require BC-breaks need to be tackled in a slower pace.
Check if we need to adjust some phpstan settings. #3641549: PHPStan: Set treatPhpDocTypesAsCertain: false
Go over each error identifier (from least to most), and resolve all issues of that identifier in a child issue. For some we will need to split this, for the lower ones we can do them all accross core in one issue, especially the ones only touching phpdocs.
| Error Identifier | Count (approx.) | Issue Link |
|---|---|---|
| missingType.return | 4958 | |
| method.notFound | 3629 | |
| property.notFound | 1392 | |
| assign.propertyType | 654 | |
| argument.type | 627 | |
| return.type | 418 | |
| property.nonObject | 321 | |
| method.nonObject | 274 | |
| return.missing | 203 | |
| drupal.entityStoragePropertyAssignment | 175 | |
| class.notFound | 146 | #3641794: Fix PHPStan L3 error: class.notFound |
| arguments.count | 106 | |
| variable.undefined | 96 | |
| property.defaultValue | 82 | |
| parameter.phpDocType | 77 | |
| property.phpDocType | 76 | |
| offsetAccess.notFound | 66 | |
| drupal.entityStorageDirectInjection | 61 | |
| varTag.nativeType | 48 | |
| method.deprecated | 47 | |
| isset.variable | 41 | |
| return.phpDocType | 41 | #3641449: Fix PHPStan L3 error: return.phpDocType |
| staticClassAccess.privateMethod | 40 | #3642127: Fix PHPStan L3 error: staticClassAccess.privateMethod |
| empty.variable | 39 | |
| return.empty | 36 | |
| varTag.differentVariable | 31 | #3640904: Fix PHPStan L3 error: varTag.differentVariable |
| offsetAssign.valueType | 30 | |
| varTag.variableNotFound | 29 | |
| generics.notSubtype | 29 | |
| unset.possiblyHookedProperty | 28 | |
| offsetAccess.nonOffsetAccessible | 23 | |
| foreach.nonIterable | 19 | |
| parameterByRef.type | 16 | |
| binaryOp.invalid | 14 | |
| constructor.unusedParameter | 14 | |
| disallowed.function | 13 | |
| dependencySerializationTraitProperty.unsupportedPrivateProperty | 12 | #3642135: Fix PHPStan L3 error: dependencySerializationTraitProperty.unsupportedPrivateProperty |
| argument.unresolvableType | 12 | |
| cast.string | 10 | |
| method.childReturnType | 10 | |
| drupal.hookEntityOperationMissingCacheabilityParameter | 10 | |
| class.nameCase | 9 | #3640899: Fix PHPStan L3 error: class.nameCase |
| pluginManagerSetsCacheBackend.missingCacheBackend | 9 | |
| phpDoc.parseError | 8 | #3642160: Fix PHPStan L3 error: phpDoc.parseError |
| assignOp.invalid | 7 | |
| method.void | 7 | |
| offsetAssign.dimType | 6 | |
| method.protected | 6 | |
| drupal.symfonyYamlParse | 5 | |
| staticMethod.nonObject | 4 | |
| offsetAccess.invalidOffset | 4 | |
| parameter.defaultValue | 3 | |
| varTag.misplaced | 3 | |
| parameter.notFound | 2 | |
| interface.nameCase | 2 | |
| loadIncludes.moduleNotFound | 2 | |
| generics.existingClass | 1 | |
| postInc.type | 1 | |
| throws.notThrowable | 1 | |
| staticMethod.notFound | 1 | |
| return.void | 1 | |
| isset.offset | 1 | |
| renderCallback.invalidKeyValue | 1 | |
| closure.unusedUse | 1 | |
| nullCoalesce.variable | 1 | |
| loggerFromFactory.propertyAssignment | 1 | |
| drupal.hookEntityOperationAlterMissingCacheabilityParameter | 1 | |
| encapsedStringPart.nonString | 1 | |
| property.protected | 1 | |
| varTag.trait | 1 | |
| staticMethod.deprecated | 1 | |
| equal.invalid | 1 | |
| notEqual.invalid | 1 | |
| unset.offset | 1 | |
| greater.invalid | 1 | |
| callable.void | 1 | |
| parameter.unresolvableType | 1 | #3642781: Fix PHPStan error: parameter.unresolvableType |
Remaining overview
Current phpstan baseline analytics (30/11/2026)
----------------------------------------
PHPStan baseline statistics
----------------------------------------
14051 * Total baselined errors
----------------------------------------
Breakdown by error identifier:
4958 missingType.return
3629 method.notFound
1392 property.notFound
654 assign.propertyType
627 argument.type
418 return.type
321 property.nonObject
274 method.nonObject
203 return.missing
175 drupal.entityStoragePropertyAssignment
146 class.notFound
106 arguments.count
96 variable.undefined
82 property.defaultValue
77 parameter.phpDocType
76 property.phpDocType
66 offsetAccess.notFound
61 drupal.entityStorageDirectInjection
48 varTag.nativeType
47 method.deprecated
41 isset.variable
41 return.phpDocType
40 staticClassAccess.privateMethod
39 empty.variable
36 return.empty
31 varTag.differentVariable
30 offsetAssign.valueType
29 varTag.variableNotFound
29 generics.notSubtype
28 unset.possiblyHookedProperty
23 offsetAccess.nonOffsetAccessible
19 foreach.nonIterable
16 parameterByRef.type
14 binaryOp.invalid
14 constructor.unusedParameter
13 disallowed.function
12 dependencySerializationTraitProperty.unsupportedPrivateProperty
12 argument.unresolvableType
10 cast.string
10 method.childReturnType
10 drupal.hookEntityOperationMissingCacheabilityParameter
9 class.nameCase
9 pluginManagerSetsCacheBackend.missingCacheBackend
8 phpDoc.parseError
7 assignOp.invalid
7 method.void
6 offsetAssign.dimType
6 method.protected
5 drupal.symfonyYamlParse
4 staticMethod.nonObject
4 offsetAccess.invalidOffset
3 parameter.defaultValue
3 varTag.misplaced
2 parameter.notFound
2 interface.nameCase
2 loadIncludes.moduleNotFound
1 generics.existingClass
1 postInc.type
1 throws.notThrowable
1 staticMethod.notFound
1 return.void
1 isset.offset
1 renderCallback.invalidKeyValue
1 closure.unusedUse
1 nullCoalesce.variable
1 loggerFromFactory.propertyAssignment
1 drupal.hookEntityOperationAlterMissingCacheabilityParameter
1 encapsedStringPart.nonString
1 property.protected
1 varTag.trait
1 staticMethod.deprecated
1 equal.invalid
1 notEqual.invalid
1 unset.offset
1 greater.invalid
1 callable.void
1 parameter.unresolvableType
Comments
Comment #2
mallezieComment #3
mallezieComment #4
mallezieComment #5
mstrelan commentedI set up this dashboard that tracks the size of the baseline over time - https://mstrelan.github.io/drupal-phpstan-baseline/
It also shows a breakdown of errors by identifier, and includes filters by path, so you can easily see where the violations are.
I also opened a few PRs for phpstan-drupal that help with the baseline:
Comment #6
smustgrave commentedNot sure review is the correct status with so many open issues still.