Upgrading phpstan/phpstan 1 to 2
Breaking1.12.34 → 2.3.7Breaking27Security1Platform1Deprecated4New356Changed643Fixed978Other583
BreakingUpgrade verdict
27 breaking changes and a platform requirement change and a security fix.
In plain terms
- Every error reported by a custom rule must now include an identifier.
- Resolves PHP version checks in remaining scope-aware extensions from Scope::getPhpVersion() and forbids injecting PhpVersion into them.
- A core extension point is now an interface, so code that extended or instantiated the old class must adapt.
- Extensions implementing TypeSpecifierAwareExtension receive the TypeSpecifier in a different place, which can affect custom extensions.
Must act Top 5 of 33 that need code or config changes
phpstan/phpstan publishes an official migration guide for version 2. It covers more than the release notes do.
**UPGRADING guide** ↗PHP requirement changed in 2.0.0: ^7.2|^8.0 → ^7.4|^8.0.
What you must change
Breaking27
Custom rules are now required to provide an identifier.
Resolves PHP version checks in remaining scope-aware extensions from Scope::getPhpVersion() and forbids injecting PhpVersion into them.
Scope::getPhpVersion()PhpVersionTypeSpecifier becomes an interface instead of a class.
TypeSpecifierChanges where TypeSpecifier is set into TypeSpecifierAwareExtension.
TypeSpecifierTypeSpecifierAwareExtensionRemoves the unreachable branches rules UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule and the unreachable arm error in MatchExpressionRule.
UnreachableIfBranchesRuleUnreachableTernaryElseBranchRuleMatchExpressionRuleReturning plain strings as errors is no longer supported; use RuleErrorBuilder.
RuleErrorBuilderAdds a PhpVersion parameter to various Type methods.
PhpVersionTypeEliminates the OriginalPropertyTypeExpr virtual node.
OriginalPropertyTypeExprEliminates the GetOffsetValueTypeExpr virtual node.
GetOffsetValueTypeExprEliminates the GetIterableKeyTypeExpr virtual node.
GetIterableKeyTypeExprEliminates the GetIterableValueTypeExpr virtual node.
GetIterableValueTypeExprReplaces SpecifiedTypes::normalize() with symbolic alternative-form entries.
SpecifiedTypes::normalize()Removes callable.nonNativeMethod.
callable.nonNativeMethodDrops MutatingScope->rememberConstructorScope().
MutatingScope->rememberConstructorScope()Removes the implicit wildcard in FileExcluder.
FileExcluderMoves IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules.
IllegalConstructorMethodCallRuleIllegalConstructorStaticCallRuleMakes a few more MutatingScope method parameters required.
MutatingScopeMakes CommandHelper::begin() parameters required.
CommandHelper::begin()Makes the MethodTag constructor parameter $templateTags required.
MethodTag$templateTagsMakes the InitializerExprTypeResolver constructor parameter $usePathConstantsAsConstantString required.
InitializerExprTypeResolver$usePathConstantsAsConstantStringMakes all parameters of PhpMethodReflectionFactory::create() required.
PhpMethodReflectionFactory::create()Makes FunctionCallParametersCheck parameters $nodeType and $acceptsNamedArguments required.
FunctionCallParametersCheck$nodeType$acceptsNamedArgumentsMakes the $ignorable parameter of MethodParameterComparisonHelper::compare() required.
MethodParameterComparisonHelpercompare()$ignorableMakes the $dateTimeClass parameter of the DateTimeModifyReturnTypeExtension constructor required.
DateTimeModifyReturnTypeExtension$dateTimeClassMakes the NativeFunctionReflection constructor parameters required.
NativeFunctionReflectionRenames NewOptimizedDirectorySourceLocator to OptimizedDirectorySourceLocator.
NewOptimizedDirectorySourceLocatorOptimizedDirectorySourceLocatorRefactors the parameters of FunctionCallParametersCheck::check().
FunctionCallParametersCheck::check()Security1
Prevents ENV var tokens from being leaked by committed DI containers.
Platform1
PHPStan supports running on PHP 8.6 runtime.
Deprecations to plan for
Deprecated4
Deprecates ResultCacheMetaExtension.
ResultCacheMetaExtensionDeprecates various getProperty/hasProperty methods and introduces getStaticProperty, hasStaticProperty, getInstanceProperty and getStaticProperty.
getProperty()hasProperty()getStaticProperty()hasStaticProperty()getInstanceProperty()Deprecates
ClassReflection::isSubclassOf(string $className) in favour of ClassReflection::isSubclassOfClass(ClassReflection $class).ClassReflection::isSubclassOf()ClassReflection::isSubclassOfClass()ClassReflection::is()ReflectionProviderDeprecates various instanceof *Type checks in favour of new methods on the Type interface.
Type