2.1.34
Major new features ๐
- Optimized performance ๐๏ธ
- Caching of reflection objects and resolved PHPDocs
- Many raw performance optimization tweaks in analyser code (thanks @staabm!)
- Projects typically see 25 % to 40 % faster analysis times. Please test this release and report back, we're looking forward to your numbers as well!
- Utilization of Fibers for more precise analysis (PHP 8.1+)
- Code like
doFoo($a = 1, $a)will see better type inference for 2nd call argument. - When a rule hooked onto MethodCall AST node asks for
$scope->getType($node->args[1]), without Fibers it getsmixed, because$scopesees the state before the method call. - Fibers allow PHPStan to "pause" the execution of the rule until the precise type of
$node->args[1]is available in the analyser. - When the 2nd argument is processed, the execution of the rule is resumed and
$scope->getType($node->args[1])sees1as the type, notmixed. - Solves 10 reported issues: https://github.com/phpstan/phpstan/issues/12234, https://github.com/phpstan/phpstan/issues/11982, https://github.com/phpstan/phpstan/issues/11386, https://github.com/phpstan/phpstan/issues/11079, https://github.com/phpstan/phpstan/issues/10612, https://github.com/phpstan/phpstan/issues/9652, https://github.com/phpstan/phpstan/issues/8936, https://github.com/phpstan/phpstan/issues/12663, https://github.com/phpstan/phpstan/issues/12735, https://github.com/phpstan/phpstan/issues/13353
- Code like
Improvements ๐ง
- Add ArrayCountValuesDynamicReturnTypeExtension (#4615), #13816, thanks @mad-briller!
Bugfixes ๐
- Fix
UnionType::getObjectClassReflections(#4541), #13777, thanks @VincentLanglet! count(non-empty-array, COUNT_RECURSIVE)isint<1, max>(#4515), thanks @staabm!- Fix bitwise operators on mixed (#4423), #8094, thanks @VincentLanglet!
- Immediate unwrap AlwaysRememberedExpr after used on NodeScopeResolver (#4651), thanks @samsonasik!
- Improve return type of
range()function to always yield anon-empty-list(#4688), thanks @FeBe95! - Fix ArgumentsNormalizer - do not overwrite already passed args (https://github.com/phpstan/phpstan-src/commit/7bdd17221f67b9e7e55741f5e9cb67d9f8232ce2)
- Prevent crash when analysing curl_setopt (#4722), thanks @schlndh!
- Fix the handling of sealed concrete classes (#4567), #13734, thanks @stof!
- Improve and sync Accessory types
accepts()methods (#4766), #13964, thanks @staabm!
Performance ๐๏ธ
- Prevent unnecessary scope merging (#4640), thanks @staabm!
- Prevent reading & json-decoding composer.json multiple times (#4645), thanks @staabm!
- Cache neon file reads (#4646), thanks @staabm!
- Optimize keepVoidType (https://github.com/phpstan/phpstan-src/commit/ff3922084b90aa4ca53dcc1f4037fb00758cdde9)
- TypeCombinator - assume that inner types in UnionType are already normalized (https://github.com/phpstan/phpstan-src/commit/e8f999276855d7673b19b67a49b693aec24e51c4)
- Remember resolved types after pushInFunctionCall (#4648), thanks @staabm!
- Remember function return type extensions (#4644) (#4644), thanks @staabm!
- Use sha256 which is cpu optimized in PHP 8.4+ (#4656), thanks @staabm!
- Cache ast-parsing in RegexGroupParser (#4655), thanks @staabm!
- Microoptimize TypeCombinator (#4657), thanks @staabm!
- TypeCombinator: Remove unnecessary md5 encoding (#4658), thanks @staabm!
- Prevent duplicate super-global-variable detection (#4662) (#4662), thanks @staabm!
- Prevent Scalar expressions to be specified (#4663), thanks @staabm!
- Print more precise elapsed time (#4664), thanks @staabm!
- TypeCombinator: remove unnecessary loop (#4665), thanks @staabm!
- TypeCombinator: Reduce number of intersect() calls (#4668), thanks @staabm!
- TypeCombinator: Simplify ConstantStringType handling (#4666) (#4666), thanks @staabm!
- TypeCombinator: Prevent unnecessary work (#4667) (#4667), thanks @staabm!
- Prevent unnecessary work when resolving Expr\BinaryOp\Coalesce (#4661), thanks @staabm!
- VerbosityLevel: early return type traversal (#4670) (#4670), thanks @staabm!
- ParametersAcceptorSelector: early return type traversal (#4669) (#4669), thanks @staabm!
- UnresolvableTypeHelper: early return type traversal (#4671), thanks @staabm!
- LazyInternalScopeFactory: Prevent expensive repeated getService() calls (#4672), thanks @staabm!
- Use more efficient spl_object_id() over spl_object_hash() (#4674), thanks @staabm!
- Remove
TypeCombinator::union()calls that are not necessary (https://github.com/phpstan/phpstan-src/commit/12f2b2318ca8ded98a544452555cb9982a7794b9) - Remove
TypeCombinator::intersect()calls that are not necessary (https://github.com/phpstan/phpstan-src/commit/f1f97c30a7ead237704c4f081e3f58d2512c67f0) - Prevent repetative method calls on ParametersAcceptor (#4686), thanks @staabm!
- Prevent unnecessary node-key calculation (#4691), thanks @staabm!
- Prevent maybe unnecessary work in MutatingScope::filterBySpecifiedTypes() (#4690), thanks @staabm!
- Prevent unnecessary work in BetterReflectionProvider (#4687), thanks @staabm!
- Simplify MutatingScope->invalidateMethodsOnExpression() (#4692), thanks @staabm!
- Speedup analysis of arrays containing closures (#4684), thanks @staabm!
- TypeNodeResolver: Reduce number of intersect() calls (#4694), thanks @staabm!
- TypeCombinator: prevent unnecessary work (#4695), thanks @staabm!
- ConstantStringType: Prevent creation of unnecessary constant-object types (#4696), thanks @staabm!
- Remove NodeFinder from MutatingScope->restoreThis() (#4697), thanks @staabm!
- MemoizingContainer - memoize getService (https://github.com/phpstan/phpstan-src/commit/68815ac1f1bcc156dfa0db973287971336beb297)
- Use static callback for TypeTraverser::map() (#4701), thanks @staabm!
- Prevent unnecessary work while Ternary analysis (#4704), thanks @staabm!
- Prevent unnecessary work in NodeScopeResolver->processAssignVar() (#4705), thanks @staabm!
- Prevent unnecessary work in While/Do analysis (#4706), thanks @staabm!
- Prevent unnecessary work in TypeSpecifier->createForExpr() (#4707), thanks @staabm!
- NodeScopeResolver: Move condition out of loop (#4708), thanks @staabm!
- NodeScopeResolver: determine callCallbackImmediately only for callables (#4709) (#4709), thanks @staabm!
- NodeScopeResolver: cheap checks first (#4710) (#4710), thanks @staabm!
- NodeScopeResolver: Move assignByReference logic out of generic path (#4711), thanks @staabm!
- Process called methods looking for initialized properties only when called from constructor (https://github.com/phpstan/phpstan-src/commit/c9937542b33e288e0b2a126d085ebdd16de7527b)
- Cheap checks first (#4715), thanks @staabm!
- Store only variables as expression types with maybe certainty (#4719)
- Prevent unnecessary work in MutatingScope->mergeVariableHolders() (#4720), thanks @staabm!
- Prevent unnecessary work in
NodeScopeResolver::processAssignVar()(#4716), thanks @staabm! - Minor optimization (https://github.com/phpstan/phpstan-src/commit/21d86f0675008ebea2ba52fdee6013a6180a228d)
- No need to resolve late-resolvable types in getVariableType (https://github.com/phpstan/phpstan-src/commit/3eea03bf1b126684b0a486a0ad2f9963368c48e3)
- Less expression printing (#4723), thanks @staabm!
- MutatingScope: Prevent duplicate work in getVariableType() (#4726), thanks @staabm!
- NodeScopeResolver: duplicate only if we actually change the storage (#4729), thanks @staabm!
- NodeScopeResolver: cheap checks first (#4728), thanks @staabm!
- Decrease usage of TypeTraverser (https://github.com/phpstan/phpstan-src/commit/93b9c34973987392b162d3770e0f4ccb0790fbcc)
- TypeSpecifier: cheap checks first (#4731), thanks @staabm!
- CallTo*Rule: cheap checks first (#4733), thanks @staabm!
- Optimize keepVoidType (#4735) (#4735), thanks @staabm!
- Prevent unnecessary work in Match_ analysis (#4739), thanks @staabm!
- Implement Type->getEnumCaseObject() (#4740), thanks @staabm!
- IntersectionType: remove unnecessary hashing (#4744), thanks @staabm!
- Faster IntersectionType->getFiniteTypes() (#4746), thanks @staabm!
- MemoizingReflectionProvider->hasClass() is case-insensitive (#4750), thanks @staabm!
- FileTypeMapper: Prevent unnecessary file IO (#4756), thanks @staabm!
- TypeSpecifier: Prevent unnecessary type specification (#4757), thanks @staabm!
- Cache ClassReflections (#4761), thanks @staabm!
- FileAnalyser: Move repetitive work out of hot loop (#4758), thanks @staabm!
- UnionType: inline array_map() call (#4765), thanks @staabm!
- TypeCombinator: Prevent unnecessary work (#4773), thanks @staabm!
- TypeCombinator: merge 2 loops in intersect() (#4771), thanks @staabm!
- MutatingScope: merge loops into one (#4774), thanks @staabm!
- Optimize Scope::mergeWith (https://github.com/phpstan/phpstan-src/commit/64e0cb4bd91451372228c70d040ad045bb75f0e1)
- Various TypeCombinator optimization ideas (https://github.com/phpstan/phpstan-src/commit/3577b698473a7c54387aae8133451fea89c87341)
- No need to call rememberConstructorExpressions for each enterClassMethod if rememberConstructorScope is kept (https://github.com/phpstan/phpstan-src/commit/78d946dacc0d8aede1508e5691f501436011c9d7)
- TypeCombinator optimization (https://github.com/phpstan/phpstan-src/commit/8b0c0839bfb0440d1f1cee2fb8cde5c4912130aa)
- Call
StaticType::transformStaticTypeless often (https://github.com/phpstan/phpstan-src/commit/d27df94ed68911af24fe93a2f33c89e948e22abc) - Optimize
CallableType::equals()(https://github.com/phpstan/phpstan-src/commit/1f1d382f80a83a749865b25c9be52c3affcfe6c2) - Cache StaticType and ObjectType::getMethod() (https://github.com/phpstan/phpstan-src/commit/270b546c9dc4a3098a6163f4060c5c00edf6ca71)
- TrinaryLogic: faster or() (#4778), thanks @staabm!
- Faster ExpressionTypeHolder->equals() (#4777), thanks @staabm!
- Debug-Rules: cheap checks first (#4764), thanks @staabm!
- InitializerExprTypeResolver: move work out of loop (#4785), thanks @staabm!
- TrinaryLogic: Prevent unnecessary work (#4784), thanks @staabm!
Function signature fixes ๐ค
- Fix getAttributeNode and getAttributeNodeNS (#4484), thanks @VincentLanglet!
Internals ๐
- Remove unused baseline-7.3.neon file (#4622), thanks @staabm!
- Update PHPStan packages (#4621, #4625), thanks @staabm!
- Tests: Use Stubs instead of Mocks (#4626), thanks @staabm!
- Allow PHPUnit 12 (#4624), thanks @staabm!
- Fix mutation testing (#4631), thanks @staabm!
- Prevent double normalization of FuncCall nodes (#4637), thanks @staabm!
- Simplify MutatingScope->compareVariableTypeHolders() (#4641), thanks @staabm!
- Ignore by identifier instead of plain error (#4652), thanks @staabm!
- ResultCacheManager - do not invalidate cache when switching Blackfire extension on/off (https://github.com/phpstan/phpstan-src/commit/97c30cacf1ed15d1fc4bf820aacae982404d4fe2)
- Simplify NodeScopeResolver->processImmediatelyCalledCallable() (#4698), thanks @staabm!
- Fix PHPStorm inspection errors (#4700), thanks @staabm!
- More precise Type->getCallableParametersAcceptors() return type (#4713) (#4713), thanks @staabm!
- Added native return types (#4732), thanks @staabm!
- Simplify PhpClassReflectionExtension (#4741), thanks @staabm!
- Fix typo in test data (#4743), thanks @takaram!
- EnumCaseObjectType enumCaseName is readonly (#4745), thanks @staabm!
- Simplify ContainerDynamicReturnTypeExtension (#4755), thanks @staabm!
- Split MutatingScope->resolveType() into smaller methods (#4759) (#4759), thanks @staabm!
- Split MutatingScope->resolveType() into smaller methods - part 2 (#4760) (#4760), thanks @staabm!
- MemoizingReflector: more precise types (#4762), thanks @staabm!
- Simplify TypeCombinator->processArrayTypes() (#4769) (#4769), thanks @staabm!
- Drop MutatingScope->rememberConstructorScope() (#4768), thanks @staabm!
- IntersectionType: Extract describeType() method (#4776), thanks @staabm!
- More precise types (#4772), thanks @staabm!